diff --git a/apps/documents/__init__.py b/apps/documents/__init__.py index bdd80e0d32..ccaf4da03e 100644 --- a/apps/documents/__init__.py +++ b/apps/documents/__init__.py @@ -20,7 +20,7 @@ from .events import (HISTORY_DOCUMENT_CREATED, HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED) from .links import (document_list, document_list_recent, document_view_simple, document_view_advanced, - document_delete, document_multiple_delete, document_edit, document_preview, + document_delete, document_multiple_delete, document_edit, document_download, document_multiple_download, document_version_download, document_find_duplicates, document_find_all_duplicates, document_update_page_count, document_clear_transformations, document_multiple_clear_transformations, @@ -37,14 +37,11 @@ from .links import (document_list, document_list_recent, from .models import (Document, DocumentPage, DocumentPageTransformation, DocumentType, DocumentTypeFilename, DocumentVersion) -from .permissions import (PERMISSION_DOCUMENT_CREATE, +from .permissions import ( PERMISSION_DOCUMENT_PROPERTIES_EDIT, PERMISSION_DOCUMENT_VIEW, PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD, - PERMISSION_DOCUMENT_TRANSFORM, PERMISSION_DOCUMENT_TOOLS, - PERMISSION_DOCUMENT_EDIT, PERMISSION_DOCUMENT_VERSION_REVERT, - PERMISSION_DOCUMENT_TYPE_EDIT, PERMISSION_DOCUMENT_TYPE_DELETE, - PERMISSION_DOCUMENT_TYPE_CREATE, PERMISSION_DOCUMENT_TYPE_VIEW, - PERMISSION_DOCUMENT_NEW_VERSION) + PERMISSION_DOCUMENT_TRANSFORM, PERMISSION_DOCUMENT_EDIT, + PERMISSION_DOCUMENT_VERSION_REVERT, PERMISSION_DOCUMENT_NEW_VERSION) from .widgets import document_thumbnail # History setup @@ -95,7 +92,7 @@ register_diagnostic('documents', _(u'Documents'), document_missing_list) register_maintenance_links([document_find_all_duplicates, document_update_page_count, document_clear_image_cache], namespace='documents', title=_(u'documents')) register_model_list_columns(Document, [ - {'name':_(u'thumbnail'), 'attribute': + {'name': _(u'thumbnail'), 'attribute': encapsulate(lambda x: document_thumbnail(x)) }, ]) @@ -119,7 +116,7 @@ register_links(Document, [document_view_advanced], menu_name='form_header', posi register_links(Document, [document_history_view], menu_name='form_header') register_links(Document, [document_version_list], menu_name='form_header') -if (validate_path(document_settings.CACHE_PATH) == False) or (not document_settings.CACHE_PATH): +if (not validate_path(document_settings.CACHE_PATH)) or (not document_settings.CACHE_PATH): setattr(document_settings, 'CACHE_PATH', tempfile.mkdtemp()) register_setup(document_type_setup) diff --git a/apps/documents/admin.py b/apps/documents/admin.py index 931fc7de8b..9c15c4b539 100644 --- a/apps/documents/admin.py +++ b/apps/documents/admin.py @@ -20,9 +20,9 @@ class DocumentVersionInline(admin.StackedInline): extra = 1 classes = ('collapse-open',) allow_add = True - #inlines = [ + # inlines = [ # DocumentPageInline, - #] + # ] class DocumentTypeFilenameInline(admin.StackedInline): diff --git a/apps/documents/forms.py b/apps/documents/forms.py index 4e515d5a49..67f452bf8e 100644 --- a/apps/documents/forms.py +++ b/apps/documents/forms.py @@ -1,23 +1,24 @@ from __future__ import absolute_import from django import forms +from django.core.urlresolvers import reverse +from django.utils.encoding import force_unicode +from django.utils.html import conditional_escape +from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext -from django.core.urlresolvers import reverse -from django.utils.safestring import mark_safe -from django.utils.html import conditional_escape -from django.utils.encoding import force_unicode - + +from common.conf.settings import DEFAULT_PAPER_SIZE, DEFAULT_PAGE_ORIENTATION from common.forms import DetailForm from common.literals import PAGE_SIZE_CHOICES, PAGE_ORIENTATION_CHOICES -from common.conf.settings import DEFAULT_PAPER_SIZE, DEFAULT_PAGE_ORIENTATION from common.widgets import TextAreaDiv from .models import (Document, DocumentType, DocumentPage, DocumentPageTransformation, DocumentTypeFilename, DocumentVersion) +from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES, + DEFAULT_ZIP_FILENAME) from .widgets import document_html_widget -from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES, DEFAULT_ZIP_FILENAME) # Document page forms @@ -283,10 +284,10 @@ class DocumentTypeSelectForm(forms.Form): class PrintForm(forms.Form): - #page_size = forms.ChoiceField(choices=PAGE_SIZE_CHOICES, initial=DEFAULT_PAPER_SIZE, label=_(u'Page size'), required=False) - #custom_page_width = forms.CharField(label=_(u'Custom page width'), required=False) - #custom_page_height = forms.CharField(label=_(u'Custom page height'), required=False) - #page_orientation = forms.ChoiceField(choices=PAGE_ORIENTATION_CHOICES, initial=DEFAULT_PAGE_ORIENTATION, label=_(u'Page orientation'), required=True) + # page_size = forms.ChoiceField(choices=PAGE_SIZE_CHOICES, initial=DEFAULT_PAPER_SIZE, label=_(u'Page size'), required=False) + # custom_page_width = forms.CharField(label=_(u'Custom page width'), required=False) + # custom_page_height = forms.CharField(label=_(u'Custom page height'), required=False) + # page_orientation = forms.ChoiceField(choices=PAGE_ORIENTATION_CHOICES, initial=DEFAULT_PAGE_ORIENTATION, label=_(u'Page orientation'), required=True) page_range = forms.CharField(label=_(u'Page range'), required=False) @@ -315,16 +316,14 @@ class DocumentTypeFilenameForm_create(forms.ModelForm): model = DocumentTypeFilename fields = ('filename',) - + class DocumentDownloadForm(forms.Form): compressed = forms.BooleanField(label=_(u'Compress'), required=False, help_text=_(u'Download the document in the original format or in a compressed manner. This option is selectable only when downloading one document, for multiple documents, the bundle will always be downloads as a compressed file.')) zip_filename = forms.CharField(initial=DEFAULT_ZIP_FILENAME, label=_(u'Compressed filename'), required=False, help_text=_(u'The filename of the compressed file that will contain the documents to be downloaded, if the previous option is selected.')) - + def __init__(self, *args, **kwargs): self.document_versions = kwargs.pop('document_versions', None) super(DocumentDownloadForm, self).__init__(*args, **kwargs) if len(self.document_versions) > 1: self.fields['compressed'].initial = True - self.fields['compressed'].widget.attrs.update({'disabled': True}) - - + self.fields['compressed'].widget.attrs.update({'disabled': True}) diff --git a/apps/documents/links.py b/apps/documents/links.py index 2763717d59..d13b54e702 100644 --- a/apps/documents/links.py +++ b/apps/documents/links.py @@ -5,14 +5,13 @@ from django.utils.translation import ugettext_lazy as _ from history.permissions import PERMISSION_HISTORY_VIEW from .conf.settings import ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL -from .permissions import (PERMISSION_DOCUMENT_CREATE, - PERMISSION_DOCUMENT_PROPERTIES_EDIT, PERMISSION_DOCUMENT_VIEW, - PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD, - PERMISSION_DOCUMENT_TRANSFORM, PERMISSION_DOCUMENT_TOOLS, - PERMISSION_DOCUMENT_EDIT, PERMISSION_DOCUMENT_VERSION_REVERT, - PERMISSION_DOCUMENT_TYPE_EDIT, PERMISSION_DOCUMENT_TYPE_DELETE, - PERMISSION_DOCUMENT_TYPE_CREATE, PERMISSION_DOCUMENT_TYPE_VIEW, - PERMISSION_DOCUMENT_NEW_VERSION) +from .permissions import (PERMISSION_DOCUMENT_PROPERTIES_EDIT, + PERMISSION_DOCUMENT_VIEW, PERMISSION_DOCUMENT_DELETE, + PERMISSION_DOCUMENT_DOWNLOAD, PERMISSION_DOCUMENT_TRANSFORM, + PERMISSION_DOCUMENT_TOOLS, PERMISSION_DOCUMENT_EDIT, + PERMISSION_DOCUMENT_VERSION_REVERT, PERMISSION_DOCUMENT_TYPE_EDIT, + PERMISSION_DOCUMENT_TYPE_DELETE, PERMISSION_DOCUMENT_TYPE_CREATE, + PERMISSION_DOCUMENT_TYPE_VIEW) # Document page links expressions diff --git a/apps/documents/models.py b/apps/documents/models.py index 24d082fa72..b774cfc56d 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -370,7 +370,7 @@ class DocumentVersion(models.Model): if not self.pk: self.timestamp = datetime.datetime.now() - #Only do this for new documents + # Only do this for new documents transformations = kwargs.pop('transformations', None) super(DocumentVersion, self).save(*args, **kwargs) @@ -378,7 +378,7 @@ class DocumentVersion(models.Model): DocumentVersion._post_save_hooks[key](self) if new_document: - #Only do this for new documents + # Only do this for new documents self.update_checksum(save=False) self.update_mimetype(save=False) self.save() @@ -432,7 +432,7 @@ class DocumentVersion(models.Model): return detected_pages def apply_default_transformations(self, transformations): - #Only apply default transformations on new documents + # Only apply default transformations on new documents if reduce(lambda x, y: x + y, [page.documentpagetransformation_set.count() for page in self.pages.all()]) == 0: for transformation in transformations: for document_page in self.pages.all(): diff --git a/apps/documents/tests.py b/apps/documents/tests.py index f8c7164cdb..ef74adbd76 100644 --- a/apps/documents/tests.py +++ b/apps/documents/tests.py @@ -22,7 +22,7 @@ class DocumentTestCase(unittest.TestCase): description='description', ) self.document.save() - #return File(file(self.filepath, 'rb'), name=self.filename) + # return File(file(self.filepath, 'rb'), name=self.filename) file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf')) new_version = self.document.new_version(file=File(file_object, name='mayan_11_1.pdf')) @@ -71,7 +71,7 @@ class DocumentTestCase(unittest.TestCase): self.failUnlessEqual(self.document.latest_version.get_formated_version(), '3.0') - #GPGVerificationError + # GPGVerificationError self.failUnlessEqual(self.document.verify_signature(), None) file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.sig'), 'rb') diff --git a/apps/documents/utils.py b/apps/documents/utils.py index cae8b87a5f..ca5cb67db3 100644 --- a/apps/documents/utils.py +++ b/apps/documents/utils.py @@ -2,6 +2,7 @@ import os from common.conf.settings import TEMPORARY_DIRECTORY + def document_save_to_temp_dir(document, filename, buffer_size=1024 * 1024): temporary_path = os.path.join(TEMPORARY_DIRECTORY, filename) return document.save_to_file(temporary_path, buffer_size) diff --git a/apps/documents/views.py b/apps/documents/views.py index f6d54d5a4a..2dcd7ef134 100644 --- a/apps/documents/views.py +++ b/apps/documents/views.py @@ -36,13 +36,11 @@ from history.api import create_history from navigation.utils import resolve_to_name from permissions.models import Permission -from .events import (HISTORY_DOCUMENT_CREATED, - HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED) +from .events import HISTORY_DOCUMENT_EDITED from .conf.settings import (PREVIEW_SIZE, STORAGE_BACKEND, ZOOM_PERCENT_STEP, ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL, ROTATION_STEP, PRINT_SIZE, RECENT_COUNT) -from .forms import (DocumentTypeSelectForm, - DocumentForm_edit, DocumentPropertiesForm, +from .forms import (DocumentForm_edit, DocumentPropertiesForm, DocumentPreviewForm, DocumentPageForm, DocumentPageTransformationForm, DocumentContentForm, DocumentPageForm_edit, DocumentPageForm_text, PrintForm, @@ -51,13 +49,13 @@ from .forms import (DocumentTypeSelectForm, from .models import (Document, DocumentType, DocumentPage, DocumentPageTransformation, RecentDocument, DocumentTypeFilename, DocumentVersion) -from .permissions import (PERMISSION_DOCUMENT_CREATE, - PERMISSION_DOCUMENT_PROPERTIES_EDIT, PERMISSION_DOCUMENT_VIEW, - PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD, - PERMISSION_DOCUMENT_TRANSFORM, PERMISSION_DOCUMENT_TOOLS, - PERMISSION_DOCUMENT_EDIT, PERMISSION_DOCUMENT_VERSION_REVERT, - PERMISSION_DOCUMENT_TYPE_EDIT, PERMISSION_DOCUMENT_TYPE_DELETE, - PERMISSION_DOCUMENT_TYPE_CREATE, PERMISSION_DOCUMENT_TYPE_VIEW) +from .permissions import (PERMISSION_DOCUMENT_PROPERTIES_EDIT, + PERMISSION_DOCUMENT_VIEW, PERMISSION_DOCUMENT_DELETE, + PERMISSION_DOCUMENT_DOWNLOAD, PERMISSION_DOCUMENT_TRANSFORM, + PERMISSION_DOCUMENT_TOOLS, PERMISSION_DOCUMENT_EDIT, + PERMISSION_DOCUMENT_VERSION_REVERT, PERMISSION_DOCUMENT_TYPE_EDIT, + PERMISSION_DOCUMENT_TYPE_DELETE, PERMISSION_DOCUMENT_TYPE_CREATE, + PERMISSION_DOCUMENT_TYPE_VIEW) logger = logging.getLogger(__name__) @@ -96,7 +94,7 @@ def document_view(request, document_id, advanced=False): except PermissionDenied: AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document) - #document = get_object_or_404(Document.objects.select_related(), pk=document_id) + # document = get_object_or_404(Document.objects.select_related(), pk=document_id) # Triggers a 404 error on documents uploaded via local upload # TODO: investigate @@ -109,11 +107,11 @@ def document_view(request, document_id, advanced=False): {'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'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'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'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'}, @@ -191,7 +189,7 @@ def document_delete(request, document_id=None, document_id_list=None): messages.warning(request, warning) document.delete() - #create_history(HISTORY_DOCUMENT_DELETED, data={'user': request.user, 'document': document}) + # create_history(HISTORY_DOCUMENT_DELETED, data={'user': request.user, 'document': document}) messages.success(request, _(u'Document deleted successfully.')) except Exception, e: messages.error(request, _(u'Document: %(document)s delete error: %(error)s') % { @@ -818,18 +816,18 @@ def document_print(request, document_id): hard_copy_arguments['page_range'] = form.cleaned_data['page_range'] # Compute page width and height - #if form.cleaned_data['custom_page_width'] and form.cleaned_data['custom_page_height']: + # if form.cleaned_data['custom_page_width'] and form.cleaned_data['custom_page_height']: # page_width = form.cleaned_data['custom_page_width'] # page_height = form.cleaned_data['custom_page_height'] - #elif form.cleaned_data['page_size']: + # elif form.cleaned_data['page_size']: # page_width, page_height = dict(PAGE_SIZE_DIMENSIONS)[form.cleaned_data['page_size']] # Page orientation - #if form.cleaned_data['page_orientation'] == PAGE_ORIENTATION_LANDSCAPE: + # if form.cleaned_data['page_orientation'] == PAGE_ORIENTATION_LANDSCAPE: # page_width, page_height = page_height, page_width - #hard_copy_arguments['page_width'] = page_width - #hard_copy_arguments['page_height'] = page_height + # hard_copy_arguments['page_width'] = page_width + # hard_copy_arguments['page_height'] = page_height new_url = [reverse('document_hard_copy', args=[document_id])] if hard_copy_arguments: @@ -837,8 +835,8 @@ def document_print(request, document_id): new_window_url = u'?'.join(new_url) new_window_url_name = u'document_hard_copy' - #html_redirect = next - #messages.success(request, _(u'Preparing document hardcopy.')) + # html_redirect = next + # messages.success(request, _(u'Preparing document hardcopy.')) else: form = PrintForm() @@ -853,7 +851,7 @@ def document_print(request, document_id): def document_hard_copy(request, document_id): - #TODO: FIXME + # TODO: FIXME document = get_object_or_404(Document, pk=document_id) try: @@ -863,10 +861,10 @@ def document_hard_copy(request, document_id): RecentDocument.objects.add_document_for_user(request.user, document) - #arguments, warnings = calculate_converter_arguments(document, size=PRINT_SIZE, file_format=DEFAULT_FILE_FORMAT) + # arguments, warnings = calculate_converter_arguments(document, size=PRINT_SIZE, file_format=DEFAULT_FILE_FORMAT) # Pre-generate - #convert_document(document, **arguments) + # convert_document(document, **arguments) # Extract dimension values ignoring any unit page_width = request.GET.get('page_width', dict(PAGE_SIZE_DIMENSIONS)[DEFAULT_PAPER_SIZE][0]) @@ -948,7 +946,7 @@ def document_type_edit(request, document_type_id): return render_to_response('generic_form.html', { 'title': _(u'edit document type: %s') % document_type, 'form': form, - #'object': document_type, + # 'object': document_type, 'object_name': _(u'document type'), 'navigation_object_name': 'document_type', 'document_type': document_type,