Skip to content

Commit

Permalink
Merge pull request #28 from ashtonpaul/master
Browse files Browse the repository at this point in the history
Add support for Django 4.0.x / Drop support for non-LTS versions of Django (1.11.x and 2.1.x)
  • Loading branch information
mbourqui authored Nov 4, 2022
2 parents 3e1380f + 55f9ef0 commit 50b56ce
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 25 deletions.
28 changes: 13 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,29 @@ 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=2.2.28
- DJANGO_VERSION=3.2.15
- DJANGO_VERSION=4.0.7
# 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=3.2.15
python: 3.5
- env: DJANGO_VERSION=4.0.7
python: 3.5
- env: DJANGO_VERSION=4.0.7
python: 3.6
- env: DJANGO_VERSION=4.0.7
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

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

### Removed
- Support of Django 1.11
- Support of Django 2.1

## 4.0.0 (23.05.2020)
### Added
- Support of Django 2.1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Python](https://img.shields.io/badge/Python-3.5,3.6,3.7,3.8-blue.svg?style=flat-square)](/)
[![Django](https://img.shields.io/badge/Django-1.11,2.1,2.2-blue.svg?style=flat-square)](/)
[![Python](https://img.shields.io/badge/Python-3.5,3.6,3.7,3.8,3.9-blue.svg?style=flat-square)](/)
[![Django](https://img.shields.io/badge/Django-2.2,3.2,4.0-blue.svg?style=flat-square)](/)
[![License](https://img.shields.io/badge/License-BSD--3--Clause-blue.svg?style=flat-square)](/LICENSE)
[![PyPIv](https://img.shields.io/pypi/v/django-constrainedfilefield.svg?style=flat-square)](https://pypi.org/project/django-constrainedfilefield)
[![PyPIs](https://img.shields.io/pypi/status/django-constrainedfilefield.svg)](https://pypi.org/project/django-constrainedfilefield)
Expand All @@ -23,7 +23,7 @@ form field.

## Requirements
* [Python][] >= 3.5
* [Django]>= 1.11.29
* [Django]>= 2.2.28
* `python-magic` >= 0.4.2 *iff* you want to check the file type

## Installation
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
Loading
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 50b56ce

Please sign in to comment.