Skip to content

Commit

Permalink
Merge 59cf89c into 3e1380f
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtonpaul committed Sep 2, 2022
2 parents 3e1380f + 59cf89c commit c2cc8f2
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ addons:
before_install:
- ./pypi_packager.sh
install:
- if [[ $TRAVIS_PYTHON_VERSION == 3.7 ]]; then pip install -U importlib_metadata; fi
- pip install -q django==$DJANGO_VERSION
- pip install -e .[coverage]
- pip install -q coveralls
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 4.0.1 (31.08.2022)
- make lazy text Django 4.0 compatible

## 4.0.0 (23.05.2020)
### Added
- Support of Django 2.1
Expand Down
2 changes: 1 addition & 1 deletion constrainedfilefield/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__license__ = "BSD-3-Clause"
__author__ = "Marc Bourqui"
__version__ = "4.0.0"
__version__ = "4.0.1"
__version_info__ = tuple(
[
int(num) if num.isdigit() else num
Expand Down
4 changes: 2 additions & 2 deletions constrainedfilefield/fields/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from django.conf import settings
from django.db import models
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class ConstrainedFileField(models.FileField):
"""
A FielField with additional constraints. Namely, the file size and type can be restricted. If
A FileField with additional constraints. Namely, the file size and type can be restricted. If
using the types, the magic library is required. Setting neither a file size nor type behaves
like a regular FileField.
Expand Down
2 changes: 1 addition & 1 deletion constrainedfilefield/fields/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.conf import settings
from django.db import models
from django.template.defaultfilters import filesizeformat
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class ConstrainedImageField(models.ImageField):
Expand Down
6 changes: 5 additions & 1 deletion constrainedfilefield/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class TestDocModel(models.Model):


class TestImageModel(models.Model):
the_image = ConstrainedImageField(null=True, blank=True, upload_to="testfile",)
the_image = ConstrainedImageField(
null=True,
blank=True,
upload_to="testfile",
content_types=['image/png'],)
the_image_small = ConstrainedImageField(
null=True,
blank=True,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions constrainedfilefield/tests/tests/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,24 @@ def test_form_invalid_filetype(self):
u"Allowed types are ['image/png'].",
)

def test_form_invalid_image_filetype(self):
files = {
"the_image": self._create_simple_uploaded_file(
orig_filename="unsupported_image.jpg",
dest_filename="the_file.jpg",
content_type="image/jpeg",
),
}
form = TestImageModelForm(data={}, files=files)
self.assertFalse(form.is_valid())
self.assertEqual(len(form.errors), 1)
self.assertEqual(len(form.errors["the_image"]), 1)
self.assertEqual(
form.errors["the_image"][0],
u"Unsupported file type: image/jpeg. "
u"Allowed types are ['image/png']."
)

def test_form_invalid_filetype_and_size(self):
form = self._create_bound_test_model_form(
form_class=TestModelForm,
Expand Down

0 comments on commit c2cc8f2

Please sign in to comment.