Convert codebase for python3 usage

This commit is contained in:
Philip Sargent
2020-05-24 01:57:06 +01:00
committed by Wookey
parent 35f85c55f1
commit 50d753a87b
38 changed files with 288 additions and 261 deletions

View File

@@ -20,9 +20,9 @@ def flush_cache(apps, options):
"""
apps = [a.strip(',') for a in apps]
if apps:
print 'Flushing cache for %s...' % ', '.join(apps)
print('Flushing cache for %s...' % ', '.join(apps))
else:
print 'Flushing caches...'
print('Flushing caches...')
for app_label in apps:
app = cache.get_app(app_label)

View File

@@ -47,7 +47,7 @@ class ImageModelBase(ModelBase):
except ImportError:
raise ImportError('Unable to load imagekit config module: %s' % \
opts.spec_module)
for spec in [spec for spec in module.__dict__.values() \
for spec in [spec for spec in list(module.__dict__.values()) \
if isinstance(spec, type) \
and issubclass(spec, specs.ImageSpec) \
and spec != specs.ImageSpec]:
@@ -56,7 +56,7 @@ class ImageModelBase(ModelBase):
setattr(cls, '_ik', opts)
class ImageModel(models.Model):
class ImageModel(models.Model, metaclass=ImageModelBase):
""" Abstract base class implementing all core ImageKit functionality
Subclasses of ImageModel are augmented with accessors for each defined
@@ -64,7 +64,6 @@ class ImageModel(models.Model):
storage locations and other options.
"""
__metaclass__ = ImageModelBase
class Meta:
abstract = True
@@ -81,10 +80,10 @@ class ImageModel(models.Model):
self._ik.admin_thumbnail_spec
else:
if hasattr(self, 'get_absolute_url'):
return u'<a href="%s"><img src="%s"></a>' % \
return '<a href="%s"><img src="%s"></a>' % \
(self.get_absolute_url(), prop.url)
else:
return u'<a href="%s"><img src="%s"></a>' % \
return '<a href="%s"><img src="%s"></a>' % \
(self._imgfield.url, prop.url)
admin_thumbnail_view.short_description = _('Thumbnail')
admin_thumbnail_view.allow_tags = True

View File

@@ -18,6 +18,6 @@ class Options(object):
spec_module = 'imagekit.defaults'
def __init__(self, opts):
for key, value in opts.__dict__.iteritems():
for key, value in opts.__dict__.items():
setattr(self, key, value)
self.specs = []

View File

@@ -6,7 +6,7 @@ spec found.
"""
import os
from StringIO import StringIO
from io import StringIO
from imagekit.lib import *
from imagekit.utils import img_to_fobj
from django.core.files.base import ContentFile

View File

@@ -83,4 +83,4 @@ class IKTest(TestCase):
# make sure image file is deleted
path = self.p.image.path
self.p.delete()
self.failIf(os.path.isfile(path))
self.assertFalse(os.path.isfile(path))