PEP8 cleanups, style cleanups, unused imports
This commit is contained in:
@@ -34,6 +34,8 @@ from .conf import settings as document_settings
|
||||
from .widgets import document_thumbnail
|
||||
|
||||
# Document page links expressions
|
||||
|
||||
|
||||
def is_first_page(context):
|
||||
return context['page'].page_number <= 1
|
||||
|
||||
@@ -179,7 +181,7 @@ register_top_menu(
|
||||
r'^documents/[^t]', r'^metadata/[^s]', r'comments', r'tags/document', r'grouping/[^s]', r'history/list/for_object/documents'
|
||||
],
|
||||
#children_view_regex=[r'upload'],
|
||||
children_views=['document_folder_list', 'folder_add_document', 'document_index_list', 'upload_version',],
|
||||
children_views=['document_folder_list', 'folder_add_document', 'document_index_list', 'upload_version', ],
|
||||
position=1
|
||||
)
|
||||
|
||||
@@ -197,7 +199,7 @@ if (validate_path(document_settings.CACHE_PATH) == False) or (not document_setti
|
||||
register_setup(document_type_setup)
|
||||
|
||||
class_permissions(Document, [
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT,
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT,
|
||||
PERMISSION_DOCUMENT_EDIT,
|
||||
PERMISSION_DOCUMENT_VIEW,
|
||||
PERMISSION_DOCUMENT_DELETE,
|
||||
@@ -205,5 +207,5 @@ class_permissions(Document, [
|
||||
PERMISSION_DOCUMENT_TRANSFORM,
|
||||
PERMISSION_DOCUMENT_NEW_VERSION,
|
||||
PERMISSION_DOCUMENT_VERSION_REVERT,
|
||||
PERMISSION_HISTORY_VIEW
|
||||
PERMISSION_HISTORY_VIEW
|
||||
])
|
||||
|
||||
@@ -5,13 +5,11 @@ 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.conf import settings
|
||||
|
||||
from common.forms import DetailForm
|
||||
from common.literals import PAGE_SIZE_CHOICES, PAGE_ORIENTATION_CHOICES
|
||||
from common.conf.settings import DEFAULT_PAPER_SIZE
|
||||
from common.conf.settings import DEFAULT_PAGE_ORIENTATION
|
||||
from common.widgets import TextAreaDiv
|
||||
from common.conf.settings import DEFAULT_PAPER_SIZE, DEFAULT_PAGE_ORIENTATION
|
||||
from common.widgets import TextAreaDiv
|
||||
|
||||
from .models import (Document, DocumentType,
|
||||
DocumentPage, DocumentPageTransformation, DocumentTypeFilename,
|
||||
@@ -19,6 +17,7 @@ from .models import (Document, DocumentType,
|
||||
from .widgets import document_html_widget
|
||||
from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES)
|
||||
|
||||
|
||||
# Document page forms
|
||||
class DocumentPageTransformationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
@@ -105,7 +104,7 @@ class DocumentPagesCarouselWidget(forms.widgets.Widget):
|
||||
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
||||
|
||||
for page in value.pages.all():
|
||||
|
||||
|
||||
output.append(u'<div style="display: inline-block; margin: 5px 10px 10px 10px;">')
|
||||
output.append(u'<div class="tc">%(page_string)s %(page)s</div>' % {'page_string': ugettext(u'Page'), 'page': page.page_number})
|
||||
output.append(
|
||||
@@ -180,24 +179,24 @@ class DocumentForm(forms.ModelForm):
|
||||
|
||||
if instance:
|
||||
self.version_fields(instance)
|
||||
|
||||
|
||||
def version_fields(self, document):
|
||||
self.fields['version_update'] = forms.ChoiceField(
|
||||
label=_(u'Version update'),
|
||||
choices=DocumentVersion.get_version_update_choices(document.latest_version)
|
||||
)
|
||||
|
||||
|
||||
self.fields['release_level'] = forms.ChoiceField(
|
||||
label=_(u'Release level'),
|
||||
choices=RELEASE_LEVEL_CHOICES,
|
||||
initial=RELEASE_LEVEL_FINAL,
|
||||
)
|
||||
|
||||
|
||||
self.fields['serial'] = forms.IntegerField(
|
||||
label=_(u'Release level serial'),
|
||||
initial=0,
|
||||
widget=forms.widgets.TextInput(
|
||||
attrs = {'style': 'width: auto;'}
|
||||
attrs={'style': 'width: auto;'}
|
||||
),
|
||||
)
|
||||
|
||||
@@ -210,7 +209,7 @@ class DocumentForm(forms.ModelForm):
|
||||
new_filename = forms.CharField(
|
||||
label=_('New document filename'), required=False
|
||||
)
|
||||
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = self.cleaned_data
|
||||
cleaned_data['new_version_data'] = {
|
||||
@@ -221,7 +220,8 @@ class DocumentForm(forms.ModelForm):
|
||||
}
|
||||
|
||||
# Always return the full collection of cleaned data.
|
||||
return cleaned_data
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class DocumentForm_edit(DocumentForm):
|
||||
"""
|
||||
@@ -230,7 +230,7 @@ class DocumentForm_edit(DocumentForm):
|
||||
class Meta:
|
||||
model = Document
|
||||
exclude = ('file', 'document_type', 'tags')
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DocumentForm_edit, self).__init__(*args, **kwargs)
|
||||
self.fields.pop('serial')
|
||||
|
||||
@@ -4,7 +4,6 @@ from ast import literal_eval
|
||||
from datetime import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
|
||||
from .conf.settings import RECENT_COUNT
|
||||
|
||||
@@ -18,7 +17,7 @@ class RecentDocumentManager(models.Manager):
|
||||
to_delete = self.model.objects.filter(user=user)[RECENT_COUNT:]
|
||||
for recent_to_delete in to_delete:
|
||||
recent_to_delete.delete()
|
||||
|
||||
|
||||
def get_for_user(self, user):
|
||||
if user.is_authenticated():
|
||||
return [recent_document.document for recent_document in self.model.objects.filter(user=user)]
|
||||
|
||||
@@ -11,8 +11,8 @@ import logging
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
@@ -30,7 +30,7 @@ from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION,
|
||||
DEFAULT_PAGE_NUMBER)
|
||||
|
||||
from .conf.settings import (CHECKSUM_FUNCTION, UUID_FUNCTION,
|
||||
STORAGE_BACKEND, PREVIEW_SIZE, DISPLAY_SIZE, CACHE_PATH,
|
||||
STORAGE_BACKEND, DISPLAY_SIZE, CACHE_PATH,
|
||||
ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL)
|
||||
from .managers import (RecentDocumentManager,
|
||||
DocumentPageTransformationManager)
|
||||
@@ -70,9 +70,9 @@ class DocumentType(models.Model):
|
||||
|
||||
|
||||
class Document(models.Model):
|
||||
'''
|
||||
"""
|
||||
Defines a single document with it's fields and properties
|
||||
'''
|
||||
"""
|
||||
uuid = models.CharField(max_length=48, blank=True, editable=False)
|
||||
document_type = models.ForeignKey(DocumentType, verbose_name=_(u'document type'), null=True, blank=True)
|
||||
description = models.TextField(blank=True, null=True, verbose_name=_(u'description'))
|
||||
@@ -133,7 +133,7 @@ class Document(models.Model):
|
||||
zoom = ZOOM_MAX_LEVEL
|
||||
|
||||
rotation = rotation % 360
|
||||
|
||||
|
||||
try:
|
||||
file_path = self.get_valid_image(size=size, page=page, zoom=zoom, rotation=rotation, version=version)
|
||||
except UnknownFileFormat:
|
||||
@@ -142,7 +142,7 @@ class Document(models.Model):
|
||||
file_path = get_error_icon_file_path()
|
||||
except:
|
||||
file_path = get_error_icon_file_path()
|
||||
|
||||
|
||||
if as_base64:
|
||||
image = open(file_path, 'r')
|
||||
out = StringIO()
|
||||
@@ -159,16 +159,16 @@ class Document(models.Model):
|
||||
|
||||
def add_as_recent_document_for_user(self, user):
|
||||
RecentDocument.objects.add_document_for_user(user, self)
|
||||
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
for version in self.versions.all():
|
||||
version.delete()
|
||||
return super(Document, self).delete(*args, **kwargs)
|
||||
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
return self.latest_version.size
|
||||
|
||||
|
||||
def new_version(self, file, comment=None, version_update=None, release_level=None, serial=None):
|
||||
logger.debug('creating new document version')
|
||||
if version_update:
|
||||
@@ -177,12 +177,12 @@ class Document(models.Model):
|
||||
new_version = DocumentVersion(
|
||||
document=self,
|
||||
file=file,
|
||||
major = new_version_dict.get('major'),
|
||||
minor = new_version_dict.get('minor'),
|
||||
micro = new_version_dict.get('micro'),
|
||||
release_level = release_level,
|
||||
serial = serial,
|
||||
comment = comment,
|
||||
major=new_version_dict.get('major'),
|
||||
minor=new_version_dict.get('minor'),
|
||||
micro=new_version_dict.get('micro'),
|
||||
release_level=release_level,
|
||||
serial=serial,
|
||||
comment=comment,
|
||||
)
|
||||
new_version.save()
|
||||
else:
|
||||
@@ -198,20 +198,20 @@ class Document(models.Model):
|
||||
|
||||
# Proxy methods
|
||||
def open(self, *args, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Return a file descriptor to a document's file irrespective of
|
||||
the storage backend
|
||||
'''
|
||||
"""
|
||||
return self.latest_version.open(*args, **kwargs)
|
||||
|
||||
|
||||
def save_to_file(self, *args, **kwargs):
|
||||
return self.latest_version.save_to_file(*args, **kwargs)
|
||||
|
||||
def exists(self):
|
||||
'''
|
||||
Returns a boolean value that indicates if the document's
|
||||
"""
|
||||
Returns a boolean value that indicates if the document's
|
||||
latest version file exists in storage
|
||||
'''
|
||||
"""
|
||||
return self.latest_version.exists()
|
||||
|
||||
# Compatibility methods
|
||||
@@ -226,7 +226,7 @@ class Document(models.Model):
|
||||
@property
|
||||
def file_mime_encoding(self):
|
||||
return self.latest_version.encoding
|
||||
|
||||
|
||||
@property
|
||||
def file_filename(self):
|
||||
return self.latest_version.filename
|
||||
@@ -275,12 +275,12 @@ class Document(models.Model):
|
||||
|
||||
|
||||
class DocumentVersion(models.Model):
|
||||
'''
|
||||
"""
|
||||
Model that describes a document version and its properties
|
||||
'''
|
||||
"""
|
||||
_pre_open_hooks = {}
|
||||
_post_save_hooks = {}
|
||||
|
||||
|
||||
@staticmethod
|
||||
def get_version_update_choices(document_version):
|
||||
return (
|
||||
@@ -288,7 +288,7 @@ class DocumentVersion(models.Model):
|
||||
(VERSION_UPDATE_MINOR, _(u'Minor %(major)i.%(minor)i, (some updates)') % document_version.get_new_version_dict(VERSION_UPDATE_MINOR)),
|
||||
(VERSION_UPDATE_MICRO, _(u'Micro %(major)i.%(minor)i.%(micro)i, (fixes)') % document_version.get_new_version_dict(VERSION_UPDATE_MICRO))
|
||||
)
|
||||
|
||||
|
||||
@classmethod
|
||||
def register_pre_open_hook(cls, order, func):
|
||||
cls._pre_open_hooks[order] = func
|
||||
@@ -296,7 +296,7 @@ class DocumentVersion(models.Model):
|
||||
@classmethod
|
||||
def register_post_save_hook(cls, order, func):
|
||||
cls._post_save_hooks[order] = func
|
||||
|
||||
|
||||
document = models.ForeignKey(Document, verbose_name=_(u'document'), editable=False)
|
||||
major = models.PositiveIntegerField(verbose_name=_(u'mayor'), default=1, editable=False)
|
||||
minor = models.PositiveIntegerField(verbose_name=_(u'minor'), default=0, editable=False)
|
||||
@@ -305,7 +305,7 @@ class DocumentVersion(models.Model):
|
||||
serial = models.PositiveIntegerField(verbose_name=_(u'serial'), default=0, editable=False)
|
||||
timestamp = models.DateTimeField(verbose_name=_(u'timestamp'), editable=False)
|
||||
comment = models.TextField(blank=True, verbose_name=_(u'comment'))
|
||||
|
||||
|
||||
# File related fields
|
||||
file = models.FileField(upload_to=get_filename_from_uuid, storage=STORAGE_BACKEND(), verbose_name=_(u'file'))
|
||||
mimetype = models.CharField(max_length=64, default='', editable=False)
|
||||
@@ -342,11 +342,11 @@ class DocumentVersion(models.Model):
|
||||
'minor': self.minor,
|
||||
'micro': self.micro + 1,
|
||||
}
|
||||
|
||||
|
||||
def get_formated_version(self):
|
||||
'''
|
||||
"""
|
||||
Return the formatted version information
|
||||
'''
|
||||
"""
|
||||
vers = [u'%i.%i' % (self.major, self.minor), ]
|
||||
|
||||
if self.micro:
|
||||
@@ -360,10 +360,10 @@ class DocumentVersion(models.Model):
|
||||
return self.documentpage_set
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
'''
|
||||
"""
|
||||
Overloaded save method that updates the document version's checksum,
|
||||
mimetype, page count and transformation when created
|
||||
'''
|
||||
"""
|
||||
new_document = not self.pk
|
||||
if not self.pk:
|
||||
self.timestamp = datetime.datetime.now()
|
||||
@@ -371,9 +371,9 @@ class DocumentVersion(models.Model):
|
||||
#Only do this for new documents
|
||||
transformations = kwargs.pop('transformations', None)
|
||||
super(DocumentVersion, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
for key in sorted(DocumentVersion._post_save_hooks):
|
||||
DocumentVersion._post_save_hooks[key](self)
|
||||
DocumentVersion._post_save_hooks[key](self)
|
||||
|
||||
if new_document:
|
||||
#Only do this for new documents
|
||||
@@ -385,10 +385,10 @@ class DocumentVersion(models.Model):
|
||||
self.apply_default_transformations(transformations)
|
||||
|
||||
def update_checksum(self, save=True):
|
||||
'''
|
||||
"""
|
||||
Open a document version's file and update the checksum field using the
|
||||
user provided checksum function
|
||||
'''
|
||||
"""
|
||||
if self.exists():
|
||||
source = self.open()
|
||||
self.checksum = unicode(CHECKSUM_FUNCTION(source.read()))
|
||||
@@ -444,17 +444,17 @@ class DocumentVersion(models.Model):
|
||||
page_transformation.save()
|
||||
|
||||
def revert(self):
|
||||
'''
|
||||
"""
|
||||
Delete the subsequent versions after this one
|
||||
'''
|
||||
"""
|
||||
for version in self.document.versions.filter(timestamp__gt=self.timestamp):
|
||||
version.delete()
|
||||
|
||||
def update_mimetype(self, save=True):
|
||||
'''
|
||||
"""
|
||||
Read a document verions's file and determine the mimetype by calling the
|
||||
get_mimetype wrapper
|
||||
'''
|
||||
"""
|
||||
if self.exists():
|
||||
try:
|
||||
self.mimetype, self.encoding = get_mimetype(self.open(), self.filename)
|
||||
@@ -466,35 +466,35 @@ class DocumentVersion(models.Model):
|
||||
self.save()
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
self.file.storage.delete(self.file.path)
|
||||
self.file.storage.delete(self.file.path)
|
||||
return super(DocumentVersion, self).delete(*args, **kwargs)
|
||||
|
||||
def exists(self):
|
||||
'''
|
||||
"""
|
||||
Returns a boolean value that indicates if the document's file
|
||||
exists in storage
|
||||
'''
|
||||
"""
|
||||
return self.file.storage.exists(self.file.path)
|
||||
|
||||
|
||||
def open(self, raw=False):
|
||||
'''
|
||||
"""
|
||||
Return a file descriptor to a document version's file irrespective of
|
||||
the storage backend
|
||||
'''
|
||||
"""
|
||||
if raw:
|
||||
return self.file.storage.open(self.file.path)
|
||||
else:
|
||||
result = self.file.storage.open(self.file.path)
|
||||
for key in sorted(DocumentVersion._pre_open_hooks):
|
||||
result = DocumentVersion._pre_open_hooks[key](result, self)
|
||||
|
||||
|
||||
return result
|
||||
|
||||
def save_to_file(self, filepath, buffer_size=1024 * 1024):
|
||||
'''
|
||||
"""
|
||||
Save a copy of the document from the document storage backend
|
||||
to the local filesystem
|
||||
'''
|
||||
"""
|
||||
input_descriptor = self.open()
|
||||
output_descriptor = open(filepath, 'wb')
|
||||
while True:
|
||||
@@ -507,7 +507,7 @@ class DocumentVersion(models.Model):
|
||||
output_descriptor.close()
|
||||
input_descriptor.close()
|
||||
return filepath
|
||||
|
||||
|
||||
@property
|
||||
def size(self):
|
||||
if self.exists():
|
||||
@@ -517,10 +517,10 @@ class DocumentVersion(models.Model):
|
||||
|
||||
|
||||
class DocumentTypeFilename(models.Model):
|
||||
'''
|
||||
"""
|
||||
List of filenames available to a specific document type for the
|
||||
quick rename functionality
|
||||
'''
|
||||
"""
|
||||
document_type = models.ForeignKey(DocumentType, 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'))
|
||||
@@ -535,12 +535,12 @@ class DocumentTypeFilename(models.Model):
|
||||
|
||||
|
||||
class DocumentPage(models.Model):
|
||||
'''
|
||||
"""
|
||||
Model that describes a document version page including it's content
|
||||
'''
|
||||
"""
|
||||
# New parent field
|
||||
document_version = models.ForeignKey(DocumentVersion, verbose_name=_(u'document version'))
|
||||
|
||||
|
||||
# Unchanged fields
|
||||
content = models.TextField(blank=True, null=True, verbose_name=_(u'content'))
|
||||
page_label = models.CharField(max_length=32, blank=True, null=True, verbose_name=_(u'page label'))
|
||||
@@ -568,7 +568,7 @@ class DocumentPage(models.Model):
|
||||
@property
|
||||
def siblings(self):
|
||||
return DocumentPage.objects.filter(document_version=self.document_version)
|
||||
|
||||
|
||||
# Compatibility methods
|
||||
@property
|
||||
def document(self):
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import absolute_import
|
||||
import os
|
||||
|
||||
from django.utils import unittest
|
||||
from django.test.client import Client
|
||||
from django.conf import settings
|
||||
from django.core.files.base import File
|
||||
|
||||
@@ -19,45 +18,45 @@ class DocumentTestCase(unittest.TestCase):
|
||||
self.document_type.save()
|
||||
|
||||
self.document = Document(
|
||||
document_type = self.document_type,
|
||||
description = 'description',
|
||||
document_type=self.document_type,
|
||||
description='description',
|
||||
)
|
||||
self.document.save()
|
||||
#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'))
|
||||
file_object.close()
|
||||
file_object.close()
|
||||
|
||||
def runTest(self):
|
||||
self.failUnlessEqual(self.document_type.name, 'test doc type')
|
||||
|
||||
self.failUnlessEqual(self.document.exists(), True)
|
||||
self.failUnlessEqual(self.document.size, 272213)
|
||||
|
||||
|
||||
self.failUnlessEqual(self.document.file_mimetype, 'application/pdf')
|
||||
self.failUnlessEqual(self.document.file_mime_encoding, 'binary')
|
||||
self.failUnlessEqual(self.document.file_filename, 'mayan_11_1.pdf')
|
||||
self.failUnlessEqual(self.document.checksum, 'c637ffab6b8bb026ed3784afdb07663fddc60099853fae2be93890852a69ecf3')
|
||||
self.failUnlessEqual(self.document.page_count, 47)
|
||||
|
||||
|
||||
self.failUnlessEqual(self.document.latest_version.get_formated_version(), '1.0')
|
||||
self.failUnlessEqual(self.document.has_detached_signature(), False)
|
||||
|
||||
|
||||
file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.gpg'))
|
||||
new_version_data = {
|
||||
'comment': 'test comment 1',
|
||||
'version_update': VERSION_UPDATE_MAJOR,
|
||||
'release_level': RELEASE_LEVEL_FINAL,
|
||||
'serial': 0,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new_version = self.document.new_version(file=File(file_object, name='mayan_11_1.pdf.gpg'), **new_version_data)
|
||||
file_object.close()
|
||||
|
||||
self.failUnlessEqual(self.document.latest_version.get_formated_version(), '2.0')
|
||||
self.failUnlessEqual(self.document.has_detached_signature(), False)
|
||||
|
||||
|
||||
self.failUnlessEqual(self.document.verify_signature().status, SIGNATURE_STATE_VALID)
|
||||
|
||||
new_version_data = {
|
||||
@@ -65,23 +64,22 @@ class DocumentTestCase(unittest.TestCase):
|
||||
'version_update': VERSION_UPDATE_MAJOR,
|
||||
'release_level': RELEASE_LEVEL_FINAL,
|
||||
'serial': 0,
|
||||
}
|
||||
}
|
||||
file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf'))
|
||||
new_version = self.document.new_version(file=File(file_object), **new_version_data)
|
||||
file_object.close()
|
||||
|
||||
self.failUnlessEqual(self.document.latest_version.get_formated_version(), '3.0')
|
||||
|
||||
|
||||
#GPGVerificationError
|
||||
self.failUnlessEqual(self.document.verify_signature(), None)
|
||||
|
||||
|
||||
file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.sig'), 'rb')
|
||||
new_version = self.document.add_detached_signature(File(file_object))
|
||||
file_object.close()
|
||||
|
||||
|
||||
self.failUnlessEqual(self.document.has_detached_signature(), True)
|
||||
self.failUnlessEqual(self.document.verify_signature().status, SIGNATURE_STATE_VALID)
|
||||
|
||||
|
||||
self.failUnlessEqual(self.document.verify_signature().status, SIGNATURE_STATE_VALID)
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
|
||||
@@ -33,7 +33,7 @@ urlpatterns = patterns('documents.views',
|
||||
url(r'^(?P<document_id>\d+)/create/siblings/$', 'document_create_siblings', (), 'document_create_siblings'),
|
||||
url(r'^(?P<document_id>\d+)/find_duplicates/$', 'document_find_duplicates', (), 'document_find_duplicates'),
|
||||
url(r'^(?P<document_id>\d+)/clear_transformations/$', 'document_clear_transformations', (), 'document_clear_transformations'),
|
||||
|
||||
|
||||
url(r'^(?P<document_pk>\d+)/version/all/$', 'document_version_list', (), 'document_version_list'),
|
||||
url(r'^document/version/(?P<document_version_pk>\d+)/download/$', 'document_download', (), 'document_version_download'),
|
||||
url(r'^document/version/(?P<document_version_pk>\d+)/revert/$', 'document_version_revert', (), 'document_version_revert'),
|
||||
|
||||
@@ -48,10 +48,10 @@ from .literals import (HISTORY_DOCUMENT_CREATED,
|
||||
HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED)
|
||||
from .forms import (DocumentTypeSelectForm,
|
||||
DocumentForm_edit, DocumentPropertiesForm,
|
||||
DocumentPreviewForm, DocumentPageForm,
|
||||
DocumentPageTransformationForm, DocumentContentForm,
|
||||
DocumentPageForm_edit, DocumentPageForm_text, PrintForm,
|
||||
DocumentTypeForm, DocumentTypeFilenameForm,
|
||||
DocumentPreviewForm, DocumentPageForm,
|
||||
DocumentPageTransformationForm, DocumentContentForm,
|
||||
DocumentPageForm_edit, DocumentPageForm_text, PrintForm,
|
||||
DocumentTypeForm, DocumentTypeFilenameForm,
|
||||
DocumentTypeFilenameForm_create)
|
||||
from .wizards import DocumentCreateWizard
|
||||
from .models import (Document, DocumentType, DocumentPage,
|
||||
@@ -68,12 +68,12 @@ def document_list(request, object_list=None, title=None, extra_context=None):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
# If user doesn't have global permission, get a list of document
|
||||
# for which he/she does hace access use it to filter the
|
||||
# for which he/she does hace access use it to filter the
|
||||
# provided object_list
|
||||
final_object_list = AccessEntry.objects.filter_objects_by_access(PERMISSION_DOCUMENT_VIEW, request.user, pre_object_list)
|
||||
else:
|
||||
final_object_list = pre_object_list
|
||||
|
||||
|
||||
context = {
|
||||
'object_list': final_object_list,
|
||||
'title': title if title else _(u'documents'),
|
||||
@@ -190,7 +190,7 @@ def document_delete(request, document_id=None, document_id_list=None):
|
||||
documents = [get_object_or_404(Document, pk=document_id)]
|
||||
post_action_redirect = reverse('document_list')
|
||||
elif document_id_list:
|
||||
documents = [get_object_or_404(Document, pk=document_id) for document_id in document_id_list.split(',')]
|
||||
documents = [get_object_or_404(Document, pk=document_id) for document_id in document_id_list.split(',')]
|
||||
else:
|
||||
messages.error(request, _(u'Must provide at least one document.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
@@ -296,12 +296,12 @@ def get_document_image(request, document_id, size=PREVIEW_SIZE, base64_version=F
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
|
||||
page = int(request.GET.get('page', DEFAULT_PAGE_NUMBER))
|
||||
|
||||
zoom = int(request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
|
||||
|
||||
|
||||
version = int(request.GET.get('version', document.latest_version.pk))
|
||||
|
||||
if zoom < ZOOM_MIN_LEVEL:
|
||||
@@ -317,12 +317,12 @@ def get_document_image(request, document_id, size=PREVIEW_SIZE, base64_version=F
|
||||
else:
|
||||
# TODO: fix hardcoded MIMETYPE
|
||||
return sendfile.sendfile(request, document.get_image(size=size, page=page, zoom=zoom, rotation=rotation, version=version), mimetype=DEFAULT_FILE_FORMAT_MIMETYPE)
|
||||
|
||||
|
||||
|
||||
def document_download(request, document_id=None, document_id_list=None, document_version_pk=None):
|
||||
document_version = None
|
||||
documents = []
|
||||
|
||||
|
||||
if document_id:
|
||||
documents = [get_object_or_404(Document, pk=document_id)]
|
||||
post_action_redirect = reverse('document_list')
|
||||
@@ -338,7 +338,7 @@ def document_download(request, document_id=None, document_id_list=None, document
|
||||
|
||||
if len(documents) == 1:
|
||||
document_version = documents[0].latest_version
|
||||
|
||||
|
||||
if document_version:
|
||||
try:
|
||||
# Test permissions and trigger exception
|
||||
@@ -363,9 +363,9 @@ def document_download(request, document_id=None, document_id_list=None, document
|
||||
descriptor = document.open()
|
||||
compressed_file.add_file(descriptor, arcname=document.filename)
|
||||
descriptor.close()
|
||||
|
||||
|
||||
compressed_file.close()
|
||||
|
||||
|
||||
return serve_file(
|
||||
request,
|
||||
compressed_file.as_file('document_bundle.zip'),
|
||||
@@ -386,14 +386,14 @@ def document_multiple_download(request):
|
||||
request, document_id_list=request.GET.get('id_list', [])
|
||||
)
|
||||
|
||||
|
||||
def document_page_transformation_list(request, document_page_id):
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page.document)
|
||||
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page.document)
|
||||
|
||||
return object_list(
|
||||
request,
|
||||
@@ -418,11 +418,11 @@ def document_page_transformation_list(request, document_page_id):
|
||||
|
||||
def document_page_transformation_create(request, document_page_id):
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page.document)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentPageTransformationForm(request.POST, initial={'document_page': document_page})
|
||||
@@ -450,7 +450,7 @@ def document_page_transformation_edit(request, document_page_transformation_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page_transformation.document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page_transformation.document_page.document)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentPageTransformationForm(request.POST, instance=document_page_transformation)
|
||||
@@ -482,7 +482,7 @@ def document_page_transformation_delete(request, document_page_transformation_id
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page_transformation.document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page_transformation.document_page.document)
|
||||
|
||||
redirect_view = reverse('document_page_transformation_list', args=[document_page_transformation.document_page_id])
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
@@ -516,7 +516,7 @@ def document_find_duplicates(request, document_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
|
||||
extra_context = {
|
||||
'title': _(u'duplicates of: %s') % document,
|
||||
@@ -565,8 +565,8 @@ def document_find_all_duplicates(request):
|
||||
|
||||
|
||||
def document_update_page_count(request):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TOOLS])
|
||||
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TOOLS])
|
||||
|
||||
office_converter = OfficeConverter()
|
||||
qs = DocumentVersion.objects.exclude(filename__iendswith='dxf').filter(mimetype__in=office_converter.mimetypes())
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))
|
||||
@@ -580,7 +580,7 @@ def document_update_page_count(request):
|
||||
processed += 1
|
||||
if old_page_count != document_version.pages.count():
|
||||
updated += 1
|
||||
|
||||
|
||||
messages.success(request, _(u'Page count update complete. Documents processed: %(total)d, documents with changed page count: %(change)d') % {
|
||||
'total': processed,
|
||||
'change': updated
|
||||
@@ -673,12 +673,12 @@ def document_missing_list(request):
|
||||
|
||||
|
||||
def document_page_view(request, document_page_id):
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
zoom = int(request.GET.get('zoom', DEFAULT_ZOOM_LEVEL))
|
||||
rotation = int(request.GET.get('rotation', DEFAULT_ROTATION))
|
||||
@@ -717,7 +717,7 @@ def document_page_text(request, document_page_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
document_page_form = DocumentPageForm_text(instance=document_page)
|
||||
|
||||
@@ -733,11 +733,11 @@ def document_page_text(request, document_page_id):
|
||||
|
||||
def document_page_edit(request, document_page_id):
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_EDIT])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_EDIT, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_EDIT, request.user, document_page.document)
|
||||
|
||||
if request.method == 'POST':
|
||||
form = DocumentPageForm_edit(request.POST, instance=document_page)
|
||||
@@ -766,8 +766,8 @@ def document_page_navigation_next(request, document_page_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)
|
||||
|
||||
if document_page.page_number >= document_page.siblings.count():
|
||||
@@ -784,7 +784,7 @@ def document_page_navigation_previous(request, document_page_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)
|
||||
|
||||
@@ -803,7 +803,7 @@ def document_page_navigation_first(request, document_page_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)
|
||||
|
||||
@@ -812,12 +812,12 @@ def document_page_navigation_first(request, document_page_id):
|
||||
|
||||
def document_page_navigation_last(request, document_page_id):
|
||||
document_page = get_object_or_404(DocumentPage, pk=document_page_id)
|
||||
document_page = get_object_or_404(document_page.siblings, page_number=document_page.siblings.count())
|
||||
document_page = get_object_or_404(document_page.siblings, page_number=document_page.siblings.count())
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)
|
||||
|
||||
@@ -841,7 +841,7 @@ def transform_page(request, document_page_id, zoom_function=None, rotation_funct
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document_page.document)
|
||||
|
||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).path)
|
||||
|
||||
@@ -900,11 +900,11 @@ def document_page_rotate_left(request, document_page_id):
|
||||
|
||||
def document_print(request, document_id):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
|
||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||
|
||||
@@ -964,7 +964,7 @@ def document_hard_copy(request, document_id):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
|
||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||
|
||||
@@ -1056,7 +1056,7 @@ def document_type_edit(request, document_type_id):
|
||||
#'object': document_type,
|
||||
'object_name': _(u'document type'),
|
||||
'navigation_object_name': 'document_type',
|
||||
'document_type': document_type,
|
||||
'document_type': document_type,
|
||||
'next': next
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
@@ -1253,8 +1253,8 @@ def document_type_filename_create(request, document_type_id):
|
||||
'document_type': document_type,
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
|
||||
def document_clear_image_cache(request):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_TOOLS])
|
||||
|
||||
@@ -1266,23 +1266,23 @@ def document_clear_image_cache(request):
|
||||
messages.success(request, _(u'Document image cache cleared successfully'))
|
||||
except Exception, msg:
|
||||
messages.error(request, _(u'Error clearing document image cache; %s') % msg)
|
||||
|
||||
|
||||
return HttpResponseRedirect(previous)
|
||||
|
||||
return render_to_response('generic_confirm.html', {
|
||||
'previous': previous,
|
||||
'title': _(u'Are you sure you wish to clear the document image cache?'),
|
||||
'form_icon': u'camera_delete.png',
|
||||
}, context_instance=RequestContext(request))
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def document_version_list(request, document_pk):
|
||||
document = get_object_or_404(Document, pk=document_pk)
|
||||
|
||||
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VIEW, request.user, document)
|
||||
|
||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||
|
||||
@@ -1330,7 +1330,7 @@ def document_version_revert(request, document_version_pk):
|
||||
try:
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_DOCUMENT_VERSION_REVERT])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VERSION_REVERT, request.user, document_version.document)
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_VERSION_REVERT, request.user, document_version.document)
|
||||
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', '/')))
|
||||
|
||||
@@ -1340,7 +1340,7 @@ def document_version_revert(request, document_version_pk):
|
||||
messages.success(request, _(u'Document version reverted successfully'))
|
||||
except Exception, msg:
|
||||
messages.error(request, _(u'Error reverting document version; %s') % msg)
|
||||
|
||||
|
||||
return HttpResponseRedirect(previous)
|
||||
|
||||
return render_to_response('generic_confirm.html', {
|
||||
@@ -1349,4 +1349,4 @@ def document_version_revert(request, document_version_pk):
|
||||
'title': _(u'Are you sure you wish to revert to this version?'),
|
||||
'message': _(u'All later version after this one will be deleted too.'),
|
||||
'form_icon': u'page_refresh.png',
|
||||
}, context_instance=RequestContext(request))
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
@@ -6,12 +6,9 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.http import urlencode
|
||||
|
||||
from converter.literals import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \
|
||||
DEFAULT_PAGE_NUMBER
|
||||
from converter.exceptions import UnknownFileFormat, UnkownConvertError
|
||||
from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION,
|
||||
DEFAULT_PAGE_NUMBER)
|
||||
from mimetype.api import get_error_icon_url
|
||||
|
||||
from .conf.settings import DISPLAY_SIZE
|
||||
|
||||
|
||||
def document_thumbnail(document):
|
||||
@@ -24,7 +21,7 @@ def document_link(document):
|
||||
|
||||
def document_html_widget(document, view='document_thumbnail', click_view=None, page=DEFAULT_PAGE_NUMBER, zoom=DEFAULT_ZOOM_LEVEL, rotation=DEFAULT_ROTATION, gallery_name=None, fancybox_class='fancybox', version=None):
|
||||
result = []
|
||||
|
||||
|
||||
alt_text = _(u'document page image')
|
||||
|
||||
if not version:
|
||||
@@ -41,13 +38,13 @@ def document_html_widget(document, view='document_thumbnail', click_view=None, p
|
||||
gallery_template = u'rel="%s"' % gallery_name
|
||||
else:
|
||||
gallery_template = u''
|
||||
|
||||
|
||||
query_string = urlencode(query_dict)
|
||||
preview_view = u'%s?%s' % (reverse(view, args=[document.pk]), query_string)
|
||||
|
||||
|
||||
plain_template = []
|
||||
plain_template.append(u'<img src="%s" alt="%s" />' % (preview_view, alt_text))
|
||||
|
||||
|
||||
result.append(u'<div class="tc" id="document-%d-%d">' % (document.pk, page if page else 1))
|
||||
|
||||
if click_view:
|
||||
@@ -55,7 +52,7 @@ def document_html_widget(document, view='document_thumbnail', click_view=None, p
|
||||
result.append(u'<img class="thin_border lazy-load" data-href="%s" src="%simages/ajax-loader.gif" alt="%s" />' % (preview_view, settings.STATIC_URL, alt_text))
|
||||
result.append(u'<noscript><img style="border: 1px solid black;" src="%s" alt="%s" /></noscript>' % (preview_view, alt_text))
|
||||
|
||||
if click_view:
|
||||
if click_view:
|
||||
result.append(u'</a>')
|
||||
result.append(u'</div>')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user