#674 closed defect (fixed)
ImageField display use undocumented thumbnails for change_list display
Reported by: | nesh <nesh [at] studioquattro [dot] co [dot] yu> | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | |
Cc: | nesh@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm hunting this almost a hour :)
When displayed in admin interface ImageField use some sort of thumbnail (like xxx_t120.jpg). AFAIK this is not documented anywhere.
Also because thumbnail is not auto-generated I'm only got broken links in admin.
First solution, probably, will be some sort of auto-generated thumbnails or something like this (no thumbs, and I'm using i18n branch):
Index: /store/django/django/contrib/admin/views/main.py =================================================================== --- /store/django/django/contrib/admin/views/main.py (revision 987) +++ /store/django/django/contrib/admin/views/main.py (working copy) @@ -414,8 +414,7 @@ result_repr = '<img src="%simg/admin/icon-%s.gif" alt="%s" />' % (ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) # ImageFields are special: Use a thumbnail. elif isinstance(f, meta.ImageField): - from django.parts.media.photos import get_thumbnail_url - result_repr = '<img src="%s" alt="%s" title="%s" />' % (get_thumbnail_url(getattr(result, 'get_%s_url' % f.name)(), '120'), field_val, field_val) + result_repr = '<img src="%s" alt="%s" title="%s" width="120" />' % (getattr(result, 'get_%s_url' % f.name)(), field_val, field_val) # FloatFields are special: Zero-pad the decimals. elif isinstance(f, meta.FloatField): if field_val is not None:
Attachments (1)
Change History (6)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Feel free to use the code from my images module in the stuff project. The code gives your scaleImage and cropImage, two different ways to produce thumbnails from images, using just the python imaging library (that is already needed for some stuff in the ImageField handling, so it's not a new dependency).
comment:3 by , 19 years ago
Update for new admin merge:
- added width="120px" for img tag
- changed
get_thumbnail_url
to return original path if no thumbnail is foundIndex: django/contrib/admin/templatetags/admin_list.py =================================================================== --- django/contrib/admin/templatetags/admin_list.py (revision 1440) +++ django/contrib/admin/templatetags/admin_list.py (working copy) @@ -149,7 +149,7 @@ # ImageFields are special: Use a thumbnail. elif isinstance(f, meta.ImageField): from django.parts.media.photos import get_thumbnail_url - result_repr = '<img src="%s" alt="%s" title="%s" />' % (get_thumbnail_url(getattr(result, 'get_%s_url' % f.name)(), '120'), field_val, field_val) + result_repr = '<img src="%s" alt="%s" title="%s" width="120px" />' % (get_thumbnail_url(getattr(result, 'get_%s_url' % f.name)(), '120'), field_val, field_val) # FloatFields are special: Zero-pad the decimals. elif isinstance(f, meta.FloatField): if field_val is not None: Index: django/parts/media/photos.py =================================================================== --- django/parts/media/photos.py (revision 1440) +++ django/parts/media/photos.py (working copy) @@ -1,6 +1,10 @@ -import re - +import re, os +from django.conf.settings import MEDIA_URL def get_thumbnail_url(photo_url, width): bits = photo_url.split('/') bits[-1] = re.sub(r'(?i)\.(gif|jpg)$', '_t%s.\\1' % width, bits[-1]) - return '/'.join(bits) + # check if thumbnail exists + if os.path.isfile(os.path.join(MEDIA_URL, *bits)): + return '/'.join(bits) + else: + return photo_url
comment:4 by , 19 years ago
Cc: | added |
---|
comment:5 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This was fixed a few weeks ago.
Yes, auto-generated thumbnails would be really useful. Support for several different-sized thumbnails being created at once would be great, too.