Ticket #674: img.diff

File img.diff, 1.5 KB (added by Nebojša Đorđević - nesh <nesh@…>, 10 years ago)

patch

  • django/contrib/admin/templatetags/admin_list.py

     
    149149            # ImageFields are special: Use a thumbnail.
    150150            elif isinstance(f, meta.ImageField):
    151151                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)
    153153            # FloatFields are special: Zero-pad the decimals.
    154154            elif isinstance(f, meta.FloatField):
    155155                if field_val is not None:
  • django/parts/media/photos.py

     
    1 import re
    2 
     1import re, os
     2from django.conf.settings import MEDIA_URL
    33def get_thumbnail_url(photo_url, width):
    44    bits = photo_url.split('/')
    55    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
Back to Top