Skip to content

Commit

Permalink
Merge pull request #600 from wm3ndez/master
Browse files Browse the repository at this point in the history
Support Django 3.0+
  • Loading branch information
wm3ndez committed Dec 5, 2019
2 parents 22ccd97 + 561563c commit 4fe1854
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 37 deletions.
42 changes: 29 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@ dist: xenial

matrix:
include:
- python: "2.7"
env: TOXENV=py27-django111-pil
- python: "2.7"
env: TOXENV=py27-django111-imagemagick
- python: "2.7"
env: TOXENV=py27-django111-graphicsmagick
- python: "2.7"
env: TOXENV=py27-django111-redis
- python: "2.7"
env: TOXENV=py27-django111-wand
- python: "2.7"
env: TOXENV=py27-django111-dbm

- python: "3.6"
env: TOXENV=py36-django111-pil
- python: "3.6"
Expand Down Expand Up @@ -57,6 +44,9 @@ matrix:
- python: "3.6"
env: TOXENV=py36-django21-dbm

- python: "3.6"
env: TOXENV=py36-django30-pil

- python: "3.7"
env: TOXENV=py37-django20-pil
- python: "3.7"
Expand All @@ -75,6 +65,32 @@ matrix:
- python: "3.7"
env: TOXENV=py37-django22-dbm

- python: "3.7"
env: TOXENV=py37-django30-pil
- python: "3.7"
env: TOXENV=py37-django30-imagemagick
- python: "3.7"
env: TOXENV=py37-django30-graphicsmagick
- python: "3.7"
env: TOXENV=py37-django30-redis
- python: "3.7"
env: TOXENV=py37-django30-wand
- python: "3.7"
env: TOXENV=py37-django30-dbm

- python: "3.8"
env: TOXENV=py38-django30-pil
- python: "3.8"
env: TOXENV=py38-django30-imagemagick
- python: "3.8"
env: TOXENV=py38-django30-graphicsmagick
- python: "3.8"
env: TOXENV=py38-django30-redis
- python: "3.8"
env: TOXENV=py38-django30-wand
- python: "3.8"
env: TOXENV=py38-django30-dbm

addons:
apt:
packages:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Thumbnails for Django.
Features at a glance
====================

- Support for Django 1.11, 2.0, 2.1, and 2.2 following the `Django supported versions policy`_
- Support for Django 1.11, 2.0, 2.1, 2.2 and 3.0 following the `Django supported versions policy`_
- Python 3 support
- Storage support
- Pluggable Engine support for `Pillow`_, `ImageMagick`_, `PIL`_, `Wand`_, `pgmagick`_, and `vipsthumbnail`_
Expand Down
4 changes: 2 additions & 2 deletions docs/template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Source can be an ImageField, FileField, a file name (assuming default_storage),
a url. What we need to know is name and storage, see how ImageFile figures
these things out::

from django.utils.encoding import force_text
from django.utils.encoding import force_str

class ImageFile(BaseImageFile):
_size = None
Expand All @@ -54,7 +54,7 @@ these things out::
if hasattr(file_, 'name'):
self.name = file_.name
else:
self.name = force_text(file_)
self.name = force_str(file_)
# figure out storage
if storage is not None:
self.storage = storage
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ def run(self):
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Multimedia :: Graphics',
'Framework :: Django',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Framework :: Django :: 2.1',
'Framework :: Django :: 2.2',
'Framework :: Django :: 3.0',
],
cmdclass={"test": TestCommand},
)
4 changes: 1 addition & 3 deletions sorl/thumbnail/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
import re

from django.utils.six import string_types

from sorl.thumbnail.conf import settings, defaults as default_settings
from sorl.thumbnail.helpers import tokey, serialize
from sorl.thumbnail.images import ImageFile, DummyImageFile
Expand Down Expand Up @@ -179,7 +177,7 @@ def _create_alternative_resolutions(self, source_image, geometry_string,
for resolution in settings.THUMBNAIL_ALTERNATIVE_RESOLUTIONS:
resolution_geometry = (int(geometry[0] * resolution), int(geometry[1] * resolution))
resolution_options = options.copy()
if 'crop' in options and isinstance(options['crop'], string_types):
if 'crop' in options and isinstance(options['crop'], str):
crop = options['crop'].split(" ")
for i in range(len(crop)):
s = re.match(r"(\d+)px", crop[i])
Expand Down
4 changes: 2 additions & 2 deletions sorl/thumbnail/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from importlib import import_module

from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_text
from django.utils.encoding import force_str
from sorl.thumbnail.compat import encode


Expand Down Expand Up @@ -43,7 +43,7 @@ def tokey(*args):
"""
Computes a unique key from arguments given.
"""
salt = '||'.join([force_text(arg) for arg in args])
salt = '||'.join([force_str(arg) for arg in args])
hash_ = hashlib.md5(encode(salt))
return hash_.hexdigest()

Expand Down
5 changes: 2 additions & 3 deletions sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from django.core.files.base import File, ContentFile
from django.core.files.storage import Storage # , default_storage
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.encoding import force_str
from django.utils.functional import LazyObject, empty
from sorl.thumbnail import default
from sorl.thumbnail.conf import settings
Expand Down Expand Up @@ -76,7 +76,6 @@ def url(self):
src = url


@python_2_unicode_compatible
class ImageFile(BaseImageFile):
_size = None

Expand All @@ -88,7 +87,7 @@ def __init__(self, file_, storage=None):
if hasattr(file_, 'name'):
self.name = file_.name
else:
self.name = force_text(file_)
self.name = force_str(file_)

# TODO: Add a customizable naming method as a signal

Expand Down
2 changes: 0 additions & 2 deletions sorl/thumbnail/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

from sorl.thumbnail.conf import settings


@python_2_unicode_compatible
class KVStore(models.Model):
key = models.CharField(
max_length=200, primary_key=True,
Expand Down
4 changes: 1 addition & 3 deletions sorl/thumbnail/parsers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# coding=utf-8
import re

from django.utils import six

from sorl.thumbnail.helpers import ThumbnailError, toint


Expand Down Expand Up @@ -100,7 +98,7 @@ def parse_cropbox(cropbox):
"""
Returns x, y, x2, y2 tuple for cropping.
"""
if isinstance(cropbox, six.text_type):
if isinstance(cropbox, str):
return tuple([int(x.strip()) for x in cropbox.split(',')])
else:
return tuple(cropbox)
3 changes: 1 addition & 2 deletions sorl/thumbnail/templatetags/thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from django.template import Library, Node, NodeList, TemplateSyntaxError
from django.utils.encoding import smart_str
from django.utils.six import text_type
from django.conf import settings

from sorl.thumbnail.conf import settings as sorl_settings
Expand Down Expand Up @@ -129,7 +128,7 @@ def _render(self, context):
options = {}
for key, expr in self.options:
noresolve = {'True': True, 'False': False, 'None': None}
value = noresolve.get(text_type(expr), expr.resolve(context))
value = noresolve.get(str(expr), expr.resolve(context))
if key == 'options':
options.update(value)
else:
Expand Down
1 change: 0 additions & 1 deletion tests/thumbnail_tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.test import SimpleTestCase
from django.test.utils import override_settings

from sorl.thumbnail.admin.current import AdminImageWidget

Expand Down
2 changes: 1 addition & 1 deletion tests/thumbnail_tests/test_backends.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from io import StringIO
import os
import sys
import shutil
import unittest
from PIL import Image

import pytest
from django.utils.six import StringIO
from django.test import TestCase
from django.test.utils import override_settings

Expand Down
2 changes: 1 addition & 1 deletion tests/thumbnail_tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from io import StringIO
import os

import pytest
from django.utils.six import StringIO
from django.core import management

from sorl.thumbnail.conf import settings
Expand Down
1 change: 0 additions & 1 deletion tests/thumbnail_tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def test_rgba_colorspace(self):
self.assertEqual(t.x, 100)
self.assertEqual(t.y, 100)


def test_falsey_file_argument(self):
with self.assertRaises(ValueError):
self.BACKEND.get_thumbnail('', '100x100')
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

[tox]
skipsdist = True
envlist = {py27,py34,py35,py36}-django111-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm,vipsthumbnail}
envlist = {py34,py35,py36}-django111-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm,vipsthumbnail}
{py34,py35,py36,py37}-django20-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm,vipsthumbnail}
{py35,py36,py37}-django21-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm,vipsthumbnail}
{py35,py36,py37}-django22-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm,vipsthumbnail}
{py36,py37,py38}-django30-{pil,imagemagick,graphicsmagick,redis,dynamodb,wand,pgmagick,dbm,vipsthumbnail}

[testenv]
changedir = {toxinidir}/tests
Expand All @@ -22,6 +23,7 @@ deps = pytest
django20: Django>=2.0a1,<2.1
django21: Django>=2.1a1,<2.2
django22: Django>=2.2a1,<3.0
django30: Django>=3.0a1,<3.1

setenv = PYTHONPATH = {toxinidir}:{toxinidir}
pil: DJANGO_SETTINGS_MODULE=tests.settings.pil
Expand Down

0 comments on commit 4fe1854

Please sign in to comment.