easy_thumbnails.widgets: 28 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/easy_thumbnails/widgets.py

Stats: 0 executed, 25 missed, 3 excluded, 12 ignored

  1. from django.forms.widgets import ClearableFileInput
  2. from django.utils.safestring import mark_safe
  3. from easy_thumbnails.files import get_thumbnailer
  4. class ImageClearableFileInput(ClearableFileInput):
  5. template_with_initial = u'%(clear_template)s<br />'\
  6. u'%(input_text)s: %(input)s'
  7. template_with_thumbnail = u'%(template)s<br />'\
  8. u'<a href="%(source_url)s" target="_blank">%(thumb)s</a>'
  9. def __init__(self, thumbnail_options=None, attrs=None):
  10. thumbnail_options = thumbnail_options or {}
  11. thumbnail_options = thumbnail_options.copy()
  12. if not 'size' in thumbnail_options:
  13. thumbnail_options['size'] = (80, 80)
  14. self.thumbnail_options = thumbnail_options.copy()
  15. super(ImageClearableFileInput, self).__init__(attrs)
  16. def thumbnail_id(self, name):
  17. return '%s_thumb_id' % name
  18. def get_thumbnail(self, value):
  19. thumbnailer = get_thumbnailer(value, value.name)
  20. thumbnailer.source_storage = value.storage
  21. if hasattr(value, 'thumbnail_storage'):
  22. thumbnailer.thumbnail_storage = value.thumbnail_storage
  23. return thumbnailer.get_thumbnail(self.thumbnail_options)
  24. def render(self, name, value, attrs=None):
  25. output = super(ImageClearableFileInput, self).render(name, value, attrs)
  26. if not value or not hasattr(value, 'storage'):
  27. return output
  28. thumb = self.get_thumbnail(value)
  29. substitution = {
  30. 'template': output,
  31. 'thumb': thumb.tag(id=self.thumbnail_id(name)),
  32. 'source_url': value.storage.url(value.name),
  33. }
  34. return mark_safe(self.template_with_thumbnail % substitution)