PEP8 cleanups, style cleanups, unused imports
This commit is contained in:
@@ -4,10 +4,10 @@ import logging
|
||||
import sys
|
||||
import types
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models.base import ModelBase
|
||||
from django.template.defaultfilters import capfirst
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from common.models import AnonymousUserSingleton
|
||||
|
||||
@@ -40,7 +40,6 @@ class EncapsulatedObject(object):
|
||||
#@classmethod
|
||||
#def encapsulate_list(cls, source_object=None, app_label=None, model=None, pk=None):
|
||||
|
||||
|
||||
@classmethod
|
||||
def encapsulate(cls, source_object):
|
||||
source_object = AnonymousUserSingleton.objects.passthru_check(source_object)
|
||||
|
||||
@@ -4,8 +4,8 @@ from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
||||
from permissions.models import Permission, Role
|
||||
from common.utils import generate_choices_w_labels, encapsulate, get_object_name
|
||||
from permissions.models import Role
|
||||
from common.utils import get_object_name
|
||||
from common.models import AnonymousUserSingleton
|
||||
|
||||
from .classes import AccessHolder
|
||||
@@ -14,6 +14,7 @@ from .classes import AccessHolder
|
||||
def _as_choice_list(holders):
|
||||
return sorted([(AccessHolder.encapsulate(holder).gid, get_object_name(holder, display_object_type=False)) for holder in holders], key=lambda x: x[1])
|
||||
|
||||
|
||||
class HolderSelectionForm(forms.Form):
|
||||
holder_gid = forms.ChoiceField(
|
||||
label=_(u'New holder')
|
||||
|
||||
@@ -8,9 +8,7 @@ from django.utils.translation import ugettext
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from permissions.models import StoredPermission
|
||||
|
||||
@@ -22,9 +20,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AccessEntry(models.Model):
|
||||
'''
|
||||
"""
|
||||
Model that hold the permission, object, actor relationship
|
||||
'''
|
||||
"""
|
||||
permission = models.ForeignKey(StoredPermission, verbose_name=_(u'permission'))
|
||||
|
||||
holder_type = models.ForeignKey(
|
||||
@@ -59,10 +57,10 @@ class AccessEntry(models.Model):
|
||||
|
||||
|
||||
class DefaultAccessEntry(models.Model):
|
||||
'''
|
||||
"""
|
||||
Model that holds the permission, class, actor relationship, that will
|
||||
be added upon the creation of an instance of said class
|
||||
'''
|
||||
"""
|
||||
@classmethod
|
||||
def get_classes(cls):
|
||||
return [AccessObjectClass.encapsulate(cls) for cls in get_classes()]
|
||||
|
||||
@@ -2,10 +2,6 @@ from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.safestring import mark_safe
|
||||
from django import forms
|
||||
from django.forms.util import flatatt
|
||||
from django.utils.html import conditional_escape
|
||||
from django.utils.encoding import force_unicode
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models.base import ModelBase
|
||||
from django.template.defaultfilters import capfirst
|
||||
|
||||
@@ -92,10 +92,10 @@ class FilterForm(forms.Form):
|
||||
|
||||
|
||||
class ChoiceForm(forms.Form):
|
||||
'''
|
||||
"""
|
||||
Form to be used in side by side templates used to add or remove
|
||||
items from a many to many field
|
||||
'''
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
choices = kwargs.pop('choices', [])
|
||||
label = kwargs.pop('label', _(u'Selection'))
|
||||
@@ -108,28 +108,28 @@ class ChoiceForm(forms.Form):
|
||||
|
||||
|
||||
class UserForm_view(DetailForm):
|
||||
'''
|
||||
"""
|
||||
Form used to display an user's public details
|
||||
'''
|
||||
"""
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('username', 'first_name', 'last_name', 'email', 'is_staff', 'is_superuser', 'last_login', 'date_joined', 'groups')
|
||||
|
||||
|
||||
class UserForm(forms.ModelForm):
|
||||
'''
|
||||
"""
|
||||
Form used to edit an user's mininal fields by the user himself
|
||||
'''
|
||||
"""
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name')
|
||||
|
||||
|
||||
class EmailAuthenticationForm(AuthenticationForm):
|
||||
'''
|
||||
"""
|
||||
Override the default authentication form to use email address
|
||||
authentication
|
||||
'''
|
||||
"""
|
||||
email = forms.CharField(label=_(u'Email'), max_length=75,
|
||||
widget=EmailInput()
|
||||
)
|
||||
@@ -153,7 +153,7 @@ EmailAuthenticationForm.base_fields.keyOrder = ['email', 'password']
|
||||
|
||||
class FileDisplayForm(forms.Form):
|
||||
text = forms.CharField(
|
||||
label='',#_(u'Text'),
|
||||
label='', # _(u'Text'),
|
||||
widget=forms.widgets.Textarea(
|
||||
attrs={'cols': 40, 'rows': 20, 'readonly': 'readonly'}
|
||||
)
|
||||
|
||||
@@ -2,6 +2,7 @@ from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
class SetVarNode(template.Node):
|
||||
def __init__(self, var_name, var_value):
|
||||
self.var_name = var_name
|
||||
@@ -18,6 +19,7 @@ class SetVarNode(template.Node):
|
||||
|
||||
return u""
|
||||
|
||||
|
||||
def set_var(parser, token):
|
||||
"""
|
||||
{% set <var_name> = <var_value> %}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
@@ -18,7 +18,7 @@ from django.contrib.auth.models import User
|
||||
|
||||
|
||||
def urlquote(link=None, get=None):
|
||||
u'''
|
||||
u"""
|
||||
This method does both: urlquote() and urlencode()
|
||||
|
||||
urlqoute(): Quote special characters in 'link'
|
||||
@@ -33,7 +33,7 @@ def urlquote(link=None, get=None):
|
||||
urlquote('/mypath/', {'key': 'value'}) --> '/mypath/?key=value'
|
||||
urlquote('/mypath/', {'key': ['value1', 'value2']}) --> '/mypath/?key=value1&key=value2'
|
||||
urlquote({'key': ['value1', 'value2']}) --> 'key=value1&key=value2'
|
||||
'''
|
||||
"""
|
||||
if get is None:
|
||||
get = []
|
||||
|
||||
@@ -112,9 +112,9 @@ def pretty_size_10(size):
|
||||
# http://www.johncardinal.com/tmgutil/capitalizenames.htm
|
||||
|
||||
def proper_name(name):
|
||||
'''
|
||||
"""
|
||||
Does the work of capitalizing a name (can be a full name).
|
||||
'''
|
||||
"""
|
||||
mc = re.compile(r'^Mc(\w)(?=\w)', re.I)
|
||||
mac = re.compile(r'^Mac(\w)(?=\w)', re.I)
|
||||
suffixes = [
|
||||
|
||||
@@ -18,19 +18,19 @@ from .conf.settings import LOGIN_METHOD
|
||||
|
||||
|
||||
def password_change_done(request):
|
||||
'''
|
||||
"""
|
||||
View called when the new user password has been accepted
|
||||
'''
|
||||
"""
|
||||
|
||||
messages.success(request, _(u'Your password has been successfully changed.'))
|
||||
return redirect('home')
|
||||
|
||||
|
||||
def multi_object_action_view(request):
|
||||
'''
|
||||
"""
|
||||
Proxy view called first when using a multi object action, which
|
||||
then redirects to the appropiate specialized view
|
||||
'''
|
||||
"""
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/')))
|
||||
|
||||
@@ -159,9 +159,9 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
|
||||
|
||||
def current_user_details(request):
|
||||
'''
|
||||
"""
|
||||
Display the current user's details
|
||||
'''
|
||||
"""
|
||||
form = UserForm_view(instance=request.user)
|
||||
|
||||
return render_to_response(
|
||||
@@ -174,9 +174,9 @@ def current_user_details(request):
|
||||
|
||||
|
||||
def current_user_edit(request):
|
||||
'''
|
||||
"""
|
||||
Allow an user to edit his own details
|
||||
'''
|
||||
"""
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', reverse('current_user_details'))))
|
||||
|
||||
@@ -199,10 +199,10 @@ def current_user_edit(request):
|
||||
|
||||
|
||||
def login_view(request):
|
||||
'''
|
||||
"""
|
||||
Control how the use is to be authenticated, options are 'email' and
|
||||
'username'
|
||||
'''
|
||||
"""
|
||||
kwargs = {'template_name': 'login.html'}
|
||||
|
||||
if LOGIN_METHOD == 'email':
|
||||
@@ -217,9 +217,9 @@ def login_view(request):
|
||||
|
||||
|
||||
def changelog_view(request):
|
||||
'''
|
||||
"""
|
||||
Display the included Changelog.txt file from the about menu
|
||||
'''
|
||||
"""
|
||||
form = ChangelogForm()
|
||||
return render_to_response(
|
||||
'generic_detail.html', {
|
||||
@@ -230,9 +230,9 @@ def changelog_view(request):
|
||||
|
||||
|
||||
def license_view(request):
|
||||
'''
|
||||
"""
|
||||
Display the included LICENSE file from the about menu
|
||||
'''
|
||||
"""
|
||||
form = LicenseForm()
|
||||
return render_to_response(
|
||||
'generic_detail.html', {
|
||||
|
||||
@@ -10,10 +10,10 @@ from django.utils.encoding import force_unicode
|
||||
|
||||
|
||||
class PlainWidget(forms.widgets.Widget):
|
||||
'''
|
||||
"""
|
||||
Class to define a form widget that effectively nulls the htmls of a
|
||||
widget and reduces the output to only it's value
|
||||
'''
|
||||
"""
|
||||
def render(self, name, value, attrs=None):
|
||||
return mark_safe(u'%s' % value)
|
||||
|
||||
@@ -74,10 +74,10 @@ def two_state_template(state, famfam_ok_icon=u'tick', famfam_fail_icon=u'cross')
|
||||
|
||||
|
||||
class TextAreaDiv(forms.widgets.Widget):
|
||||
'''
|
||||
"""
|
||||
Class to define a form widget that simulates the behavior of a
|
||||
Textarea widget but using a div tag instead
|
||||
'''
|
||||
"""
|
||||
|
||||
def __init__(self, attrs=None):
|
||||
# The 'rows' and 'cols' attributes are required for HTML correctness.
|
||||
@@ -98,10 +98,10 @@ class TextAreaDiv(forms.widgets.Widget):
|
||||
|
||||
# From: http://www.peterbe.com/plog/emailinput-html5-django
|
||||
class EmailInput(forms.widgets.Input):
|
||||
'''
|
||||
"""
|
||||
Class for a login form widget that accepts only well formated
|
||||
email address
|
||||
'''
|
||||
"""
|
||||
input_type = 'email'
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
@@ -114,11 +114,11 @@ class EmailInput(forms.widgets.Input):
|
||||
|
||||
|
||||
class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
'''
|
||||
"""
|
||||
Class for a form widget composed of a selection of checkboxes wrapped
|
||||
in a div tag with automatic overflow to add scrollbars when the list
|
||||
exceds the height of the div
|
||||
'''
|
||||
"""
|
||||
def render(self, name, value, attrs=None, choices=()):
|
||||
if value is None:
|
||||
value = []
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
'''Common abstract classes for forms.'''
|
||||
"""Common abstract classes for forms."""
|
||||
try:
|
||||
import cPickle as pickle
|
||||
except ImportError:
|
||||
@@ -15,13 +15,13 @@ __all__ = ('security_hash', 'BoundFormWizard')
|
||||
|
||||
|
||||
def security_hash_new(form, exclude=None, *args):
|
||||
'''
|
||||
"""
|
||||
Calculates a security hash for the given Form/FormSet instance.
|
||||
|
||||
This creates a list of the form field names/values in a deterministic
|
||||
order, pickles the result with the SECRET_KEY setting, then takes an md5
|
||||
hash of that.
|
||||
'''
|
||||
"""
|
||||
|
||||
data = []
|
||||
if exclude is None:
|
||||
@@ -52,19 +52,19 @@ def security_hash_new(form, exclude=None, *args):
|
||||
|
||||
|
||||
class BoundFormWizard(FormWizard):
|
||||
'''
|
||||
"""
|
||||
Render prev_fields as a list of bound form fields in the template
|
||||
context rather than raw html.
|
||||
'''
|
||||
"""
|
||||
|
||||
def security_hash(self, request, form):
|
||||
'''
|
||||
"""
|
||||
Calculates the security hash for the given HttpRequest and
|
||||
Form/FormSet instances.
|
||||
|
||||
Subclasses may want to take into account request-specific information,
|
||||
such as the IP address.
|
||||
'''
|
||||
"""
|
||||
|
||||
return security_hash_new(form)
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ import logging
|
||||
import tempfile
|
||||
import os
|
||||
|
||||
from django.core.files.base import File
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.http import urlquote_plus
|
||||
|
||||
from hkp import KeyServer
|
||||
import gnupg
|
||||
@@ -107,7 +105,7 @@ class Key(object):
|
||||
keys = gpg.gpg.list_keys(secret=secret)
|
||||
key = next((key for key in keys if key['keyid'] == key_id), None)
|
||||
if not key:
|
||||
if search_keyservers and secret==False:
|
||||
if search_keyservers and secret == False:
|
||||
try:
|
||||
gpg.receive_key(key_id)
|
||||
return Key(gpg, key_id)
|
||||
|
||||
@@ -4,13 +4,9 @@ import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.conf import settings
|
||||
from django.template.defaultfilters import force_escape
|
||||
|
||||
from permissions.models import Permission
|
||||
from common.utils import (urlquote, encapsulate)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from documents.models import Document
|
||||
from navigation.api import register_links, register_multi_item_links
|
||||
from project_setup.api import register_setup
|
||||
from navigation.api import register_links
|
||||
from acls import ACLS_VIEW_ACL, ACLS_EDIT_ACL
|
||||
from acls.api import class_permissions
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from documents.models import Document
|
||||
from acls.views import acl_list_for
|
||||
from acls.models import AccessEntry
|
||||
|
||||
|
||||
def document_acl_list(request, document_id):
|
||||
|
||||
@@ -6,7 +6,6 @@ from django.contrib.comments.models import Comment
|
||||
from django.contrib.contenttypes import generic
|
||||
|
||||
from navigation.api import register_links, register_model_list_columns
|
||||
from permissions.models import PermissionNamespace, Permission
|
||||
from common.utils import encapsulate
|
||||
from acls.api import class_permissions
|
||||
from documents.models import Document
|
||||
|
||||
@@ -6,16 +6,16 @@ from .conf.settings import SUFFIX_SEPARATOR
|
||||
|
||||
|
||||
def assemble_suffixed_filename(filename, suffix=0):
|
||||
'''
|
||||
"""
|
||||
Split document filename, to attach suffix to the name part then
|
||||
re attacht the extension
|
||||
'''
|
||||
"""
|
||||
|
||||
if suffix:
|
||||
name, extension = filename.split(os.split(os.extsep))
|
||||
return SUFFIX_SEPARATOR.join([name, unicode(suffix), os.extsep, extension])
|
||||
else:
|
||||
return file_filename
|
||||
return filename
|
||||
|
||||
|
||||
def assemble_path_from_list(directory_list):
|
||||
|
||||
@@ -59,7 +59,7 @@ def index_instance_list(request, index_id=None):
|
||||
},
|
||||
{
|
||||
'name': _(u'items'),
|
||||
'attribute': encapsulate(lambda x: x.documents.count() if x.index.link_documents else x.get_children().count() )
|
||||
'attribute': encapsulate(lambda x: x.documents.count() if x.index.link_documents else x.get_children().count())
|
||||
}
|
||||
],
|
||||
'title': title,
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -5,12 +5,10 @@ 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.conf.settings import DEFAULT_PAPER_SIZE, DEFAULT_PAGE_ORIENTATION
|
||||
from common.widgets import TextAreaDiv
|
||||
|
||||
from .models import (Document, DocumentType,
|
||||
@@ -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:
|
||||
@@ -197,7 +196,7 @@ class DocumentForm(forms.ModelForm):
|
||||
label=_(u'Release level serial'),
|
||||
initial=0,
|
||||
widget=forms.widgets.TextInput(
|
||||
attrs = {'style': 'width: auto;'}
|
||||
attrs={'style': 'width: auto;'}
|
||||
),
|
||||
)
|
||||
|
||||
@@ -223,6 +222,7 @@ class DocumentForm(forms.ModelForm):
|
||||
# Always return the full collection of cleaned data.
|
||||
return cleaned_data
|
||||
|
||||
|
||||
class DocumentForm_edit(DocumentForm):
|
||||
"""
|
||||
Form sub classes from DocumentForm used only when editing a document
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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'))
|
||||
@@ -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
|
||||
latest version file exists in storage
|
||||
'''
|
||||
"""
|
||||
return self.latest_version.exists()
|
||||
|
||||
# Compatibility methods
|
||||
@@ -275,9 +275,9 @@ class Document(models.Model):
|
||||
|
||||
|
||||
class DocumentVersion(models.Model):
|
||||
'''
|
||||
"""
|
||||
Model that describes a document version and its properties
|
||||
'''
|
||||
"""
|
||||
_pre_open_hooks = {}
|
||||
_post_save_hooks = {}
|
||||
|
||||
@@ -344,9 +344,9 @@ class DocumentVersion(models.Model):
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -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)
|
||||
@@ -470,17 +470,17 @@ class DocumentVersion(models.Model):
|
||||
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:
|
||||
@@ -491,10 +491,10 @@ class DocumentVersion(models.Model):
|
||||
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:
|
||||
@@ -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,9 +535,9 @@ 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'))
|
||||
|
||||
|
||||
@@ -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,8 +18,8 @@ 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)
|
||||
@@ -82,6 +81,5 @@ class DocumentTestCase(unittest.TestCase):
|
||||
self.failUnlessEqual(self.document.has_detached_signature(), True)
|
||||
self.failUnlessEqual(self.document.verify_signature().status, SIGNATURE_STATE_VALID)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
self.document.delete()
|
||||
|
||||
@@ -386,6 +386,7 @@ 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)
|
||||
|
||||
@@ -394,7 +395,6 @@ def document_page_transformation_list(request, document_page_id):
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_DOCUMENT_TRANSFORM, request.user, document_page.document)
|
||||
|
||||
|
||||
return object_list(
|
||||
request,
|
||||
queryset=document_page.documentpagetransformation_set.all(),
|
||||
|
||||
@@ -6,13 +6,10 @@ 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):
|
||||
return document_html_widget(document, click_view='document_preview')
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.shortcuts import get_object_or_404, render_to_response
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import RequestContext
|
||||
|
||||
from common.utils import generate_choices_w_labels, encapsulate
|
||||
from common.utils import encapsulate
|
||||
from common.widgets import two_state_template
|
||||
from documents.models import Document
|
||||
from documents.views import document_list
|
||||
|
||||
@@ -3,7 +3,6 @@ from __future__ import absolute_import
|
||||
import logging
|
||||
import datetime
|
||||
|
||||
from django.db.utils import DatabaseError
|
||||
from django.db.utils import IntegrityError
|
||||
from django.db import transaction
|
||||
from django.db import models
|
||||
|
||||
@@ -21,7 +21,7 @@ class Lock(models.Model):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.creation_datetime = datetime.datetime.now()
|
||||
if not self.timeout and not kwarget.get('timeout'):
|
||||
if not self.timeout and not kwargs.get('timeout'):
|
||||
self.timeout = DEFAULT_LOCK_TIMEOUT
|
||||
|
||||
super(Lock, self).save(*args, **kwargs)
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import copy
|
||||
|
||||
object_navigation = {}
|
||||
multi_object_navigation = {}
|
||||
model_list_columns = {}
|
||||
|
||||
@@ -8,13 +8,11 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template.defaultfilters import capfirst
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.template import RequestContext
|
||||
from django.template import (TemplateSyntaxError, Library,
|
||||
VariableDoesNotExist, Node, Variable)
|
||||
from django.template import RequestContext, Variable
|
||||
|
||||
from permissions.models import Permission
|
||||
|
||||
from .templatetags.navigation_tags import resolve_links, _get_object_navigation_links
|
||||
from .templatetags.navigation_tags import resolve_links
|
||||
from .utils import resolve_to_name
|
||||
|
||||
|
||||
@@ -28,6 +26,7 @@ def button_navigation_widget(request, link):
|
||||
else:
|
||||
return render_widget(request, link)
|
||||
|
||||
|
||||
def render_widget(request, link):
|
||||
context = RequestContext(request)
|
||||
|
||||
|
||||
@@ -2,15 +2,11 @@ from __future__ import absolute_import
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from navigation.api import register_links, \
|
||||
register_model_list_columns
|
||||
from permissions.models import Permission, PermissionNamespace
|
||||
from navigation.api import (register_links,
|
||||
register_model_list_columns)
|
||||
from common.utils import encapsulate
|
||||
from project_setup.api import register_setup
|
||||
from documents.models import Document
|
||||
from documents.permissions import (PERMISSION_DOCUMENT_CREATE,
|
||||
PERMISSION_DOCUMENT_NEW_VERSION)
|
||||
from acls.api import class_permissions
|
||||
from documents.permissions import PERMISSION_DOCUMENT_NEW_VERSION
|
||||
|
||||
from .staging import StagingFile
|
||||
from .models import (WebForm, StagingFolder, SourceTransformation,
|
||||
|
||||
@@ -26,7 +26,7 @@ from sources.literals import (SOURCE_CHOICE_WEB_FORM, SOURCE_CHOICE_STAGING,
|
||||
SOURCE_CHOICE_WATCH)
|
||||
from sources.literals import (SOURCE_UNCOMPRESS_CHOICE_Y,
|
||||
SOURCE_UNCOMPRESS_CHOICE_ASK)
|
||||
from sources.staging import create_staging_file_class, StagingFile
|
||||
from sources.staging import create_staging_file_class
|
||||
from sources.forms import (StagingDocumentForm, WebFormForm,
|
||||
WatchFolderSetupForm)
|
||||
from sources.forms import WebFormSetupForm, StagingFolderSetupForm
|
||||
@@ -75,6 +75,7 @@ def get_active_tab_links(document=None):
|
||||
SOURCE_CHOICE_STAGING: staging_folders
|
||||
}
|
||||
|
||||
|
||||
def upload_interactive(request, source_type=None, source_id=None, document_pk=None):
|
||||
subtemplates_list = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user