Add from __future__ import unicode_literals, issue #37
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import tempfile
|
||||
|
||||
@@ -10,53 +10,45 @@ from common.utils import encapsulate, validate_path
|
||||
from dynamic_search.classes import SearchModel
|
||||
from events.permissions import PERMISSION_EVENTS_VIEW
|
||||
from main.api import register_maintenance_links
|
||||
from navigation.api import (register_links, register_model_list_columns)
|
||||
from navigation.api import register_links, register_model_list_columns
|
||||
from navigation.links import link_spacer
|
||||
from project_setup.api import register_setup
|
||||
from rest_api.classes import APIEndPoint
|
||||
from statistics.classes import StatisticNamespace
|
||||
|
||||
from documents import settings as document_settings
|
||||
from .links import (document_clear_image_cache,
|
||||
document_clear_transformations, document_content,
|
||||
document_delete,
|
||||
document_document_type_edit,
|
||||
document_events_view,
|
||||
document_multiple_document_type_edit, document_download,
|
||||
document_edit, document_list,
|
||||
document_list_recent, document_multiple_delete,
|
||||
document_multiple_clear_transformations,
|
||||
document_multiple_download,
|
||||
document_multiple_update_page_count, document_page_edit,
|
||||
document_page_navigation_first,
|
||||
document_page_navigation_last,
|
||||
document_page_navigation_next,
|
||||
document_page_navigation_previous,
|
||||
document_page_rotate_left, document_page_rotate_right,
|
||||
document_page_text, document_page_transformation_list,
|
||||
document_page_transformation_create,
|
||||
document_page_transformation_edit,
|
||||
document_page_transformation_delete, document_page_view,
|
||||
document_page_view_reset, document_page_zoom_in,
|
||||
document_page_zoom_out, document_preview, document_print,
|
||||
document_properties, document_type_create,
|
||||
document_type_delete, document_type_edit,
|
||||
document_type_filename_create,
|
||||
document_type_filename_delete, document_type_filename_edit,
|
||||
document_type_filename_list, document_type_list,
|
||||
document_type_setup, document_update_page_count,
|
||||
document_version_download, document_version_list,
|
||||
document_version_revert)
|
||||
from .models import (Document, DocumentPage, DocumentPageTransformation,
|
||||
DocumentType, DocumentTypeFilename, DocumentVersion)
|
||||
from .permissions import (PERMISSION_DOCUMENT_DELETE,
|
||||
PERMISSION_DOCUMENT_DOWNLOAD,
|
||||
PERMISSION_DOCUMENT_EDIT,
|
||||
PERMISSION_DOCUMENT_NEW_VERSION,
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT,
|
||||
PERMISSION_DOCUMENT_TRANSFORM,
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT,
|
||||
PERMISSION_DOCUMENT_VIEW)
|
||||
from .links import (
|
||||
document_clear_image_cache, document_clear_transformations,
|
||||
document_content, document_delete, document_document_type_edit,
|
||||
document_events_view, document_multiple_document_type_edit,
|
||||
document_download, document_edit, document_list, document_list_recent,
|
||||
document_multiple_delete, document_multiple_clear_transformations,
|
||||
document_multiple_download, document_multiple_update_page_count,
|
||||
document_page_edit, document_page_navigation_first,
|
||||
document_page_navigation_last, document_page_navigation_next,
|
||||
document_page_navigation_previous, document_page_rotate_left,
|
||||
document_page_rotate_right, document_page_text,
|
||||
document_page_transformation_list, document_page_transformation_create,
|
||||
document_page_transformation_edit, document_page_transformation_delete,
|
||||
document_page_view, document_page_view_reset, document_page_zoom_in,
|
||||
document_page_zoom_out, document_preview, document_print,
|
||||
document_properties, document_type_create, document_type_delete,
|
||||
document_type_edit, document_type_filename_create,
|
||||
document_type_filename_delete, document_type_filename_edit,
|
||||
document_type_filename_list, document_type_list, document_type_setup,
|
||||
document_update_page_count, document_version_download,
|
||||
document_version_list, document_version_revert
|
||||
)
|
||||
from .models import (
|
||||
Document, DocumentPage, DocumentPageTransformation, DocumentType,
|
||||
DocumentTypeFilename, DocumentVersion
|
||||
)
|
||||
from .permissions import (
|
||||
PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD,
|
||||
PERMISSION_DOCUMENT_EDIT, PERMISSION_DOCUMENT_NEW_VERSION,
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT, PERMISSION_DOCUMENT_TRANSFORM,
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT, PERMISSION_DOCUMENT_VIEW
|
||||
)
|
||||
from .settings import THUMBNAIL_SIZE
|
||||
from .statistics import DocumentStatistics, DocumentUsageStatistics
|
||||
from .widgets import document_thumbnail
|
||||
@@ -98,14 +90,14 @@ register_links('documents:document_page_transformation_list', [document_page_tra
|
||||
register_links('documents:document_page_transformation_create', [document_page_transformation_create], menu_name='sidebar')
|
||||
register_links(['documents:document_page_transformation_edit', 'documents:document_page_transformation_delete'], [document_page_transformation_create], menu_name='sidebar')
|
||||
|
||||
register_maintenance_links([document_clear_image_cache], namespace='documents', title=_(u'Documents'))
|
||||
register_maintenance_links([document_clear_image_cache], namespace='documents', title=_('Documents'))
|
||||
register_model_list_columns(Document, [
|
||||
{
|
||||
'name': _(u'Thumbnail'), 'attribute':
|
||||
'name': _('Thumbnail'), 'attribute':
|
||||
encapsulate(lambda x: document_thumbnail(x, gallery_name='documents:document_list', title=getattr(x, 'filename', None), size=THUMBNAIL_SIZE))
|
||||
},
|
||||
{
|
||||
'name': _(u'Type'), 'attribute': 'document_type'
|
||||
'name': _('Type'), 'attribute': 'document_type'
|
||||
}
|
||||
])
|
||||
|
||||
@@ -114,32 +106,30 @@ if (not validate_path(document_settings.CACHE_PATH)) or (not document_settings.C
|
||||
|
||||
register_setup(document_type_setup)
|
||||
|
||||
class_permissions(Document, [PERMISSION_DOCUMENT_DELETE,
|
||||
PERMISSION_DOCUMENT_DOWNLOAD,
|
||||
PERMISSION_DOCUMENT_EDIT,
|
||||
PERMISSION_DOCUMENT_NEW_VERSION,
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT,
|
||||
PERMISSION_DOCUMENT_TRANSFORM,
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT,
|
||||
PERMISSION_DOCUMENT_VIEW,
|
||||
PERMISSION_EVENTS_VIEW])
|
||||
class_permissions(Document, [
|
||||
PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD,
|
||||
PERMISSION_DOCUMENT_EDIT, PERMISSION_DOCUMENT_NEW_VERSION,
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT, PERMISSION_DOCUMENT_TRANSFORM,
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT, PERMISSION_DOCUMENT_VIEW,
|
||||
PERMISSION_EVENTS_VIEW
|
||||
])
|
||||
|
||||
document_search = SearchModel('documents', 'Document', permission=PERMISSION_DOCUMENT_VIEW, serializer_string='documents.serializers.DocumentSerializer')
|
||||
|
||||
# TODO: move these to their respective apps
|
||||
# Moving these to other apps cause an ImportError; circular import?
|
||||
document_search.add_model_field('document_type__name', label=_(u'Document type'))
|
||||
document_search.add_model_field('versions__mimetype', label=_(u'MIME type'))
|
||||
document_search.add_model_field('label', label=_(u'Label'))
|
||||
document_search.add_model_field('metadata__metadata_type__name', label=_(u'Metadata type'))
|
||||
document_search.add_model_field('metadata__value', label=_(u'Metadata value'))
|
||||
document_search.add_model_field('versions__pages__content', label=_(u'Content'))
|
||||
document_search.add_model_field('description', label=_(u'Description'))
|
||||
document_search.add_model_field('tags__label', label=_(u'Tags'))
|
||||
document_search.add_model_field('document_type__name', label=_('Document type'))
|
||||
document_search.add_model_field('versions__mimetype', label=_('MIME type'))
|
||||
document_search.add_model_field('label', label=_('Label'))
|
||||
document_search.add_model_field('metadata__metadata_type__name', label=_('Metadata type'))
|
||||
document_search.add_model_field('metadata__value', label=_('Metadata value'))
|
||||
document_search.add_model_field('versions__pages__content', label=_('Content'))
|
||||
document_search.add_model_field('description', label=_('Description'))
|
||||
document_search.add_model_field('tags__label', label=_('Tags'))
|
||||
|
||||
namespace = StatisticNamespace(name='documents', label=_(u'Documents'))
|
||||
namespace.add_statistic(DocumentStatistics(name='document_stats', label=_(u'Document tendencies')))
|
||||
namespace.add_statistic(DocumentUsageStatistics(name='document_usage', label=_(u'Document usage')))
|
||||
namespace = StatisticNamespace(name='documents', label=_('Documents'))
|
||||
namespace.add_statistic(DocumentStatistics(name='document_stats', label=_('Document tendencies')))
|
||||
namespace.add_statistic(DocumentUsageStatistics(name='document_usage', label=_('Document usage')))
|
||||
|
||||
APIEndPoint('documents')
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
# TODO: Improve API methods docstrings
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
class NewDocumentVersionNotAllowed(Exception):
|
||||
"""
|
||||
Uploading new versions for this document is not allowed
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
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.utils.translation import ugettext_lazy as _, ugettext
|
||||
|
||||
from common.forms import DetailForm
|
||||
from common.widgets import TextAreaDiv
|
||||
|
||||
from .models import (Document, DocumentType, DocumentPage,
|
||||
DocumentPageTransformation, DocumentTypeFilename)
|
||||
from .models import (
|
||||
Document, DocumentType, DocumentPage, DocumentPageTransformation,
|
||||
DocumentTypeFilename
|
||||
)
|
||||
from .literals import DEFAULT_ZIP_FILENAME
|
||||
from .widgets import DocumentPagesCarouselWidget, DocumentPageImageWidget
|
||||
|
||||
@@ -42,7 +43,7 @@ class DocumentPageForm(DetailForm):
|
||||
})
|
||||
|
||||
page_image = forms.CharField(
|
||||
label=_(u'Page image'), widget=DocumentPageImageWidget()
|
||||
label=_('Page image'), widget=DocumentPageImageWidget()
|
||||
)
|
||||
|
||||
|
||||
@@ -52,7 +53,7 @@ class DocumentPageForm_text(DetailForm):
|
||||
fields = ('page_label', 'content')
|
||||
|
||||
content = forms.CharField(
|
||||
label=_(u'Contents'),
|
||||
label=_('Contents'),
|
||||
widget=forms.widgets.Textarea(attrs={
|
||||
'rows': 18, 'cols': 80, 'readonly': 'readonly'
|
||||
}))
|
||||
@@ -85,9 +86,9 @@ class DocumentPreviewForm(forms.Form):
|
||||
super(DocumentPreviewForm, self).__init__(*args, **kwargs)
|
||||
self.fields['preview'].initial = document
|
||||
try:
|
||||
self.fields['preview'].label = _(u'Document pages (%d)') % document.page_count
|
||||
self.fields['preview'].label = _('Document pages (%d)') % document.page_count
|
||||
except AttributeError:
|
||||
self.fields['preview'].label = _(u'Document pages (%d)') % 0
|
||||
self.fields['preview'].label = _('Document pages (%d)') % 0
|
||||
|
||||
preview = forms.CharField(widget=DocumentPagesCarouselWidget())
|
||||
|
||||
@@ -114,7 +115,7 @@ class DocumentForm(forms.ModelForm):
|
||||
self.fields['document_type_available_filenames'] = forms.ModelChoiceField(
|
||||
queryset=filenames_qs,
|
||||
required=False,
|
||||
label=_(u'Quick document rename'))
|
||||
label=_('Quick document rename'))
|
||||
|
||||
|
||||
class DocumentPropertiesForm(DetailForm):
|
||||
@@ -135,7 +136,7 @@ class DocumentContentForm(forms.Form):
|
||||
self.document = kwargs.pop('document', None)
|
||||
super(DocumentContentForm, self).__init__(*args, **kwargs)
|
||||
content = []
|
||||
self.fields['contents'].initial = u''
|
||||
self.fields['contents'].initial = ''
|
||||
try:
|
||||
document_pages = self.document.pages.all()
|
||||
except AttributeError:
|
||||
@@ -144,12 +145,12 @@ class DocumentContentForm(forms.Form):
|
||||
for page in document_pages:
|
||||
if page.content:
|
||||
content.append(conditional_escape(force_unicode(page.content)))
|
||||
content.append(u'\n\n\n<hr/><div class="document-page-content-divider">- %s -</div><hr/>\n\n\n' % (ugettext(u'Page %(page_number)d') % {'page_number': page.page_number}))
|
||||
content.append('\n\n\n<hr/><div class="document-page-content-divider">- %s -</div><hr/>\n\n\n' % (ugettext('Page %(page_number)d') % {'page_number': page.page_number}))
|
||||
|
||||
self.fields['contents'].initial = mark_safe(u''.join(content))
|
||||
self.fields['contents'].initial = mark_safe(''.join(content))
|
||||
|
||||
contents = forms.CharField(
|
||||
label=_(u'Contents'),
|
||||
label=_('Contents'),
|
||||
widget=TextAreaDiv()
|
||||
)
|
||||
|
||||
@@ -159,11 +160,11 @@ class DocumentTypeSelectForm(forms.Form):
|
||||
Form to select the document type of a document to be created, used
|
||||
as form #1 in the document creation wizard
|
||||
"""
|
||||
document_type = forms.ModelChoiceField(queryset=DocumentType.objects.all(), label=(u'Document type'))
|
||||
document_type = forms.ModelChoiceField(queryset=DocumentType.objects.all(), label=('Document type'))
|
||||
|
||||
|
||||
class PrintForm(forms.Form):
|
||||
page_range = forms.CharField(label=_(u'Page range'), required=False)
|
||||
page_range = forms.CharField(label=_('Page range'), required=False)
|
||||
|
||||
|
||||
class DocumentTypeForm(forms.ModelForm):
|
||||
@@ -193,8 +194,8 @@ class DocumentTypeFilenameForm_create(forms.ModelForm):
|
||||
|
||||
|
||||
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.'))
|
||||
compressed = forms.BooleanField(label=_('Compress'), required=False, help_text=_('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=_('Compressed filename'), required=False, help_text=_('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)
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from events.permissions import PERMISSION_EVENTS_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)
|
||||
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
|
||||
)
|
||||
from .settings import ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL
|
||||
|
||||
# Document page links expressions
|
||||
@@ -36,60 +37,60 @@ def is_current_version(context):
|
||||
return context['object'].document.latest_version.timestamp == context['object'].timestamp
|
||||
|
||||
|
||||
document_list = {'text': _(u'All documents'), 'view': 'documents:document_list', 'famfam': 'page'}
|
||||
document_list_recent = {'text': _(u'Recent documents'), 'view': 'documents:document_list_recent', 'famfam': 'page'}
|
||||
document_preview = {'text': _(u'Preview'), 'view': 'documents:document_preview', 'args': 'object.id', 'famfam': 'page', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_content = {'text': _(u'Content'), 'view': 'documents:document_content', 'args': 'object.id', 'famfam': 'page_white_text', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_properties = {'text': _(u'Properties'), 'view': 'documents:document_properties', 'args': 'object.id', 'famfam': 'page_gear', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_delete = {'text': _(u'Delete'), 'view': 'documents:document_delete', 'args': 'object.id', 'famfam': 'page_delete', 'permissions': [PERMISSION_DOCUMENT_DELETE]}
|
||||
document_multiple_delete = {'text': _(u'Delete'), 'view': 'documents:document_multiple_delete', 'famfam': 'page_delete', 'permissions': [PERMISSION_DOCUMENT_DELETE]}
|
||||
document_edit = {'text': _(u'Edit properties'), 'view': 'documents:document_edit', 'args': 'object.id', 'famfam': 'page_edit', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}
|
||||
document_document_type_edit = {'text': _(u'Change type'), 'view': 'documents:document_document_type_edit', 'args': 'object.id', 'famfam': 'layout', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}
|
||||
document_multiple_document_type_edit = {'text': _(u'Change type'), 'view': 'documents:document_multiple_document_type_edit', 'famfam': 'layout', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}
|
||||
document_download = {'text': _(u'Download'), 'view': 'documents:document_download', 'args': 'object.id', 'famfam': 'page_save', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}
|
||||
document_multiple_download = {'text': _(u'Download'), 'view': 'documents:document_multiple_download', 'famfam': 'page_save', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}
|
||||
document_version_download = {'text': _(u'Download'), 'view': 'documents:document_version_download', 'args': 'object.pk', 'famfam': 'page_save', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}
|
||||
document_update_page_count = {'text': _(u'Reset page count'), 'view': 'documents:document_update_page_count', 'args': 'object.pk', 'famfam': 'page_white_csharp', 'permissions': [PERMISSION_DOCUMENT_TOOLS]}
|
||||
document_multiple_update_page_count = {'text': _(u'Reset page count'), 'view': 'documents:document_multiple_update_page_count', 'famfam': 'page_white_csharp', 'permissions': [PERMISSION_DOCUMENT_TOOLS]}
|
||||
document_clear_transformations = {'text': _(u'Clear transformations'), 'view': 'documents:document_clear_transformations', 'args': 'object.id', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_multiple_clear_transformations = {'text': _(u'Clear transformations'), 'view': 'documents:document_multiple_clear_transformations', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_print = {'text': _(u'Print'), 'view': 'documents:document_print', 'args': 'object.id', 'famfam': 'printer', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_events_view = {'text': _(u'Events'), 'view': 'events:events_for_object', 'args': ['"documents"', '"document"', 'object.id'], 'famfam': 'book_go', 'permissions': [PERMISSION_EVENTS_VIEW]}
|
||||
document_list = {'text': _('All documents'), 'view': 'documents:document_list', 'famfam': 'page'}
|
||||
document_list_recent = {'text': _('Recent documents'), 'view': 'documents:document_list_recent', 'famfam': 'page'}
|
||||
document_preview = {'text': _('Preview'), 'view': 'documents:document_preview', 'args': 'object.id', 'famfam': 'page', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_content = {'text': _('Content'), 'view': 'documents:document_content', 'args': 'object.id', 'famfam': 'page_white_text', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_properties = {'text': _('Properties'), 'view': 'documents:document_properties', 'args': 'object.id', 'famfam': 'page_gear', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_delete = {'text': _('Delete'), 'view': 'documents:document_delete', 'args': 'object.id', 'famfam': 'page_delete', 'permissions': [PERMISSION_DOCUMENT_DELETE]}
|
||||
document_multiple_delete = {'text': _('Delete'), 'view': 'documents:document_multiple_delete', 'famfam': 'page_delete', 'permissions': [PERMISSION_DOCUMENT_DELETE]}
|
||||
document_edit = {'text': _('Edit properties'), 'view': 'documents:document_edit', 'args': 'object.id', 'famfam': 'page_edit', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}
|
||||
document_document_type_edit = {'text': _('Change type'), 'view': 'documents:document_document_type_edit', 'args': 'object.id', 'famfam': 'layout', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}
|
||||
document_multiple_document_type_edit = {'text': _('Change type'), 'view': 'documents:document_multiple_document_type_edit', 'famfam': 'layout', 'permissions': [PERMISSION_DOCUMENT_PROPERTIES_EDIT]}
|
||||
document_download = {'text': _('Download'), 'view': 'documents:document_download', 'args': 'object.id', 'famfam': 'page_save', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}
|
||||
document_multiple_download = {'text': _('Download'), 'view': 'documents:document_multiple_download', 'famfam': 'page_save', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}
|
||||
document_version_download = {'text': _('Download'), 'view': 'documents:document_version_download', 'args': 'object.pk', 'famfam': 'page_save', 'permissions': [PERMISSION_DOCUMENT_DOWNLOAD]}
|
||||
document_update_page_count = {'text': _('Reset page count'), 'view': 'documents:document_update_page_count', 'args': 'object.pk', 'famfam': 'page_white_csharp', 'permissions': [PERMISSION_DOCUMENT_TOOLS]}
|
||||
document_multiple_update_page_count = {'text': _('Reset page count'), 'view': 'documents:document_multiple_update_page_count', 'famfam': 'page_white_csharp', 'permissions': [PERMISSION_DOCUMENT_TOOLS]}
|
||||
document_clear_transformations = {'text': _('Clear transformations'), 'view': 'documents:document_clear_transformations', 'args': 'object.id', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_multiple_clear_transformations = {'text': _('Clear transformations'), 'view': 'documents:document_multiple_clear_transformations', 'famfam': 'page_paintbrush', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_print = {'text': _('Print'), 'view': 'documents:document_print', 'args': 'object.id', 'famfam': 'printer', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_events_view = {'text': _('Events'), 'view': 'events:events_for_object', 'args': ['"documents"', '"document"', 'object.id'], 'famfam': 'book_go', 'permissions': [PERMISSION_EVENTS_VIEW]}
|
||||
|
||||
# Tools
|
||||
document_clear_image_cache = {'text': _(u'Clear the document image cache'), 'view': 'documents:document_clear_image_cache', 'famfam': 'camera_delete', 'permissions': [PERMISSION_DOCUMENT_TOOLS], 'description': _(u'Clear the graphics representations used to speed up the documents\' display and interactive transformations results.')}
|
||||
document_clear_image_cache = {'text': _('Clear the document image cache'), 'view': 'documents:document_clear_image_cache', 'famfam': 'camera_delete', 'permissions': [PERMISSION_DOCUMENT_TOOLS], 'description': _('Clear the graphics representations used to speed up the documents\' display and interactive transformations results.')}
|
||||
|
||||
# Document pages
|
||||
document_page_transformation_list = {'text': _(u'Page transformations'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_list', 'args': 'page.pk', 'famfam': 'pencil_go', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_create = {'text': _(u'Create new transformation'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_create', 'args': 'page.pk', 'famfam': 'pencil_add', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_edit = {'text': _(u'Edit'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_edit', 'args': 'transformation.pk', 'famfam': 'pencil_go', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_delete = {'text': _(u'Delete'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_delete', 'args': 'transformation.pk', 'famfam': 'pencil_delete', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_list = {'text': _('Page transformations'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_list', 'args': 'page.pk', 'famfam': 'pencil_go', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_create = {'text': _('Create new transformation'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_create', 'args': 'page.pk', 'famfam': 'pencil_add', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_edit = {'text': _('Edit'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_edit', 'args': 'transformation.pk', 'famfam': 'pencil_go', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
document_page_transformation_delete = {'text': _('Delete'), 'class': 'no-parent-history', 'view': 'documents:document_page_transformation_delete', 'args': 'transformation.pk', 'famfam': 'pencil_delete', 'permissions': [PERMISSION_DOCUMENT_TRANSFORM]}
|
||||
|
||||
document_page_view = {'text': _(u'Page image'), 'class': 'no-parent-history', 'view': 'documents:document_page_view', 'args': 'page.pk', 'famfam': 'page_white_picture', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_text = {'text': _(u'Page text'), 'class': 'no-parent-history', 'view': 'documents:document_page_text', 'args': 'page.pk', 'famfam': 'page_white_text', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_edit = {'text': _(u'Edit page text'), 'class': 'no-parent-history', 'view': 'documents:document_page_edit', 'args': 'page.pk', 'famfam': 'page_white_edit', 'permissions': [PERMISSION_DOCUMENT_EDIT]}
|
||||
document_page_navigation_next = {'text': _(u'Next page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_next', 'args': 'page.pk', 'famfam': 'resultset_next', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_last_page, 'keep_query': True}
|
||||
document_page_navigation_previous = {'text': _(u'Previous page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_previous', 'args': 'page.pk', 'famfam': 'resultset_previous', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_first_page, 'keep_query': True}
|
||||
document_page_navigation_first = {'text': _(u'First page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_first', 'args': 'page.pk', 'famfam': 'resultset_first', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_first_page, 'keep_query': True}
|
||||
document_page_navigation_last = {'text': _(u'Last page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_last', 'args': 'page.pk', 'famfam': 'resultset_last', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_last_page, 'keep_query': True}
|
||||
document_page_zoom_in = {'text': _(u'Zoom in'), 'class': 'no-parent-history', 'view': 'documents:document_page_zoom_in', 'args': 'page.pk', 'famfam': 'zoom_in', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_max_zoom}
|
||||
document_page_zoom_out = {'text': _(u'Zoom out'), 'class': 'no-parent-history', 'view': 'documents:document_page_zoom_out', 'args': 'page.pk', 'famfam': 'zoom_out', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_min_zoom}
|
||||
document_page_rotate_right = {'text': _(u'Rotate right'), 'class': 'no-parent-history', 'view': 'documents:document_page_rotate_right', 'args': 'page.pk', 'famfam': 'arrow_turn_right', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_rotate_left = {'text': _(u'Rotate left'), 'class': 'no-parent-history', 'view': 'documents:document_page_rotate_left', 'args': 'page.pk', 'famfam': 'arrow_turn_left', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_view_reset = {'text': _(u'Reset view'), 'class': 'no-parent-history', 'view': 'documents:document_page_view_reset', 'args': 'page.pk', 'famfam': 'page_white', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_view = {'text': _('Page image'), 'class': 'no-parent-history', 'view': 'documents:document_page_view', 'args': 'page.pk', 'famfam': 'page_white_picture', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_text = {'text': _('Page text'), 'class': 'no-parent-history', 'view': 'documents:document_page_text', 'args': 'page.pk', 'famfam': 'page_white_text', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_edit = {'text': _('Edit page text'), 'class': 'no-parent-history', 'view': 'documents:document_page_edit', 'args': 'page.pk', 'famfam': 'page_white_edit', 'permissions': [PERMISSION_DOCUMENT_EDIT]}
|
||||
document_page_navigation_next = {'text': _('Next page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_next', 'args': 'page.pk', 'famfam': 'resultset_next', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_last_page, 'keep_query': True}
|
||||
document_page_navigation_previous = {'text': _('Previous page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_previous', 'args': 'page.pk', 'famfam': 'resultset_previous', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_first_page, 'keep_query': True}
|
||||
document_page_navigation_first = {'text': _('First page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_first', 'args': 'page.pk', 'famfam': 'resultset_first', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_first_page, 'keep_query': True}
|
||||
document_page_navigation_last = {'text': _('Last page'), 'class': 'no-parent-history', 'view': 'documents:document_page_navigation_last', 'args': 'page.pk', 'famfam': 'resultset_last', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_last_page, 'keep_query': True}
|
||||
document_page_zoom_in = {'text': _('Zoom in'), 'class': 'no-parent-history', 'view': 'documents:document_page_zoom_in', 'args': 'page.pk', 'famfam': 'zoom_in', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_max_zoom}
|
||||
document_page_zoom_out = {'text': _('Zoom out'), 'class': 'no-parent-history', 'view': 'documents:document_page_zoom_out', 'args': 'page.pk', 'famfam': 'zoom_out', 'permissions': [PERMISSION_DOCUMENT_VIEW], 'conditional_disable': is_min_zoom}
|
||||
document_page_rotate_right = {'text': _('Rotate right'), 'class': 'no-parent-history', 'view': 'documents:document_page_rotate_right', 'args': 'page.pk', 'famfam': 'arrow_turn_right', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_rotate_left = {'text': _('Rotate left'), 'class': 'no-parent-history', 'view': 'documents:document_page_rotate_left', 'args': 'page.pk', 'famfam': 'arrow_turn_left', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_page_view_reset = {'text': _('Reset view'), 'class': 'no-parent-history', 'view': 'documents:document_page_view_reset', 'args': 'page.pk', 'famfam': 'page_white', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
|
||||
# Document versions
|
||||
document_version_list = {'text': _(u'Versions'), 'view': 'documents:document_version_list', 'args': 'object.pk', 'famfam': 'page_world', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_version_revert = {'text': _(u'Revert'), 'view': 'documents:document_version_revert', 'args': 'object.pk', 'famfam': 'page_refresh', 'permissions': [PERMISSION_DOCUMENT_VERSION_REVERT], 'conditional_disable': is_current_version}
|
||||
document_version_list = {'text': _('Versions'), 'view': 'documents:document_version_list', 'args': 'object.pk', 'famfam': 'page_world', 'permissions': [PERMISSION_DOCUMENT_VIEW]}
|
||||
document_version_revert = {'text': _('Revert'), 'view': 'documents:document_version_revert', 'args': 'object.pk', 'famfam': 'page_refresh', 'permissions': [PERMISSION_DOCUMENT_VERSION_REVERT], 'conditional_disable': is_current_version}
|
||||
|
||||
# Document type related links
|
||||
document_type_list = {'text': _(u'Document types'), 'view': 'documents:document_type_list', 'famfam': 'layout', 'permissions': [PERMISSION_DOCUMENT_TYPE_VIEW]}
|
||||
document_type_setup = {'text': _(u'Document types'), 'view': 'documents:document_type_list', 'famfam': 'layout', 'icon': 'layout.png', 'permissions': [PERMISSION_DOCUMENT_TYPE_VIEW]}
|
||||
document_type_edit = {'text': _(u'Edit'), 'view': 'documents:document_type_edit', 'args': 'document_type.id', 'famfam': 'layout_edit', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_delete = {'text': _(u'Delete'), 'view': 'documents:document_type_delete', 'args': 'document_type.id', 'famfam': 'layout_delete', 'permissions': [PERMISSION_DOCUMENT_TYPE_DELETE]}
|
||||
document_type_create = {'text': _(u'Create document type'), 'view': 'documents:document_type_create', 'famfam': 'layout_add', 'permissions': [PERMISSION_DOCUMENT_TYPE_CREATE]}
|
||||
document_type_list = {'text': _('Document types'), 'view': 'documents:document_type_list', 'famfam': 'layout', 'permissions': [PERMISSION_DOCUMENT_TYPE_VIEW]}
|
||||
document_type_setup = {'text': _('Document types'), 'view': 'documents:document_type_list', 'famfam': 'layout', 'icon': 'layout.png', 'permissions': [PERMISSION_DOCUMENT_TYPE_VIEW]}
|
||||
document_type_edit = {'text': _('Edit'), 'view': 'documents:document_type_edit', 'args': 'document_type.id', 'famfam': 'layout_edit', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_delete = {'text': _('Delete'), 'view': 'documents:document_type_delete', 'args': 'document_type.id', 'famfam': 'layout_delete', 'permissions': [PERMISSION_DOCUMENT_TYPE_DELETE]}
|
||||
document_type_create = {'text': _('Create document type'), 'view': 'documents:document_type_create', 'famfam': 'layout_add', 'permissions': [PERMISSION_DOCUMENT_TYPE_CREATE]}
|
||||
|
||||
document_type_filename_list = {'text': _(u'Filenames'), 'view': 'documents:document_type_filename_list', 'args': 'document_type.id', 'famfam': 'database', 'permissions': [PERMISSION_DOCUMENT_TYPE_VIEW]}
|
||||
document_type_filename_create = {'text': _(u'Add filename to document type'), 'view': 'documents:document_type_filename_create', 'args': 'document_type.id', 'famfam': 'database_add', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_filename_edit = {'text': _(u'Edit'), 'view': 'documents:document_type_filename_edit', 'args': 'filename.id', 'famfam': 'database_edit', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_filename_delete = {'text': _(u'Delete'), 'view': 'documents:document_type_filename_delete', 'args': 'filename.id', 'famfam': 'database_delete', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_filename_list = {'text': _('Filenames'), 'view': 'documents:document_type_filename_list', 'args': 'document_type.id', 'famfam': 'database', 'permissions': [PERMISSION_DOCUMENT_TYPE_VIEW]}
|
||||
document_type_filename_create = {'text': _('Add filename to document type'), 'view': 'documents:document_type_filename_create', 'args': 'document_type.id', 'famfam': 'database_add', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_filename_edit = {'text': _('Edit'), 'view': 'documents:document_type_filename_edit', 'args': 'filename.id', 'famfam': 'database_edit', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
document_type_filename_delete = {'text': _('Delete'), 'view': 'documents:document_type_filename_delete', 'args': 'filename.id', 'famfam': 'database_delete', 'permissions': [PERMISSION_DOCUMENT_TYPE_EDIT]}
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
PICTURE_ERROR_SMALL = u'picture_error.png'
|
||||
PICTURE_ERROR_MEDIUM = u'1297211435_error.png'
|
||||
PICTURE_UNKNOWN_SMALL = u'1299549572_unknown2.png'
|
||||
PICTURE_UNKNOWN_MEDIUM = u'1299549805_unknown.png'
|
||||
|
||||
DEFAULT_ZIP_FILENAME = u'document_bundle.zip'
|
||||
from __future__ import unicode_literals
|
||||
|
||||
DEFAULT_ZIP_FILENAME = 'document_bundle.zip'
|
||||
DOCUMENT_IMAGE_TASK_TIMEOUT = 20
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ast import literal_eval
|
||||
import logging
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from ast import literal_eval
|
||||
import base64
|
||||
@@ -49,10 +49,10 @@ class DocumentType(models.Model):
|
||||
Define document types or classes to which a specific set of
|
||||
properties can be attached
|
||||
"""
|
||||
name = models.CharField(max_length=32, verbose_name=_(u'Name'), unique=True)
|
||||
name = models.CharField(max_length=32, verbose_name=_('Name'), unique=True)
|
||||
|
||||
# TODO: find a way to move this to the ocr app
|
||||
ocr = models.BooleanField(default=True, verbose_name=_(u'Automatically queue newly created documents for OCR.'))
|
||||
ocr = models.BooleanField(default=True, verbose_name=_('Automatically queue newly created documents for OCR.'))
|
||||
|
||||
objects = DocumentTypeManager()
|
||||
|
||||
@@ -63,8 +63,8 @@ class DocumentType(models.Model):
|
||||
return (self.name,)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'Document type')
|
||||
verbose_name_plural = _(u'Documents types')
|
||||
verbose_name = _('Document type')
|
||||
verbose_name_plural = _('Documents types')
|
||||
ordering = ['name']
|
||||
|
||||
|
||||
@@ -74,17 +74,17 @@ class Document(models.Model):
|
||||
"""
|
||||
|
||||
uuid = models.CharField(default=lambda: UUID_FUNCTION(), max_length=48, editable=False)
|
||||
document_type = models.ForeignKey(DocumentType, verbose_name=_(u'Document type'), related_name='documents')
|
||||
document_type = models.ForeignKey(DocumentType, verbose_name=_('Document type'), related_name='documents')
|
||||
label = models.CharField(max_length=255, default=_('Uninitialized document'), db_index=True, help_text=_('The name of the document'), verbose_name=_('Label'))
|
||||
description = models.TextField(blank=True, null=True, verbose_name=_(u'Description'))
|
||||
date_added = models.DateTimeField(verbose_name=_(u'Added'), auto_now_add=True)
|
||||
description = models.TextField(blank=True, null=True, verbose_name=_('Description'))
|
||||
date_added = models.DateTimeField(verbose_name=_('Added'), auto_now_add=True)
|
||||
language = models.CharField(choices=LANGUAGE_CHOICES, default=LANGUAGE, max_length=8, verbose_name=_('Language'))
|
||||
|
||||
objects = DocumentManager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'Document')
|
||||
verbose_name_plural = _(u'Documents')
|
||||
verbose_name = _('Document')
|
||||
verbose_name_plural = _('Documents')
|
||||
ordering = ['-date_added']
|
||||
|
||||
def set_document_type(self, document_type, force=False):
|
||||
@@ -127,7 +127,7 @@ class Document(models.Model):
|
||||
document_version = DocumentVersion.objects.get(pk=version)
|
||||
document_page = document_version.pages.get(page_number=page)
|
||||
transformations, warnings = document_page.get_transformation_list()
|
||||
hash_value = HASH_FUNCTION(u''.join([document_version.checksum, unicode(page), unicode(transformations)]))
|
||||
hash_value = HASH_FUNCTION(''.join([document_version.checksum, unicode(page), unicode(transformations)]))
|
||||
return os.path.join(CACHE_PATH, hash_value), transformations
|
||||
|
||||
def get_image_cache_name(self, page, version):
|
||||
@@ -165,7 +165,7 @@ class Document(models.Model):
|
||||
image = open(file_path, 'r')
|
||||
base64_data = base64.b64encode(image.read())
|
||||
image.close()
|
||||
return u'data:%s;base64,%s' % (mimetype, base64_data)
|
||||
return 'data:%s;base64,%s' % (mimetype, base64_data)
|
||||
else:
|
||||
return file_path
|
||||
|
||||
@@ -285,23 +285,23 @@ class DocumentVersion(models.Model):
|
||||
def register_post_save_hook(cls, order, func):
|
||||
cls._post_save_hooks[order] = func
|
||||
|
||||
document = models.ForeignKey(Document, verbose_name=_(u'Document'), related_name='versions')
|
||||
timestamp = models.DateTimeField(verbose_name=_(u'Timestamp'), auto_now_add=True)
|
||||
comment = models.TextField(blank=True, verbose_name=_(u'Comment'))
|
||||
document = models.ForeignKey(Document, verbose_name=_('Document'), related_name='versions')
|
||||
timestamp = models.DateTimeField(verbose_name=_('Timestamp'), auto_now_add=True)
|
||||
comment = models.TextField(blank=True, verbose_name=_('Comment'))
|
||||
|
||||
# File related fields
|
||||
file = models.FileField(upload_to=lambda instance, filename: UUID_FUNCTION(), storage=storage_backend, verbose_name=_(u'File'))
|
||||
file = models.FileField(upload_to=lambda instance, filename: UUID_FUNCTION(), storage=storage_backend, verbose_name=_('File'))
|
||||
mimetype = models.CharField(max_length=255, null=True, blank=True, editable=False)
|
||||
encoding = models.CharField(max_length=64, null=True, blank=True, editable=False)
|
||||
|
||||
checksum = models.TextField(blank=True, null=True, verbose_name=_(u'Checksum'), editable=False)
|
||||
checksum = models.TextField(blank=True, null=True, verbose_name=_('Checksum'), editable=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'Document version')
|
||||
verbose_name_plural = _(u'Document version')
|
||||
verbose_name = _('Document version')
|
||||
verbose_name_plural = _('Document version')
|
||||
|
||||
def __unicode__(self):
|
||||
return u'{0} - {1}'.format(self.document, self.timestamp)
|
||||
return '{0} - {1}'.format(self.document, self.timestamp)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
@@ -353,7 +353,7 @@ class DocumentVersion(models.Model):
|
||||
# If converter backend doesn't understand the format,
|
||||
# use 1 as the total page count
|
||||
detected_pages = 1
|
||||
self.description = ugettext(u'This document\'s file format is not known, the page count has therefore defaulted to 1.')
|
||||
self.description = ugettext('This document\'s file format is not known, the page count has therefore defaulted to 1.')
|
||||
self.save()
|
||||
try:
|
||||
os.remove(filepath)
|
||||
@@ -405,8 +405,8 @@ class DocumentVersion(models.Model):
|
||||
try:
|
||||
self.mimetype, self.encoding = get_mimetype(self.open(), self.document.label)
|
||||
except:
|
||||
self.mimetype = u''
|
||||
self.encoding = u''
|
||||
self.mimetype = ''
|
||||
self.encoding = ''
|
||||
finally:
|
||||
if save:
|
||||
self.save()
|
||||
@@ -471,9 +471,9 @@ class DocumentTypeFilename(models.Model):
|
||||
List of filenames available to a specific document type for the
|
||||
quick rename functionality
|
||||
"""
|
||||
document_type = models.ForeignKey(DocumentType, related_name='filenames', verbose_name=_(u'Document type'))
|
||||
filename = models.CharField(max_length=128, verbose_name=_(u'Filename'), db_index=True)
|
||||
enabled = models.BooleanField(default=True, verbose_name=_(u'Enabled'))
|
||||
document_type = models.ForeignKey(DocumentType, related_name='filenames', verbose_name=_('Document type'))
|
||||
filename = models.CharField(max_length=128, verbose_name=_('Filename'), db_index=True)
|
||||
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
|
||||
|
||||
def __unicode__(self):
|
||||
return self.filename
|
||||
@@ -481,21 +481,21 @@ class DocumentTypeFilename(models.Model):
|
||||
class Meta:
|
||||
ordering = ['filename']
|
||||
unique_together = ('document_type', 'filename')
|
||||
verbose_name = _(u'Document type quick rename filename')
|
||||
verbose_name_plural = _(u'Document types quick rename filenames')
|
||||
verbose_name = _('Document type quick rename filename')
|
||||
verbose_name_plural = _('Document types quick rename filenames')
|
||||
|
||||
|
||||
class DocumentPage(models.Model):
|
||||
"""
|
||||
Model that describes a document version page including it's content
|
||||
"""
|
||||
document_version = models.ForeignKey(DocumentVersion, verbose_name=_(u'Document version'), related_name='pages')
|
||||
content = models.TextField(blank=True, null=True, verbose_name=_(u'Content'))
|
||||
page_label = models.CharField(max_length=40, blank=True, null=True, verbose_name=_(u'Page label'))
|
||||
page_number = models.PositiveIntegerField(default=1, editable=False, verbose_name=_(u'Page number'), db_index=True)
|
||||
document_version = models.ForeignKey(DocumentVersion, verbose_name=_('Document version'), related_name='pages')
|
||||
content = models.TextField(blank=True, null=True, verbose_name=_('Content'))
|
||||
page_label = models.CharField(max_length=40, blank=True, null=True, verbose_name=_('Page label'))
|
||||
page_number = models.PositiveIntegerField(default=1, editable=False, verbose_name=_('Page number'), db_index=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return _(u'Page %(page_num)d out of %(total_pages)d of %(document)s') % {
|
||||
return _('Page %(page_num)d out of %(total_pages)d of %(document)s') % {
|
||||
'document': unicode(self.document),
|
||||
'page_num': self.page_number,
|
||||
'total_pages': self.document_version.pages.count()
|
||||
@@ -503,8 +503,8 @@ class DocumentPage(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ['page_number']
|
||||
verbose_name = _(u'Document page')
|
||||
verbose_name_plural = _(u'Document pages')
|
||||
verbose_name = _('Document page')
|
||||
verbose_name_plural = _('Document pages')
|
||||
|
||||
@models.permalink
|
||||
def get_absolute_url(self):
|
||||
@@ -521,7 +521,7 @@ class DocumentPage(models.Model):
|
||||
|
||||
|
||||
class ArgumentsValidator(object):
|
||||
message = _(u'Enter a valid value.')
|
||||
message = _('Enter a valid value.')
|
||||
code = 'invalid'
|
||||
|
||||
def __init__(self, message=None, code=None):
|
||||
@@ -546,10 +546,10 @@ class DocumentPageTransformation(models.Model):
|
||||
Model that stores the transformation and transformation arguments
|
||||
for a given document page
|
||||
"""
|
||||
document_page = models.ForeignKey(DocumentPage, verbose_name=_(u'Document page'))
|
||||
order = models.PositiveIntegerField(default=0, blank=True, null=True, verbose_name=_(u'Order'), db_index=True)
|
||||
transformation = models.CharField(choices=get_available_transformations_choices(), max_length=128, verbose_name=_(u'Transformation'))
|
||||
arguments = models.TextField(blank=True, null=True, verbose_name=_(u'Arguments'), help_text=_(u'Use dictionaries to indentify arguments, example: {\'degrees\':90}'), validators=[ArgumentsValidator()])
|
||||
document_page = models.ForeignKey(DocumentPage, verbose_name=_('Document page'))
|
||||
order = models.PositiveIntegerField(default=0, blank=True, null=True, verbose_name=_('Order'), db_index=True)
|
||||
transformation = models.CharField(choices=get_available_transformations_choices(), max_length=128, verbose_name=_('Transformation'))
|
||||
arguments = models.TextField(blank=True, null=True, verbose_name=_('Arguments'), help_text=_('Use dictionaries to indentify arguments, example: {\'degrees\':90}'), validators=[ArgumentsValidator()])
|
||||
objects = DocumentPageTransformationManager()
|
||||
|
||||
def __unicode__(self):
|
||||
@@ -557,8 +557,8 @@ class DocumentPageTransformation(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ('order',)
|
||||
verbose_name = _(u'Document page transformation')
|
||||
verbose_name_plural = _(u'Document page transformations')
|
||||
verbose_name = _('Document page transformation')
|
||||
verbose_name_plural = _('Document page transformations')
|
||||
|
||||
|
||||
class RecentDocument(models.Model):
|
||||
@@ -566,9 +566,9 @@ class RecentDocument(models.Model):
|
||||
Keeps a list of the n most recent accessed or created document for
|
||||
a given user
|
||||
"""
|
||||
user = models.ForeignKey(User, verbose_name=_(u'User'), editable=False)
|
||||
document = models.ForeignKey(Document, verbose_name=_(u'Document'), editable=False)
|
||||
datetime_accessed = models.DateTimeField(verbose_name=_(u'Accessed'), auto_now=True, db_index=True)
|
||||
user = models.ForeignKey(User, verbose_name=_('User'), editable=False)
|
||||
document = models.ForeignKey(Document, verbose_name=_('Document'), editable=False)
|
||||
datetime_accessed = models.DateTimeField(verbose_name=_('Accessed'), auto_now=True, db_index=True)
|
||||
|
||||
objects = RecentDocumentManager()
|
||||
|
||||
@@ -577,8 +577,8 @@ class RecentDocument(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ('-datetime_accessed',)
|
||||
verbose_name = _(u'Recent document')
|
||||
verbose_name_plural = _(u'Recent documents')
|
||||
verbose_name = _('Recent document')
|
||||
verbose_name_plural = _('Recent documents')
|
||||
|
||||
|
||||
# Quick hack to break the DocumentPage and DocumentPageTransformation circular dependency
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from permissions.models import PermissionNamespace, Permission
|
||||
|
||||
document_namespace = PermissionNamespace('documents', _(u'Documents'))
|
||||
document_namespace = PermissionNamespace('documents', _('Documents'))
|
||||
|
||||
PERMISSION_DOCUMENT_CREATE = Permission.objects.register(document_namespace, 'document_create', _(u'Create documents'))
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT = Permission.objects.register(document_namespace, 'document_properties_edit', _(u'Edit document properties'))
|
||||
PERMISSION_DOCUMENT_EDIT = Permission.objects.register(document_namespace, 'document_edit', _(u'Edit documents'))
|
||||
PERMISSION_DOCUMENT_VIEW = Permission.objects.register(document_namespace, 'document_view', _(u'View documents'))
|
||||
PERMISSION_DOCUMENT_DELETE = Permission.objects.register(document_namespace, 'document_delete', _(u'Delete documents'))
|
||||
PERMISSION_DOCUMENT_DOWNLOAD = Permission.objects.register(document_namespace, 'document_download', _(u'Download documents'))
|
||||
PERMISSION_DOCUMENT_TRANSFORM = Permission.objects.register(document_namespace, 'document_transform', _(u'Transform documents'))
|
||||
PERMISSION_DOCUMENT_TOOLS = Permission.objects.register(document_namespace, 'document_tools', _(u'Execute document modifying tools'))
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT = Permission.objects.register(document_namespace, 'document_version_revert', _(u'Revert documents to a previous version'))
|
||||
PERMISSION_DOCUMENT_NEW_VERSION = Permission.objects.register(document_namespace, 'document_new_version', _(u'Create new document versions'))
|
||||
PERMISSION_DOCUMENT_CREATE = Permission.objects.register(document_namespace, 'document_create', _('Create documents'))
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT = Permission.objects.register(document_namespace, 'document_properties_edit', _('Edit document properties'))
|
||||
PERMISSION_DOCUMENT_EDIT = Permission.objects.register(document_namespace, 'document_edit', _('Edit documents'))
|
||||
PERMISSION_DOCUMENT_VIEW = Permission.objects.register(document_namespace, 'document_view', _('View documents'))
|
||||
PERMISSION_DOCUMENT_DELETE = Permission.objects.register(document_namespace, 'document_delete', _('Delete documents'))
|
||||
PERMISSION_DOCUMENT_DOWNLOAD = Permission.objects.register(document_namespace, 'document_download', _('Download documents'))
|
||||
PERMISSION_DOCUMENT_TRANSFORM = Permission.objects.register(document_namespace, 'document_transform', _('Transform documents'))
|
||||
PERMISSION_DOCUMENT_TOOLS = Permission.objects.register(document_namespace, 'document_tools', _('Execute document modifying tools'))
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT = Permission.objects.register(document_namespace, 'document_version_revert', _('Revert documents to a previous version'))
|
||||
PERMISSION_DOCUMENT_NEW_VERSION = Permission.objects.register(document_namespace, 'document_new_version', _('Create new document versions'))
|
||||
|
||||
documents_setup_namespace = PermissionNamespace('documents_setup', _(u'Documents setup'))
|
||||
documents_setup_namespace = PermissionNamespace('documents_setup', _('Documents setup'))
|
||||
|
||||
PERMISSION_DOCUMENT_TYPE_VIEW = Permission.objects.register(documents_setup_namespace, 'document_type_view', _(u'View document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_EDIT = Permission.objects.register(documents_setup_namespace, 'document_type_edit', _(u'Edit document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_DELETE = Permission.objects.register(documents_setup_namespace, 'document_type_delete', _(u'Delete document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_CREATE = Permission.objects.register(documents_setup_namespace, 'document_type_create', _(u'Create document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_VIEW = Permission.objects.register(documents_setup_namespace, 'document_type_view', _('View document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_EDIT = Permission.objects.register(documents_setup_namespace, 'document_type_edit', _('Edit document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_DELETE = Permission.objects.register(documents_setup_namespace, 'document_type_delete', _('Delete document types'))
|
||||
PERMISSION_DOCUMENT_TYPE_CREATE = Permission.objects.register(documents_setup_namespace, 'document_type_create', _('Create document types'))
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from common.utils import load_backend
|
||||
|
||||
from .settings import STORAGE_BACKEND
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Configuration options for the documents app"""
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import pycountry
|
||||
@@ -11,25 +11,25 @@ from smart_settings.api import register_settings
|
||||
LANGUAGE_CHOICES = [(i.bibliographic, _(i.name)) for i in list(pycountry.languages)]
|
||||
|
||||
register_settings(
|
||||
namespace=u'documents',
|
||||
module=u'documents.settings',
|
||||
namespace='documents',
|
||||
module='documents.settings',
|
||||
settings=[
|
||||
# Storage
|
||||
{'name': u'STORAGE_BACKEND', 'global_name': u'DOCUMENTS_STORAGE_BACKEND', 'default': 'storage.backends.filebasedstorage.FileBasedStorage'},
|
||||
{'name': 'STORAGE_BACKEND', 'global_name': 'DOCUMENTS_STORAGE_BACKEND', 'default': 'storage.backends.filebasedstorage.FileBasedStorage'},
|
||||
# Usage
|
||||
{'name': u'PREVIEW_SIZE', 'global_name': u'DOCUMENTS_PREVIEW_SIZE', 'default': u'640x480'},
|
||||
{'name': u'PRINT_SIZE', 'global_name': u'DOCUMENTS_PRINT_SIZE', 'default': u'1400'},
|
||||
{'name': u'MULTIPAGE_PREVIEW_SIZE', 'global_name': u'DOCUMENTS_MULTIPAGE_PREVIEW_SIZE', 'default': u'160x120'},
|
||||
{'name': u'THUMBNAIL_SIZE', 'global_name': u'DOCUMENTS_THUMBNAIL_SIZE', 'default': u'50x50'},
|
||||
{'name': u'DISPLAY_SIZE', 'global_name': u'DOCUMENTS_DISPLAY_SIZE', 'default': u'1200'},
|
||||
{'name': u'RECENT_COUNT', 'global_name': u'DOCUMENTS_RECENT_COUNT', 'default': 40, 'description': _(u'Maximum number of recent (created, edited, viewed) documents to remember per user.')},
|
||||
{'name': u'ZOOM_PERCENT_STEP', 'global_name': u'DOCUMENTS_ZOOM_PERCENT_STEP', 'default': 50, 'description': _(u'Amount in percent zoom in or out a document page per user interaction.')},
|
||||
{'name': u'ZOOM_MAX_LEVEL', 'global_name': u'DOCUMENTS_ZOOM_MAX_LEVEL', 'default': 200, 'description': _(u'Maximum amount in percent (%) to allow user to zoom in a document page interactively.')},
|
||||
{'name': u'ZOOM_MIN_LEVEL', 'global_name': u'DOCUMENTS_ZOOM_MIN_LEVEL', 'default': 50, 'description': _(u'Minimum amount in percent (%) to allow user to zoom out a document page interactively.')},
|
||||
{'name': u'ROTATION_STEP', 'global_name': u'DOCUMENTS_ROTATION_STEP', 'default': 90, 'description': _(u'Amount in degrees to rotate a document page per user interaction.')},
|
||||
{'name': 'PREVIEW_SIZE', 'global_name': 'DOCUMENTS_PREVIEW_SIZE', 'default': '640x480'},
|
||||
{'name': 'PRINT_SIZE', 'global_name': 'DOCUMENTS_PRINT_SIZE', 'default': '1400'},
|
||||
{'name': 'MULTIPAGE_PREVIEW_SIZE', 'global_name': 'DOCUMENTS_MULTIPAGE_PREVIEW_SIZE', 'default': '160x120'},
|
||||
{'name': 'THUMBNAIL_SIZE', 'global_name': 'DOCUMENTS_THUMBNAIL_SIZE', 'default': '50x50'},
|
||||
{'name': 'DISPLAY_SIZE', 'global_name': 'DOCUMENTS_DISPLAY_SIZE', 'default': '1200'},
|
||||
{'name': 'RECENT_COUNT', 'global_name': 'DOCUMENTS_RECENT_COUNT', 'default': 40, 'description': _('Maximum number of recent (created, edited, viewed) documents to remember per user.')},
|
||||
{'name': 'ZOOM_PERCENT_STEP', 'global_name': 'DOCUMENTS_ZOOM_PERCENT_STEP', 'default': 50, 'description': _('Amount in percent zoom in or out a document page per user interaction.')},
|
||||
{'name': 'ZOOM_MAX_LEVEL', 'global_name': 'DOCUMENTS_ZOOM_MAX_LEVEL', 'default': 200, 'description': _('Maximum amount in percent (%) to allow user to zoom in a document page interactively.')},
|
||||
{'name': 'ZOOM_MIN_LEVEL', 'global_name': 'DOCUMENTS_ZOOM_MIN_LEVEL', 'default': 50, 'description': _('Minimum amount in percent (%) to allow user to zoom out a document page interactively.')},
|
||||
{'name': 'ROTATION_STEP', 'global_name': 'DOCUMENTS_ROTATION_STEP', 'default': 90, 'description': _('Amount in degrees to rotate a document page per user interaction.')},
|
||||
#
|
||||
{'name': u'CACHE_PATH', 'global_name': u'DOCUMENTS_CACHE_PATH', 'default': os.path.join(settings.MEDIA_ROOT, 'image_cache'), 'exists': True},
|
||||
{'name': u'LANGUAGE', 'global_name': u'DOCUMENTS_LANGUAGE', 'default': u'eng', 'description': _('Default documents language (in ISO639-2 format).')},
|
||||
{'name': u'LANGUAGE_CHOICES', 'global_name': u'DOCUMENTS_LANGUAGE_CHOICES', 'default': LANGUAGE_CHOICES, 'description': _('List of supported document languages.')},
|
||||
{'name': 'CACHE_PATH', 'global_name': 'DOCUMENTS_CACHE_PATH', 'default': os.path.join(settings.MEDIA_ROOT, 'image_cache'), 'exists': True},
|
||||
{'name': 'LANGUAGE', 'global_name': 'DOCUMENTS_LANGUAGE', 'default': 'eng', 'description': _('Default documents language (in ISO639-2 format).')},
|
||||
{'name': 'LANGUAGE_CHOICES', 'global_name': 'DOCUMENTS_LANGUAGE_CHOICES', 'default': LANGUAGE_CHOICES, 'description': _('List of supported document languages.')},
|
||||
]
|
||||
)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.dispatch import Signal
|
||||
|
||||
post_version_upload = Signal(providing_args=['instance'], use_caching=True)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db.models import Avg, Count, Min, Max
|
||||
@@ -21,7 +21,7 @@ def get_used_size(path, file_list):
|
||||
return total_size
|
||||
|
||||
|
||||
def storage_count(path=u'.'):
|
||||
def storage_count(path='.'):
|
||||
try:
|
||||
directories, files = storage_backend.listdir(path)
|
||||
except OSError:
|
||||
@@ -43,13 +43,13 @@ class DocumentStatistics(Statistic):
|
||||
results = []
|
||||
|
||||
results.extend([
|
||||
_(u'Document types: %d') % DocumentType.objects.count(),
|
||||
_('Document types: %d') % DocumentType.objects.count(),
|
||||
])
|
||||
document_stats = DocumentVersion.objects.annotate(page_count=Count('pages')).aggregate(Min('page_count'), Max('page_count'), Avg('page_count'))
|
||||
results.extend([
|
||||
_(u'Minimum amount of pages per document: %d') % (document_stats['page_count__min'] or 0),
|
||||
_(u'Maximum amount of pages per document: %d') % (document_stats['page_count__max'] or 0),
|
||||
_(u'Average amount of pages per document: %f') % (document_stats['page_count__avg'] or 0),
|
||||
_('Minimum amount of pages per document: %d') % (document_stats['page_count__min'] or 0),
|
||||
_('Maximum amount of pages per document: %d') % (document_stats['page_count__max'] or 0),
|
||||
_('Average amount of pages per document: %f') % (document_stats['page_count__avg'] or 0),
|
||||
])
|
||||
|
||||
return results
|
||||
@@ -62,14 +62,14 @@ class DocumentUsageStatistics(Statistic):
|
||||
total_db_documents = Document.objects.only('pk',).count()
|
||||
|
||||
results.extend([
|
||||
_(u'Documents in database: %d') % total_db_documents,
|
||||
_('Documents in database: %d') % total_db_documents,
|
||||
])
|
||||
|
||||
try:
|
||||
total_storage_documents, storage_used_space = storage_count()
|
||||
results.append(_(u'Documents in storage: %d') %
|
||||
results.append(_('Documents in storage: %d') %
|
||||
total_storage_documents)
|
||||
results.append(_(u'Space used in storage: %(base_2)s (base 2), %(base_10)s (base 10), %(bytes)d bytes') % {
|
||||
results.append(_('Space used in storage: %(base_2)s (base 2), %(base_10)s (base 10), %(bytes)d bytes') % {
|
||||
'base_2': pretty_size(storage_used_space),
|
||||
'base_10': pretty_size_10(storage_used_space),
|
||||
'bytes': storage_used_space
|
||||
@@ -78,7 +78,7 @@ class DocumentUsageStatistics(Statistic):
|
||||
pass
|
||||
|
||||
results.extend([
|
||||
_(u'Document pages in database: %d') % DocumentPage.objects.only('pk',).count(),
|
||||
_('Document pages in database: %d') % DocumentPage.objects.only('pk',).count(),
|
||||
])
|
||||
|
||||
return results
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
@@ -51,13 +53,13 @@ def task_new_document(document_type_id, shared_uploaded_file_id, label, descript
|
||||
|
||||
# TODO: Report/record how was file uploaded
|
||||
# if result['is_compressed'] is None:
|
||||
# messages.success(request, _(u'File uploaded successfully.'))
|
||||
# messages.success(request, _('File uploaded successfully.'))
|
||||
|
||||
# if result['is_compressed'] is True:
|
||||
# messages.success(request, _(u'File uncompressed successfully and uploaded as individual files.'))
|
||||
# messages.success(request, _('File uncompressed successfully and uploaded as individual files.'))
|
||||
|
||||
# if result['is_compressed'] is False:
|
||||
# messages.warning(request, _(u'File was not a compressed file, uploaded as it was.'))
|
||||
# messages.warning(request, _('File was not a compressed file, uploaded as it was.'))
|
||||
|
||||
|
||||
@app.task(ignore_result=True)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.template import Library, Node, Variable
|
||||
|
||||
from converter.api import get_dimensions
|
||||
@@ -12,9 +14,9 @@ class GetImageSizeNode(Node):
|
||||
def render(self, context):
|
||||
document = Variable(self.document).resolve(context)
|
||||
width, height = get_dimensions(document)
|
||||
context[u'document_width'], context['document_height'] = width, height
|
||||
context[u'document_aspect'] = float(width) / float(height)
|
||||
return u''
|
||||
context['document_width'], context['document_height'] = width, height
|
||||
context['document_aspect'] = float(width) / float(height)
|
||||
return ''
|
||||
|
||||
|
||||
@register.tag
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from json import loads
|
||||
import os
|
||||
@@ -83,7 +83,7 @@ class DocumentAPICreateDocumentTestCase(TestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
# Make sure a token was returned
|
||||
self.assertTrue(u'token' in response.content)
|
||||
self.assertTrue('token' in response.content)
|
||||
|
||||
token = loads(response.content)['token']
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
@@ -25,9 +25,9 @@ class DocumentPageImageWidget(forms.widgets.Widget):
|
||||
output.append('<div class="full-height scrollable mayan-page-wrapper-interactive">')
|
||||
output.append(document_html_widget(value.document, page=value.page_number, zoom=zoom, rotation=rotation, image_class='lazy-load-interactive', nolazyload=False, size=DISPLAY_SIZE))
|
||||
output.append('</div>')
|
||||
return mark_safe(u''.join(output))
|
||||
return mark_safe(''.join(output))
|
||||
else:
|
||||
return u''
|
||||
return ''
|
||||
|
||||
|
||||
class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||
@@ -36,7 +36,7 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||
"""
|
||||
def render(self, name, value, attrs=None):
|
||||
output = []
|
||||
output.append(u'<div id="carousel-container">')
|
||||
output.append('<div id="carousel-container">')
|
||||
|
||||
try:
|
||||
document_pages = value.pages.all()
|
||||
@@ -47,7 +47,7 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||
latest_version_pk = value.latest_version.pk
|
||||
|
||||
for page in document_pages:
|
||||
output.append(u'<div class="carousel-item">')
|
||||
output.append('<div class="carousel-item">')
|
||||
output.append(
|
||||
document_html_widget(
|
||||
page.document,
|
||||
@@ -61,12 +61,12 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||
post_load_class='lazy-load-carousel-loaded',
|
||||
)
|
||||
)
|
||||
output.append(u'<div class="carousel-item-page-number">%s</div>' % ugettext(u'Page %(page_number)d') % {'page_number': page.page_number})
|
||||
output.append(u'</div>')
|
||||
output.append('<div class="carousel-item-page-number">%s</div>' % ugettext('Page %(page_number)d') % {'page_number': page.page_number})
|
||||
output.append('</div>')
|
||||
|
||||
output.append(u'</div>')
|
||||
output.append('</div>')
|
||||
|
||||
return mark_safe(u''.join(output))
|
||||
return mark_safe(''.join(output))
|
||||
|
||||
|
||||
def document_thumbnail(document, **kwargs):
|
||||
@@ -74,13 +74,13 @@ def document_thumbnail(document, **kwargs):
|
||||
|
||||
|
||||
def document_link(document):
|
||||
return mark_safe(u'<a href="%s">%s</a>' % (document.get_absolute_url(), document))
|
||||
return mark_safe('<a href="%s">%s</a>' % (document.get_absolute_url(), document))
|
||||
|
||||
|
||||
def document_html_widget(document, click_view=None, click_view_arguments=None, page=DEFAULT_PAGE_NUMBER, zoom=DEFAULT_ZOOM_LEVEL, rotation=DEFAULT_ROTATION, gallery_name=None, fancybox_class='fancybox', version=None, image_class='lazy-load', title=None, size=THUMBNAIL_SIZE, nolazyload=False, post_load_class=None):
|
||||
result = []
|
||||
|
||||
alt_text = _(u'Document page image')
|
||||
alt_text = _('Document page image')
|
||||
|
||||
if not version:
|
||||
try:
|
||||
@@ -97,31 +97,31 @@ def document_html_widget(document, click_view=None, click_view_arguments=None, p
|
||||
}
|
||||
|
||||
if gallery_name:
|
||||
gallery_template = u'rel="%s"' % gallery_name
|
||||
gallery_template = 'rel="%s"' % gallery_name
|
||||
else:
|
||||
gallery_template = u''
|
||||
gallery_template = ''
|
||||
|
||||
query_string = urlencode(query_dict)
|
||||
|
||||
preview_view = u'%s?%s' % (reverse('document-image', args=[document.pk]), query_string)
|
||||
preview_view = '%s?%s' % (reverse('document-image', args=[document.pk]), query_string)
|
||||
|
||||
result.append(u'<div class="tc" id="document-%d-%d">' % (document.pk, page if page else 1))
|
||||
result.append('<div class="tc" id="document-%d-%d">' % (document.pk, page if page else 1))
|
||||
|
||||
if title:
|
||||
title_template = u'title="%s"' % strip_tags(title)
|
||||
title_template = 'title="%s"' % strip_tags(title)
|
||||
else:
|
||||
title_template = u''
|
||||
title_template = ''
|
||||
|
||||
if click_view:
|
||||
result.append(u'<a %s class="%s" href="%s" %s>' % (gallery_template, fancybox_class, u'%s?%s' % (reverse(click_view, args=click_view_arguments or [document.pk]), query_string), title_template))
|
||||
result.append('<a %s class="%s" href="%s" %s>' % (gallery_template, fancybox_class, '%s?%s' % (reverse(click_view, args=click_view_arguments or [document.pk]), query_string), title_template))
|
||||
|
||||
if nolazyload:
|
||||
result.append(u'<img class="img-nolazyload" src="%s" alt="%s" />' % (preview_view, alt_text))
|
||||
result.append('<img class="img-nolazyload" src="%s" alt="%s" />' % (preview_view, alt_text))
|
||||
else:
|
||||
result.append(u'<img class="thin_border %s" data-src="%s" data-post-load-class="%s" src="%smain/icons/hourglass.png" alt="%s" />' % (image_class, preview_view, post_load_class, settings.STATIC_URL, alt_text))
|
||||
result.append('<img class="thin_border %s" data-src="%s" data-post-load-class="%s" src="%smain/icons/hourglass.png" alt="%s" />' % (image_class, preview_view, post_load_class, settings.STATIC_URL, alt_text))
|
||||
|
||||
if click_view:
|
||||
result.append(u'</a>')
|
||||
result.append(u'</div>')
|
||||
result.append('</a>')
|
||||
result.append('</div>')
|
||||
|
||||
return mark_safe(u''.join(result))
|
||||
return mark_safe(''.join(result))
|
||||
|
||||
Reference in New Issue
Block a user