diff --git a/.travis.yml b/.travis.yml index b6a4d54..6e4a6a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b8d0e5..2dfde09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/constrainedfilefield/__init__.py b/constrainedfilefield/__init__.py index ec5434c..88b6012 100644 --- a/constrainedfilefield/__init__.py +++ b/constrainedfilefield/__init__.py @@ -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 diff --git a/constrainedfilefield/fields/file.py b/constrainedfilefield/fields/file.py index 1e50480..7efed81 100644 --- a/constrainedfilefield/fields/file.py +++ b/constrainedfilefield/fields/file.py @@ -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. diff --git a/constrainedfilefield/fields/image.py b/constrainedfilefield/fields/image.py index cc381f1..f62f0c7 100644 --- a/constrainedfilefield/fields/image.py +++ b/constrainedfilefield/fields/image.py @@ -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): diff --git a/constrainedfilefield/tests/models.py b/constrainedfilefield/tests/models.py index 264f06b..1d8967e 100644 --- a/constrainedfilefield/tests/models.py +++ b/constrainedfilefield/tests/models.py @@ -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, diff --git a/constrainedfilefield/tests/sample_files/unsupported_image.jpg b/constrainedfilefield/tests/sample_files/unsupported_image.jpg new file mode 100644 index 0000000..1aafc9f Binary files /dev/null and b/constrainedfilefield/tests/sample_files/unsupported_image.jpg differ diff --git a/constrainedfilefield/tests/tests/backend.py b/constrainedfilefield/tests/tests/backend.py index 9408c72..7b6defd 100644 --- a/constrainedfilefield/tests/tests/backend.py +++ b/constrainedfilefield/tests/tests/backend.py @@ -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,