diff --git a/AUTHORS b/AUTHORS index 34c4c8d..255827b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,8 +6,8 @@ HZDG_. Maintainers ----------- -* `Bryan Veloso`_ * `Matthew Tretter`_ +* `Bryan Veloso`_ * `Chris Drackett`_ * `Greg Newman`_ diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index e36fd1c..b9f2de2 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -21,4 +21,4 @@ __ http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html __ https://groups.google.com/forum/#!forum/django-imagekit __ irc://irc.freenode.net/imagekit .. _nose: https://nose.readthedocs.org/en/latest/ -__ https://github.com/jdriscoll/django-imagekit/tree/develop/tests +__ https://github.com/matthewwithanm/django-imagekit/tree/develop/tests diff --git a/README.rst b/README.rst index c2b60a7..8a30efd 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ |Build Status|_ -.. |Build Status| image:: https://travis-ci.org/jdriscoll/django-imagekit.png?branch=develop -.. _Build Status: https://travis-ci.org/jdriscoll/django-imagekit +.. |Build Status| image:: https://travis-ci.org/matthewwithanm/django-imagekit.png?branch=develop +.. _Build Status: https://travis-ci.org/matthewwithanm/django-imagekit ImageKit is a Django app for processing images. Need a thumbnail? A black-and-white version of a user-uploaded image? ImageKit will make them for @@ -21,7 +21,6 @@ Installation 1. Install `PIL`_ or `Pillow`_. (If you're using an ``ImageField`` in Django, you should have already done this.) 2. ``pip install django-imagekit`` - (or clone the source and put the imagekit module on your path) 3. Add ``'imagekit'`` to your ``INSTALLED_APPS`` list in your project's settings.py .. note:: If you've never seen Pillow before, it considers itself a @@ -177,7 +176,7 @@ to register it. .. code-block:: python - from imagekit import ImageSpec + from imagekit import ImageSpec, register from imagekit.processors import ResizeToFill class Thumbnail(ImageSpec): @@ -371,7 +370,7 @@ it in your spec's ``processors`` list: options = {'quality': 60} Note that when you import a processor from ``imagekit.processors``, imagekit -in turn imports the processor from `PILKit`_. So if you are looking for +in turn imports the processor from `PILKit`_. So if you are looking for available processors, look at PILKit. .. _`PILKit`: https://github.com/matthewwithanm/pilkit @@ -414,7 +413,7 @@ of generator ids in order to generate images selectively. Community ========= -Please use `the GitHub issue tracker `_ +Please use `the GitHub issue tracker `_ to report bugs with django-imagekit. `A mailing list `_ also exists to discuss the project and ask questions, as well as the official `#imagekit `_ channel on Freenode. @@ -436,5 +435,5 @@ Check out our `contributing guidelines`__ for more information about pitching in with ImageKit. -__ https://github.com/jdriscoll/django-imagekit/issues?labels=contributor-friendly&state=open -__ https://github.com/jdriscoll/django-imagekit/blob/develop/CONTRIBUTING.rst +__ https://github.com/matthewwithanm/django-imagekit/issues?labels=contributor-friendly&state=open +__ https://github.com/matthewwithanm/django-imagekit/blob/develop/CONTRIBUTING.rst diff --git a/imagekit/cachefiles/__init__.py b/imagekit/cachefiles/__init__.py index 7d8233a..2c602ff 100644 --- a/imagekit/cachefiles/__init__.py +++ b/imagekit/cachefiles/__init__.py @@ -1,7 +1,7 @@ from django.conf import settings from django.core.files import File from django.core.files.images import ImageFile -from django.utils.functional import LazyObject +from django.utils.functional import SimpleLazyObject from ..files import BaseIKFile from ..registry import generator_registry from ..signals import content_required, existence_required @@ -130,27 +130,12 @@ class ImageCacheFile(BaseIKFile, ImageFile): return self.cachefile_backend.exists(self) -class LazyImageCacheFile(LazyObject): +class LazyImageCacheFile(SimpleLazyObject): def __init__(self, generator_id, *args, **kwargs): - super(LazyImageCacheFile, self).__init__() - def setup(): generator = generator_registry.get(generator_id, *args, **kwargs) - self._wrapped = ImageCacheFile(generator) - - self.__dict__['_setup'] = setup + return ImageCacheFile(generator) + super(LazyImageCacheFile, self).__init__(setup) def __repr__(self): - if self._wrapped is None: - self._setup() - return '<%s: %s>' % (self.__class__.__name__, self or 'None') - - def __str__(self): - if self._wrapped is None: - self._setup() - return str(self._wrapped) - - def __unicode__(self): - if self._wrapped is None: - self._setup() - return unicode(self._wrapped) + return '<%s: %s>' % (self.__class__.__name__, str(self) or 'None') diff --git a/imagekit/conf.py b/imagekit/conf.py index 1edad95..2900da1 100644 --- a/imagekit/conf.py +++ b/imagekit/conf.py @@ -24,14 +24,19 @@ class ImageKitConf(AppConf): else: dummy_cache = 'django.core.cache.backends.dummy.DummyCache' + # DEFAULT_CACHE_ALIAS doesn't exist in Django<=1.2 + try: + from django.core.cache import DEFAULT_CACHE_ALIAS as default_cache_alias + except ImportError: + default_cache_alias = 'default' + if settings.DEBUG: value = dummy_cache + elif default_cache_alias in getattr(settings, 'CACHES', {}): + value = default_cache_alias else: - value = ( - getattr(settings, 'CACHES', {}).get('default') - or getattr(settings, 'CACHE_BACKEND', None) - or dummy_cache - ) + value = getattr(settings, 'CACHE_BACKEND', None) or dummy_cache + return value def configure_default_file_storage(self, value): diff --git a/imagekit/management/commands/generateimages.py b/imagekit/management/commands/generateimages.py index 099fe3d..444440a 100644 --- a/imagekit/management/commands/generateimages.py +++ b/imagekit/management/commands/generateimages.py @@ -27,7 +27,7 @@ well as "a:b" and "a:b:c".""") try: # TODO: Allow other validation actions through command option file.generate() - except Exception, err: + except Exception as err: # TODO: How should we handle failures? Don't want to error, but should call it out more than this. self.stdout.write(' FAILED: %s\n' % err) diff --git a/imagekit/models/fields/__init__.py b/imagekit/models/fields/__init__.py index 3f1a2f6..91c6252 100644 --- a/imagekit/models/fields/__init__.py +++ b/imagekit/models/fields/__init__.py @@ -39,7 +39,7 @@ class ImageSpecField(SpecHostField): cachefile_strategy=cachefile_strategy, spec=spec, spec_id=id) - # TODO: Allow callable for source. See https://github.com/jdriscoll/django-imagekit/issues/158#issuecomment-10921664 + # TODO: Allow callable for source. See https://github.com/matthewwithanm/django-imagekit/issues/158#issuecomment-10921664 self.source = source def contribute_to_class(self, cls, name): diff --git a/imagekit/pkgmeta.py b/imagekit/pkgmeta.py index e7813dd..feb0225 100644 --- a/imagekit/pkgmeta.py +++ b/imagekit/pkgmeta.py @@ -1,5 +1,5 @@ __title__ = 'django-imagekit' __author__ = 'Justin Driscoll, Bryan Veloso, Greg Newman, Chris Drackett, Matthew Tretter, Eric Eldredge' -__version__ = '3.0.0' +__version__ = '3.0.1' __license__ = 'BSD' __all__ = ['__title__', '__author__', '__version__', '__license__'] diff --git a/imagekit/specs/sourcegroups.py b/imagekit/specs/sourcegroups.py index dd804dc..2008f59 100644 --- a/imagekit/specs/sourcegroups.py +++ b/imagekit/specs/sourcegroups.py @@ -47,7 +47,7 @@ class ModelSignalRouter(object): ``ImageFieldSourceGroup``s. This class encapsulates that functionality. Related: - https://github.com/jdriscoll/django-imagekit/issues/126 + https://github.com/matthewwithanm/django-imagekit/issues/126 https://code.djangoproject.com/ticket/9318 """ diff --git a/setup.py b/setup.py index 393c019..da959a0 100644 --- a/setup.py +++ b/setup.py @@ -31,12 +31,12 @@ setup( version=pkgmeta['__version__'], description='Automated image processing for Django models.', long_description=read(os.path.join(os.path.dirname(__file__), 'README.rst')), - author='Justin Driscoll', - author_email='justin@driscolldev.com', + author='Matthew Tretter', + author_email='m@tthewwithanm.com', maintainer='Bryan Veloso', maintainer_email='bryan@revyver.com', license='BSD', - url='http://github.com/jdriscoll/django-imagekit/', + url='http://github.com/matthewwithanm/django-imagekit/', packages=find_packages(), zip_safe=False, include_package_data=True, diff --git a/tests/test_cachefiles.py b/tests/test_cachefiles.py index 957b132..4338a82 100644 --- a/tests/test_cachefiles.py +++ b/tests/test_cachefiles.py @@ -1,13 +1,12 @@ from django.conf import settings from hashlib import md5 -from imagekit.cachefiles import ImageCacheFile +from imagekit.cachefiles import ImageCacheFile, LazyImageCacheFile from imagekit.cachefiles.backends import Simple from nose.tools import raises, eq_ -import random -import string from .imagegenerators import TestSpec from .utils import (assert_file_is_truthy, assert_file_is_falsy, - DummyAsyncCacheFileBackend, get_unique_image_file) + DummyAsyncCacheFileBackend, get_unique_image_file, + get_image_file) def test_no_source_falsiness(): @@ -75,3 +74,15 @@ def test_memcached_cache_key(): settings.IMAGEKIT_CACHE_PREFIX, '1' * (200 - len(':') - 32 - len(settings.IMAGEKIT_CACHE_PREFIX)), md5('%s%s-state' % (settings.IMAGEKIT_CACHE_PREFIX, filename)).hexdigest())) + + +def test_lazyfile_stringification(): + file = LazyImageCacheFile('testspec', source=None) + eq_(str(file), '') + eq_(repr(file), '') + + source_file = get_image_file() + file = LazyImageCacheFile('testspec', source=source_file) + file.name = 'a.jpg' + eq_(str(file), 'a.jpg') + eq_(repr(file), '') diff --git a/tests/test_sourcegroups.py b/tests/test_sourcegroups.py index 12eed3b..c69b11f 100644 --- a/tests/test_sourcegroups.py +++ b/tests/test_sourcegroups.py @@ -32,7 +32,7 @@ def test_no_source_saved_signal(): Creating a new instance without an image shouldn't cause the source_saved signal to be dispatched. - https://github.com/jdriscoll/django-imagekit/issues/214 + https://github.com/matthewwithanm/django-imagekit/issues/214 """ source_group = ImageFieldSourceGroup(ImageModel, 'image')