From 934a5283ad823a5c637f875f07dcaf5eb617e2be Mon Sep 17 00:00:00 2001 From: mikob Date: Mon, 10 Apr 2017 17:46:29 +0900 Subject: [PATCH 1/6] Improved docs to include example on how to use plain ImageSpec (defined outside of model, not ImageSpecField) with AdminThumbnail. --- README.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.rst b/README.rst index 84ec2944..23d26ac3 100644 --- a/README.rst +++ b/README.rst @@ -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(model): + # `image` is the name of the image field on the model + cached = ImageCacheFile(AdminThumbnailSpec(model.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``. From c24455ef36c36f0a844a98e692e60d6eaae15074 Mon Sep 17 00:00:00 2001 From: mikob Date: Wed, 10 May 2017 18:03:28 +0900 Subject: [PATCH 2/6] Update README.st change model->instance for clarity in defining specs outside of models. --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 23d26ac3..7d40b053 100644 --- a/README.rst +++ b/README.rst @@ -423,9 +423,9 @@ To use specs defined outside of models: format = 'JPEG' options = {'quality': 60 } - def cached_admin_thumb(model): + def cached_admin_thumb(instance): # `image` is the name of the image field on the model - cached = ImageCacheFile(AdminThumbnailSpec(model.image)) + cached = ImageCacheFile(AdminThumbnailSpec(instance.image)) # only generates the first time, subsequent calls use cache cached.generate() return cached From c74d8424b88c0bffe9a3d18cf09b33ea12ea4551 Mon Sep 17 00:00:00 2001 From: Moritz Pfeiffer Date: Tue, 16 May 2017 14:19:05 +0200 Subject: [PATCH 3/6] Added huge performance improvement by running imagekit.utils.autodiscover() only once on Django > 1.7 as it was intended. --- imagekit/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/imagekit/utils.py b/imagekit/utils.py index 27902c9a..03a709ec 100644 --- a/imagekit/utils.py +++ b/imagekit/utils.py @@ -79,6 +79,7 @@ def autodiscover(): _autodiscover_modules_fallback() else: autodiscover_modules('imagegenerators') + _autodiscovered = True def _autodiscover_modules_fallback(): From 36fa53e249726f88090de24bb6834f2c3285675a Mon Sep 17 00:00:00 2001 From: Moritz Pfeiffer Date: Wed, 17 May 2017 09:51:24 +0200 Subject: [PATCH 4/6] Cleaned up _autodiscovered flag handling. --- imagekit/utils.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/imagekit/utils.py b/imagekit/utils.py index 03a709ec..ca6727ae 100644 --- a/imagekit/utils.py +++ b/imagekit/utils.py @@ -79,7 +79,7 @@ def autodiscover(): _autodiscover_modules_fallback() else: autodiscover_modules('imagegenerators') - _autodiscovered = True + _autodiscovered = True def _autodiscover_modules_fallback(): @@ -92,11 +92,6 @@ 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 @@ -104,8 +99,6 @@ def _autodiscover_modules_fallback(): 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 From f96dadbfe0f405282cd256390746eaf6bb9fd0af Mon Sep 17 00:00:00 2001 From: Venelin Stoykov Date: Wed, 17 May 2017 17:45:22 +0300 Subject: [PATCH 5/6] Bump version to 4.0.1 --- imagekit/pkgmeta.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imagekit/pkgmeta.py b/imagekit/pkgmeta.py index 9a389ab8..6c9eefe4 100644 --- a/imagekit/pkgmeta.py +++ b/imagekit/pkgmeta.py @@ -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__'] From 681b85d7bffbae3fa9518088ff84585d3562b97a Mon Sep 17 00:00:00 2001 From: Venelin Stoykov Date: Wed, 17 May 2017 18:12:57 +0300 Subject: [PATCH 6/6] stylling and linting fixes to setup.py --- setup.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 8244049a..2af1ad58 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -#/usr/bin/env python +#!/usr/bin/env python import codecs import os from setuptools import setup, find_packages @@ -7,7 +7,7 @@ # Workaround for multiprocessing/nose issue. See http://bugs.python.org/msg170215 try: - import multiprocessing + import multiprocessing # NOQA except ImportError: pass @@ -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(