mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-16 21:30:23 +00:00
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.
This commit is contained in:
commit
ef45747bf9
4 changed files with 38 additions and 11 deletions
31
README.rst
31
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(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``.
|
||||
|
||||
|
|
|
|||
|
|
@ -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__']
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ def autodiscover():
|
|||
_autodiscover_modules_fallback()
|
||||
else:
|
||||
autodiscover_modules('imagegenerators')
|
||||
_autodiscovered = True
|
||||
|
||||
|
||||
def _autodiscover_modules_fallback():
|
||||
|
|
@ -91,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
|
||||
|
|
@ -103,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
|
||||
|
|
|
|||
8
setup.py
8
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 @@ import sys
|
|||
|
||||
# Workaround for multiprocessing/nose issue. See http://bugs.python.org/msg170215
|
||||
try:
|
||||
import multiprocessing
|
||||
import multiprocessing # NOQA
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
|
@ -19,13 +19,15 @@ if 'publish' in sys.argv:
|
|||
|
||||
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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue