Ticket #674: img.diff
File img.diff, 1.5 KB (added by , 19 years ago) |
---|
-
django/contrib/admin/templatetags/admin_list.py
149 149 # ImageFields are special: Use a thumbnail. 150 150 elif isinstance(f, meta.ImageField): 151 151 from django.parts.media.photos import get_thumbnail_url 152 result_repr = '<img src="%s" alt="%s" title="%s" />' % (get_thumbnail_url(getattr(result, 'get_%s_url' % f.name)(), '120'), field_val, field_val)152 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) 153 153 # FloatFields are special: Zero-pad the decimals. 154 154 elif isinstance(f, meta.FloatField): 155 155 if field_val is not None: -
django/parts/media/photos.py
1 import re 2 1 import re, os 2 from django.conf.settings import MEDIA_URL 3 3 def get_thumbnail_url(photo_url, width): 4 4 bits = photo_url.split('/') 5 5 bits[-1] = re.sub(r'(?i)\.(gif|jpg)$', '_t%s.\\1' % width, bits[-1]) 6 return '/'.join(bits) 6 # check if thumbnail exists 7 if os.path.isfile(os.path.join(MEDIA_URL, *bits)): 8 return '/'.join(bits) 9 else: 10 return photo_url