Skip to content

Commit ef45747

Browse files
committed
Merge branch 'release/4.0.1'
* release/4.0.1: stylling and linting fixes to setup.py Bump version to 4.0.1 Cleaned up _autodiscovered flag handling. Added huge performance improvement by running imagekit.utils.autodiscover() only once on Django > 1.7 as it was intended. Update README.st change model->instance for clarity in defining specs outside of models. Improved docs to include example on how to use plain ImageSpec (defined outside of model, not ImageSpecField) with AdminThumbnail.
2 parents acefa91 + 681b85d commit ef45747

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

README.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,37 @@ Django admin classes:
406406
407407
admin.site.register(Photo, PhotoAdmin)
408408
409+
To use specs defined outside of models:
410+
411+
.. code-block:: python
412+
413+
from django.contrib import admin
414+
from imagekit.admin import AdminThumbnail
415+
from imagekit import ImageSpec
416+
from imagekit.processors import ResizeToFill
417+
from imagekit.cachefiles import ImageCacheFile
418+
419+
from .models import Photo
420+
421+
class AdminThumbnailSpec(ImageSpec):
422+
processors = [ResizeToFill(100, 30)]
423+
format = 'JPEG'
424+
options = {'quality': 60 }
425+
426+
def cached_admin_thumb(instance):
427+
# `image` is the name of the image field on the model
428+
cached = ImageCacheFile(AdminThumbnailSpec(instance.image))
429+
# only generates the first time, subsequent calls use cache
430+
cached.generate()
431+
return cached
432+
433+
class PhotoAdmin(admin.ModelAdmin):
434+
list_display = ('__str__', 'admin_thumbnail')
435+
admin_thumbnail = AdminThumbnail(image_field=cached_admin_thumb)
436+
437+
admin.site.register(Photo, PhotoAdmin)
438+
439+
409440
AdminThumbnail can even use a custom template. For more information, see
410441
``imagekit.admin.AdminThumbnail``.
411442

imagekit/pkgmeta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = 'django-imagekit'
22
__author__ = 'Matthew Tretter, Venelin Stoykov, Eric Eldredge, Bryan Veloso, Greg Newman, Chris Drackett, Justin Driscoll'
3-
__version__ = '4.0'
3+
__version__ = '4.0.1'
44
__license__ = 'BSD'
55
__all__ = ['__title__', '__author__', '__version__', '__license__']

imagekit/utils.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def autodiscover():
7979
_autodiscover_modules_fallback()
8080
else:
8181
autodiscover_modules('imagegenerators')
82+
_autodiscovered = True
8283

8384

8485
def _autodiscover_modules_fallback():
@@ -91,20 +92,13 @@ def _autodiscover_modules_fallback():
9192
9293
Used for Django versions < 1.7
9394
"""
94-
global _autodiscovered
95-
96-
if _autodiscovered:
97-
return
98-
9995
from django.conf import settings
10096
try:
10197
from importlib import import_module
10298
except ImportError:
10399
from django.utils.importlib import import_module
104100
from django.utils.module_loading import module_has_submodule
105101

106-
_autodiscovered = True
107-
108102
for app in settings.INSTALLED_APPS:
109103
# As of Django 1.7, settings.INSTALLED_APPS may contain classes instead of modules, hence the try/except
110104
# See here: https://docs.djangoproject.com/en/dev/releases/1.7/#introspecting-applications

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#/usr/bin/env python
1+
#!/usr/bin/env python
22
import codecs
33
import os
44
from setuptools import setup, find_packages
@@ -7,7 +7,7 @@
77

88
# Workaround for multiprocessing/nose issue. See http://bugs.python.org/msg170215
99
try:
10-
import multiprocessing
10+
import multiprocessing # NOQA
1111
except ImportError:
1212
pass
1313

@@ -19,13 +19,15 @@
1919

2020
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
2121

22+
2223
def exec_file(filepath, globalz=None, localz=None):
2324
exec(read(filepath), globalz, localz)
2425

26+
2527
# Load package meta from the pkgmeta module without loading imagekit.
2628
pkgmeta = {}
2729
exec_file(os.path.join(os.path.dirname(__file__),
28-
'imagekit', 'pkgmeta.py'), pkgmeta)
30+
'imagekit', 'pkgmeta.py'), pkgmeta)
2931

3032

3133
setup(

0 commit comments

Comments
 (0)