diff --git a/apps/converter/api.py b/apps/converter/api.py index 82d183bdc0..bdcfe40f77 100644 --- a/apps/converter/api.py +++ b/apps/converter/api.py @@ -67,6 +67,8 @@ def convert(input_filepath, output_filepath=None, cleanup_files=False, *args, ** rotation = kwargs.get('rotation', DEFAULT_ROTATION) page = kwargs.get('page', DEFAULT_PAGE_NUMBER) transformations = kwargs.get('transformations', []) + if transformations is None: + transformations = [] unoconv_output = None diff --git a/apps/documents/forms.py b/apps/documents/forms.py index 5eba57bb09..9fdc19c5c2 100644 --- a/apps/documents/forms.py +++ b/apps/documents/forms.py @@ -113,21 +113,38 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget): output.append(u'
') for page in value.documentpage_set.all(): - output.append( - u'''
-
%(page_string)s %(page)s
-
- + try: + page.document.get_valid_image() + template = u'''
+
%(page_string)s %(page)s
+
+ +
''' + except: + template = u'''
+
%(page_string)s %(page)s
+
%(string)s - -
- -
''' % { +
+ +
''' + + + output.append(template % { 'url': reverse('document_page_view', args=[page.pk]), 'img': reverse('document_preview_multipage', args=[value.pk]), 'page': page.page_number, diff --git a/apps/documents/models.py b/apps/documents/models.py index efdd6a6841..d4bb53f274 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -248,10 +248,13 @@ class Document(models.Model): document_file = document_save_to_temp_dir(self, self.checksum) return convert(document_file, output_filepath=cache_file_path, page=page, transformations=transformations) + def get_valid_image(self, size=DISPLAY_SIZE, page=DEFAULT_PAGE_NUMBER, zoom=DEFAULT_ZOOM_LEVEL, rotation=DEFAULT_ROTATION): + image_cache_name = self.get_image_cache_name(page=page) + return convert(image_cache_name, cleanup_files=False, size=size, zoom=zoom, rotation=rotation) + def get_image(self, size=DISPLAY_SIZE, page=DEFAULT_PAGE_NUMBER, zoom=DEFAULT_ZOOM_LEVEL, rotation=DEFAULT_ROTATION): try: - image_cache_name = self.get_image_cache_name(page=page) - return convert(image_cache_name, cleanup_files=False, size=size, zoom=zoom, rotation=rotation) + return self.get_valid_image(size=size, page=page, zoom=zoom, rotation=rotation) except UnknownFileFormat: return get_icon_file_path(self.file_mimetype) except UnkownConvertError: diff --git a/apps/documents/widgets.py b/apps/documents/widgets.py index 56657bfcef..b875aade25 100644 --- a/apps/documents/widgets.py +++ b/apps/documents/widgets.py @@ -6,7 +6,13 @@ from django.core.urlresolvers import reverse def document_thumbnail(document): try: - return mark_safe(u'%(string)s' % { + document.get_valid_image() + template = u'%(string)s' + except: + template = u'%(string)s' + + try: + return mark_safe(template % { 'url': reverse('document_preview', args=[document.pk]), 'thumbnail': reverse('document_thumbnail', args=[document.pk]), 'static_url': settings.STATIC_URL, diff --git a/apps/grouping/forms.py b/apps/grouping/forms.py index 1fa96b3ab9..389987ab7a 100644 --- a/apps/grouping/forms.py +++ b/apps/grouping/forms.py @@ -30,8 +30,9 @@ class DocumentGroupImageWidget(forms.widgets.Widget): for document in value['group_data']: tags_template = get_tags_inline_widget(document) - output.append( - u'''
+ try: + document.get_valid_image() + template = u'''
%(document_name)s
%(page_string)s: %(document_pages)d
%(tags_template)s @@ -46,7 +47,24 @@ class DocumentGroupImageWidget(forms.widgets.Widget): -
''' % { +
''' + except: + template = u'''
+
%(document_name)s
+
%(page_string)s: %(document_pages)d
+ %(tags_template)s +
+ %(string)s + +
+ +
''' + + output.append(template % { 'url': reverse('document_view_simple', args=[document.pk]), 'img': reverse('document_preview_multipage', args=[document.pk]), 'current': u'border: 5px solid black; padding: 3px;' if value['current_document'] == document else u'', 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, diff --git a/apps/tags/widgets.py b/apps/tags/widgets.py index d201516255..ab1b6762b1 100644 --- a/apps/tags/widgets.py +++ b/apps/tags/widgets.py @@ -10,8 +10,6 @@ def get_tags_inline_widget(document): tag_count = document.tags.count() if tag_count: tags_template.append(u'
') - tags_template.append(u'
%(tag_string)s: %(tag_count)s
' % { - 'tag_string': _(u'Tags'), 'tag_count': tag_count}) for tag in document.tags.all(): tags_template.append(u'' % (tag.tagproperties_set.get().get_color_code(), tag.name))