mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-12 01:10:58 +00:00
Merge branch 'develop' of git://github.com/jdriscoll/django-imagekit into develop
* 'develop' of git://github.com/jdriscoll/django-imagekit: `format_to_extension` correctly handles `None` arg Proper handling of empty images and missing fields Fixes error message
This commit is contained in:
commit
115baa9a97
3 changed files with 20 additions and 15 deletions
|
|
@ -21,11 +21,11 @@ class AdminThumbnail(object):
|
|||
self.template = template
|
||||
|
||||
def __call__(self, obj):
|
||||
thumbnail = getattr(obj, self.image_field, None)
|
||||
|
||||
if not thumbnail:
|
||||
raise Exception('The property {0} is not defined on {1}.'.format(
|
||||
obj, self.image_field))
|
||||
try:
|
||||
thumbnail = getattr(obj, self.image_field)
|
||||
except AttributeError:
|
||||
raise Exception('The property %s is not defined on %s.' % \
|
||||
(self.image_field, obj.__class__.__name__))
|
||||
|
||||
original_image = getattr(thumbnail, 'source_file', None) or thumbnail
|
||||
template = self.template or 'imagekit/admin/thumbnail.html'
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
<a href="{{ model.get_absolute_url|default:original_image.url }}">
|
||||
<img src="{{ thumbnail.url }}">
|
||||
</a>
|
||||
{% if thumbnail %}
|
||||
<a href="{{ model.get_absolute_url|default:original_image.url }}">
|
||||
<img src="{{ thumbnail.url }}">
|
||||
</a>
|
||||
{% endif %}
|
||||
|
|
@ -97,9 +97,10 @@ def _extension_to_format(extension):
|
|||
|
||||
|
||||
def _format_to_extension(format):
|
||||
for k, v in Image.EXTENSION.iteritems():
|
||||
if v == format.upper():
|
||||
return k
|
||||
if format:
|
||||
for k, v in Image.EXTENSION.iteritems():
|
||||
if v == format.upper():
|
||||
return k
|
||||
return None
|
||||
|
||||
|
||||
|
|
@ -121,11 +122,13 @@ def format_to_extension(format):
|
|||
"""Returns the first extension that matches the provided format.
|
||||
|
||||
"""
|
||||
extension = _format_to_extension(format)
|
||||
if not extension and _preinit_pil():
|
||||
extension = _format_to_extension(format)
|
||||
if not extension and _init_pil():
|
||||
extension = None
|
||||
if format:
|
||||
extension = _format_to_extension(format)
|
||||
if not extension and _preinit_pil():
|
||||
extension = _format_to_extension(format)
|
||||
if not extension and _init_pil():
|
||||
extension = _format_to_extension(format)
|
||||
if not extension:
|
||||
raise UnknownFormatError(format)
|
||||
return extension
|
||||
|
|
|
|||
Loading…
Reference in a new issue