diff --git a/apps/sources/staging.py b/apps/sources/staging.py index b2edd41848..774bc01db8 100644 --- a/apps/sources/staging.py +++ b/apps/sources/staging.py @@ -6,6 +6,8 @@ from django.core.files.base import File from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ugettext +from documents.conf.settings import THUMBNAIL_SIZE + from mimetype.api import get_icon_file_path, get_error_icon_file_path, \ get_mimetype from converter.api import convert, cache_cleanup @@ -134,9 +136,13 @@ class StagingFile(object): else: raise OSError(ugettext(u'Unable to delete staging file: %s') % exc) + def get_valid_image(self, size=THUMBNAIL_SIZE, transformations=None): + return convert(self.filepath, size=size, cleanup_files=False, transformations=transformations) + def get_image(self, size, transformations): try: - return convert(self.filepath, size=size, cleanup_files=False, transformations=transformations) + return self.get_valid_image(size=size, transformations=transformations) + #return convert(self.filepath, size=size, cleanup_files=False, transformations=transformations) except UnknownFileFormat: mimetype, encoding = get_mimetype(open(self.filepath, 'rb'), self.filepath) return get_icon_file_path(mimetype) diff --git a/apps/sources/widgets.py b/apps/sources/widgets.py index 59f4de1f5a..665303e427 100644 --- a/apps/sources/widgets.py +++ b/apps/sources/widgets.py @@ -26,7 +26,13 @@ class FamFamRadioSelect(forms.widgets.RadioSelect): def staging_file_thumbnail(staging_file): - return mark_safe(u'%(string)s' % { + try: + staging_file.get_valid_image() + template = u'%(string)s' + except: + template = u'%(string)s' + + return mark_safe(template % { 'url': reverse('staging_file_preview', args=[staging_file.source.source_type, staging_file.source.pk, staging_file.id]), 'thumbnail': reverse('staging_file_thumbnail', args=[staging_file.source.pk, staging_file.id]), 'static_url': settings.STATIC_URL,