Skip to content

Commit

Permalink
Merge b2826a6 into 3e1380f
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtonpaul committed Sep 2, 2022
2 parents 3e1380f + b2826a6 commit 32e3997
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 18 deletions.
25 changes: 14 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ python:
- 3.6
- 3.7
- 3.8
- 3.9
env:
- DJANGO_VERSION=1.11.29
- DJANGO_VERSION=2.1.15
- DJANGO_VERSION=2.2.12
- DJANGO_VERSION=3.2.15
- DJANGO_VERSION=4.1
# https://docs.djangoproject.com/en/stable/faq/install/#what-python-version-can-i-use-with-django
matrix:
exclude:
- env: DJANGO_VERSION=1.11.29
python: 3.8
- env: DJANGO_VERSION=2.1.15
python: 2.7
- env: DJANGO_VERSION=2.1.15
python: 3.4
- env: DJANGO_VERSION=2.1.15
python: 3.8
- env: DJANGO_VERSION=2.2.12
python: 2.7
- env: DJANGO_VERSION=2.2.12
python: 3.4
- env: DJANGO_VERSION=2.1.15
python: 3.9
- env: DJANGO_VERSION=3.2.15
python: 3.5
- env: DJANGO_VERSION=4.1
python: 3.5
- env: DJANGO_VERSION=4.1
python: 3.6
- env: DJANGO_VERSION=4.1
python: 3.7
addons:
apt_packages:
- pandoc
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 5.0.0 (02.09.2022)
### Added
- Support of Django 4.1

### Removed
- Support of Django 1.11.x

## 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__ = "5.0.0"
__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
5 changes: 4 additions & 1 deletion constrainedfilefield/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ 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",)
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_small": 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_small"]), 1)
self.assertEqual(
form.errors["the_image_small"][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
4 changes: 2 additions & 2 deletions constrainedfilefield/tests/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding:utf-8 -*-
from django.conf.urls import url
from django.urls import re_path
from constrainedfilefield.tests import views

urlpatterns = [
url(r"^nomodel/$", views.nomodel_form, name="nomodel"),
re_path(r"^nomodel/$", views.nomodel_form, name="nomodel"),
]

0 comments on commit 32e3997

Please sign in to comment.