Skip to content

Commit

Permalink
Merge pull request #45 from Chive/fix/upgrade-versions
Browse files Browse the repository at this point in the history
Cleanup Django/Python version support
  • Loading branch information
Chive authored Oct 6, 2021
2 parents ba52e16 + 381b457 commit 4c8b5a7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 41 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: python
python: 3.7
python: 3.9
dist: xenial

env:
- TOX_ENV=py2.7-dj1.11
- TOX_ENV=py3.7-dj2.0
- TOX_ENV=py3.7-dj2.1
- TOX_ENV=py3.9-dj2.2
- TOX_ENV=py3.9-dj3.1
- TOX_ENV=py3.9-dj3.2
- TOX_ENV=lint

install:
Expand Down
28 changes: 13 additions & 15 deletions examples/contact_form/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# Generated by Django 2.2.24 on 2021-10-06 19:33

from django.db import models, migrations
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Attachment',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('file', models.FileField(upload_to=b'attachments', verbose_name='Attachment')),
],
),
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('author_name', models.CharField(max_length=255, verbose_name='Name')),
('author_email', models.EmailField(max_length=254, verbose_name='Email')),
('content', models.TextField(verbose_name='Content')),
],
),
migrations.AddField(
model_name='attachment',
name='message',
field=models.ForeignKey(verbose_name='Message', to='contact_form.Message'),
migrations.CreateModel(
name='Attachment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to='attachments', verbose_name='Attachment')),
('message', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='contact_form.Message', verbose_name='Message')),
],
),
]
4 changes: 2 additions & 2 deletions examples/contact_form/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class Message(models.Model):
Expand All @@ -9,5 +9,5 @@ class Message(models.Model):


class Attachment(models.Model):
message = models.ForeignKey(Message, verbose_name=_('Message'))
message = models.ForeignKey(Message, verbose_name=_('Message'), on_delete=models.PROTECT)
file = models.FileField(_('Attachment'), upload_to='attachments')
11 changes: 6 additions & 5 deletions examples/simple/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
# Generated by Django 2.2.24 on 2021-10-06 19:33

from django.db import models, migrations
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Attachment',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('file', models.FileField(upload_to=b'attachments')),
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to='attachments')),
],
),
]
17 changes: 8 additions & 9 deletions multiupload/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from django import forms
from django.core.exceptions import ValidationError, FieldError
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

# Feel free to extend this, see
# http://www.iana.org/assignments/media-types/media-types.xhtml
Expand All @@ -18,13 +18,12 @@ class MultiUploadMetaInput(forms.ClearableFileInput):

def __init__(self, *args, **kwargs):
self.multiple = kwargs.pop('multiple', True)
super(MultiUploadMetaInput, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def render(self, name, value, attrs=None, renderer=None):
if self.multiple:
attrs['multiple'] = 'multiple'

return super(MultiUploadMetaInput, self).render(name, value, attrs, renderer)
return super().render(name, value, attrs, renderer)

def value_from_datadict(self, data, files, name):
if hasattr(files, 'getlist'):
Expand Down Expand Up @@ -58,19 +57,19 @@ def __init__(self, *args, **kwargs):
attrs=kwargs.pop('attrs', {}),
multiple=(self.max_num is None or self.max_num > 1),
)
super(MultiUploadMetaField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def to_python(self, data):
ret = []
data = data or []
for item in data:
i = super(MultiUploadMetaField, self).to_python(item)
i = super().to_python(item)
if i:
ret.append(i)
return ret

def validate(self, value):
super(MultiUploadMetaField, self).validate(value)
super().validate(value)

num_files = len(value)
if num_files and not value[0]:
Expand Down Expand Up @@ -132,15 +131,15 @@ def __init__(self, *args, **kwargs):
'accept': '{0}/*'.format(self.media_type),
}
})
super(MultiMediaField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class MultiImageField(MultiMediaField, forms.ImageField):
""" Handles multiple image uploads, requires Pillow to be installed. """

def __init__(self, *args, **kwargs):
kwargs.update({'media_type': 'image'})
super(MultiImageField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def to_python(self, data):
ret = []
Expand Down
1 change: 0 additions & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pytest
pytest-django
psycopg2-binary
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py2.7-dj1.11, py3.7-dj2.{0,1}, lint
envlist = py3.9-dj2.2, py3.9-dj3.{1,2}, lint

[testenv]
recreate = False
Expand All @@ -9,15 +9,15 @@ setenv =
pip_pre = True
deps =
-rtest_requirements.txt
dj1.11: Django<2
dj2.0: Django>=2,<2.1
dj2.1: Django>=2.1,<2.2
dj2.2: Django>=2.2,<2.3
dj3.1: Django>=3.1,<3.2
dj3.2: Django>=3.2,<3.3

commands =
py.test multiupload

[testenv:lint]
basepython = python3.7
basepython = python3.9
commands =
pylint multiupload/ setup.py
deps =
Expand Down

0 comments on commit 4c8b5a7

Please sign in to comment.