Skip to content

Commit

Permalink
Merge branch 'release/4.0.1'
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
vstoykov committed May 17, 2017
2 parents acefa91 + 681b85d commit ef45747
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
31 changes: 31 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,37 @@ Django admin classes:
admin.site.register(Photo, PhotoAdmin)
To use specs defined outside of models:

.. code-block:: python
from django.contrib import admin
from imagekit.admin import AdminThumbnail
from imagekit import ImageSpec
from imagekit.processors import ResizeToFill
from imagekit.cachefiles import ImageCacheFile
from .models import Photo
class AdminThumbnailSpec(ImageSpec):
processors = [ResizeToFill(100, 30)]
format = 'JPEG'
options = {'quality': 60 }
def cached_admin_thumb(instance):
# `image` is the name of the image field on the model
cached = ImageCacheFile(AdminThumbnailSpec(instance.image))
# only generates the first time, subsequent calls use cache
cached.generate()
return cached
class PhotoAdmin(admin.ModelAdmin):
list_display = ('__str__', 'admin_thumbnail')
admin_thumbnail = AdminThumbnail(image_field=cached_admin_thumb)
admin.site.register(Photo, PhotoAdmin)
AdminThumbnail can even use a custom template. For more information, see
``imagekit.admin.AdminThumbnail``.

Expand Down
2 changes: 1 addition & 1 deletion imagekit/pkgmeta.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = 'django-imagekit'
__author__ = 'Matthew Tretter, Venelin Stoykov, Eric Eldredge, Bryan Veloso, Greg Newman, Chris Drackett, Justin Driscoll'
__version__ = '4.0'
__version__ = '4.0.1'
__license__ = 'BSD'
__all__ = ['__title__', '__author__', '__version__', '__license__']
8 changes: 1 addition & 7 deletions imagekit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def autodiscover():
_autodiscover_modules_fallback()
else:
autodiscover_modules('imagegenerators')
_autodiscovered = True


def _autodiscover_modules_fallback():
Expand All @@ -91,20 +92,13 @@ def _autodiscover_modules_fallback():
Used for Django versions < 1.7
"""
global _autodiscovered

if _autodiscovered:
return

from django.conf import settings
try:
from importlib import import_module
except ImportError:
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule

_autodiscovered = True

for app in settings.INSTALLED_APPS:
# As of Django 1.7, settings.INSTALLED_APPS may contain classes instead of modules, hence the try/except
# See here: https://docs.djangoproject.com/en/dev/releases/1.7/#introspecting-applications
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/usr/bin/env python
#!/usr/bin/env python
import codecs
import os
from setuptools import setup, find_packages
Expand All @@ -7,7 +7,7 @@

# Workaround for multiprocessing/nose issue. See http://bugs.python.org/msg170215
try:
import multiprocessing
import multiprocessing # NOQA
except ImportError:
pass

Expand All @@ -19,13 +19,15 @@

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


def exec_file(filepath, globalz=None, localz=None):
exec(read(filepath), globalz, localz)


# Load package meta from the pkgmeta module without loading imagekit.
pkgmeta = {}
exec_file(os.path.join(os.path.dirname(__file__),
'imagekit', 'pkgmeta.py'), pkgmeta)
'imagekit', 'pkgmeta.py'), pkgmeta)


setup(
Expand Down

0 comments on commit ef45747

Please sign in to comment.