diff --git a/mayan/apps/document_signatures/managers.py b/mayan/apps/document_signatures/managers.py index 6f0fbc888a..4898df1828 100644 --- a/mayan/apps/document_signatures/managers.py +++ b/mayan/apps/document_signatures/managers.py @@ -32,19 +32,25 @@ class DocumentVersionSignatureManager(models.Manager): document_signature.save() def has_detached_signature(self, document): - document_signature = self.get_document_signature(document) - - if document_signature.signature_file: - return True - else: + try: + document_signature = self.get_document_signature(document) + except ValueError: return False + else: + if document_signature.signature_file: + return True + else: + return False def has_embedded_signature(self, document): logger.debug('document: %s' % document) - document_signature = self.get_document_signature(document) - - return document_signature.has_embedded_signature + try: + document_signature = self.get_document_signature(document) + except ValueError: + return False + else: + return document_signature.has_embedded_signature def detached_signature(self, document): document_signature = self.get_document_signature(document) diff --git a/mayan/apps/document_signatures/views.py b/mayan/apps/document_signatures/views.py index 132db4b8e8..14d1a550aa 100644 --- a/mayan/apps/document_signatures/views.py +++ b/mayan/apps/document_signatures/views.py @@ -15,7 +15,7 @@ from django.utils.translation import ugettext_lazy as _ from acls.models import AccessEntry from filetransfers.api import serve_file -from django_gpg.api import SIGNATURE_STATES +from django_gpg.api import SIGNATURE_STATE_NONE, SIGNATURE_STATES from documents.models import Document, RecentDocument from permissions.models import Permission @@ -37,9 +37,13 @@ def document_verify(request, document_pk): RecentDocument.objects.add_document_for_user(request.user, document) - signature = DocumentVersionSignature.objects.verify_signature(document) - - signature_state = SIGNATURE_STATES.get(getattr(signature, 'status', None)) + try: + signature = DocumentVersionSignature.objects.verify_signature(document) + except AttributeError: + signature_state = SIGNATURE_STATES.get(SIGNATURE_STATE_NONE) + signature = None + else: + signature_state = SIGNATURE_STATES.get(getattr(signature, 'status', None)) widget = (u'' % (settings.STATIC_URL, signature_state['icon'])) paragraphs = [ @@ -49,10 +53,13 @@ def document_verify(request, document_pk): }, ] - if DocumentVersionSignature.objects.has_embedded_signature(document): - signature_type = _(u'embedded') - else: - signature_type = _(u'detached') + try: + if DocumentVersionSignature.objects.has_embedded_signature(document): + signature_type = _(u'embedded') + else: + signature_type = _(u'detached') + except ValueError: + signature_type = _(u'None') if signature: paragraphs.extend( diff --git a/mayan/apps/documents/__init__.py b/mayan/apps/documents/__init__.py index d67ffef569..6e93f6a158 100644 --- a/mayan/apps/documents/__init__.py +++ b/mayan/apps/documents/__init__.py @@ -100,7 +100,7 @@ register_maintenance_links([document_find_all_duplicates, document_update_page_c register_model_list_columns(Document, [ { 'name': _(u'thumbnail'), 'attribute': - encapsulate(lambda x: document_thumbnail(x, gallery_name='document_list', title=x.filename, size=THUMBNAIL_SIZE)) + encapsulate(lambda x: document_thumbnail(x, gallery_name='document_list', title=getattr(x, 'filename', None), size=THUMBNAIL_SIZE)) }, ]) diff --git a/mayan/apps/documents/forms.py b/mayan/apps/documents/forms.py index 015971bd31..4141a06f08 100644 --- a/mayan/apps/documents/forms.py +++ b/mayan/apps/documents/forms.py @@ -86,7 +86,10 @@ class DocumentPreviewForm(forms.Form): document = kwargs.pop('document', None) super(DocumentPreviewForm, self).__init__(*args, **kwargs) self.fields['preview'].initial = document - self.fields['preview'].label = _(u'Document pages (%s)') % document.pages.count() + try: + self.fields['preview'].label = _(u'Document pages (%d)') % document.pages.count() + except AttributeError: + self.fields['preview'].label = _(u'Document pages (%d)') % 0 preview = forms.CharField(widget=DocumentPagesCarouselWidget()) @@ -131,7 +134,8 @@ class DocumentForm(forms.ModelForm): label=_(u'Quick document rename')) if instance: - self.version_fields(instance) + if instance.latest_version: + self.version_fields(instance) def version_fields(self, document): self.fields['version_update'] = forms.ChoiceField( @@ -186,10 +190,14 @@ class DocumentForm_edit(DocumentForm): def __init__(self, *args, **kwargs): super(DocumentForm_edit, self).__init__(*args, **kwargs) - self.fields.pop('serial') - self.fields.pop('release_level') - self.fields.pop('version_update') - self.fields.pop('comment') + if kwargs['instance'].latest_version: + self.fields.pop('serial') + self.fields.pop('release_level') + self.fields.pop('version_update') + self.fields.pop('comment') + else: + self.fields.pop('new_filename') + self.fields.pop('use_file_name') @@ -212,7 +220,12 @@ class DocumentContentForm(forms.Form): super(DocumentContentForm, self).__init__(*args, **kwargs) content = [] self.fields['contents'].initial = u'' - for page in self.document.pages.all(): + try: + document_pages = self.document.pages.all() + except AttributeError: + document_pages = [] + + for page in document_pages: if page.content: content.append(conditional_escape(force_unicode(page.content))) content.append(u'\n\n\n
- %s %s -

\n\n\n' % (ugettext(u'Page'), page.page_number)) diff --git a/mayan/apps/documents/views.py b/mayan/apps/documents/views.py index b7c8ad928e..ba735e6aab 100644 --- a/mayan/apps/documents/views.py +++ b/mayan/apps/documents/views.py @@ -96,19 +96,24 @@ def document_view(request, document_id, advanced=False): subtemplates_list = [] if advanced: - document_properties_form = DocumentPropertiesForm(instance=document, extra_fields=[ - {'label': _(u'Filename'), 'field': 'filename'}, - {'label': _(u'File mimetype'), 'field': lambda x: x.file_mimetype or _(u'None')}, - {'label': _(u'File mime encoding'), 'field': lambda x: x.file_mime_encoding or _(u'None')}, - {'label': _(u'File size'), 'field': lambda x: pretty_size(x.size) if x.size else '-'}, - {'label': _(u'Exists in storage'), 'field': 'exists'}, - {'label': _(u'File path in storage'), 'field': 'file'}, + document_fields = [ {'label': _(u'Date added'), 'field': lambda x: x.date_added.date()}, {'label': _(u'Time added'), 'field': lambda x: unicode(x.date_added.time()).split('.')[0]}, - {'label': _(u'Checksum'), 'field': 'checksum'}, {'label': _(u'UUID'), 'field': 'uuid'}, - {'label': _(u'Pages'), 'field': 'page_count'}, - ]) + ] + if document.latest_version: + document_fields.extend([ + {'label': _(u'Filename'), 'field': 'filename'}, + {'label': _(u'File mimetype'), 'field': lambda x: x.file_mimetype or _(u'None')}, + {'label': _(u'File mime encoding'), 'field': lambda x: x.file_mime_encoding or _(u'None')}, + {'label': _(u'File size'), 'field': lambda x: pretty_size(x.size) if x.size else '-'}, + {'label': _(u'Exists in storage'), 'field': 'exists'}, + {'label': _(u'File path in storage'), 'field': 'file'}, + {'label': _(u'Checksum'), 'field': 'checksum'}, + {'label': _(u'Pages'), 'field': 'page_count'}, + ]) + + document_properties_form = DocumentPropertiesForm(instance=document, extra_fields=document_fields) subtemplates_list.append( { @@ -235,8 +240,12 @@ def document_edit(request, document_id): return HttpResponseRedirect(document.get_absolute_url()) else: - form = DocumentForm_edit(instance=document, initial={ - 'new_filename': document.filename, 'description': document.description}) + if document.latest_version: + form = DocumentForm_edit(instance=document, initial={ + 'new_filename': document.filename, 'description': document.description}) + else: + form = DocumentForm_edit(instance=document, initial={ + 'description': document.description}) return render_to_response('generic_form.html', { 'form': form, diff --git a/mayan/apps/documents/widgets.py b/mayan/apps/documents/widgets.py index 2a6d7d7a4c..91d167f5f9 100644 --- a/mayan/apps/documents/widgets.py +++ b/mayan/apps/documents/widgets.py @@ -38,8 +38,12 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget): output = [] output.append(u'