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
|
||||
|
||||
@@ -31,7 +31,7 @@ class EncapsulatedObject(object):
|
||||
if hasattr(value, 'contribute_to_class'):
|
||||
value.contribute_to_class(cls, name)
|
||||
else:
|
||||
setattr(cls, name, value)
|
||||
setattr(cls, name, value)
|
||||
|
||||
@classmethod
|
||||
def set_source_object_name(cls, new_name):
|
||||
@@ -39,8 +39,7 @@ 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,11 +14,12 @@ 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')
|
||||
)
|
||||
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
current_holders = kwargs.pop('current_holders', [])
|
||||
if current_holders:
|
||||
@@ -29,14 +30,14 @@ class HolderSelectionForm(forms.Form):
|
||||
users = set(User.objects.filter(is_active=True)) - set(staff_users) - set(super_users) - set(current_holders)
|
||||
roles = set(Role.objects.all()) - set(current_holders)
|
||||
groups = set(Group.objects.all()) - set(current_holders)
|
||||
|
||||
|
||||
non_holder_list = []
|
||||
if users:
|
||||
non_holder_list.append((_(u'Users'), _as_choice_list(list(users))))
|
||||
|
||||
|
||||
if groups:
|
||||
non_holder_list.append((_(u'Groups'), _as_choice_list(list(groups))))
|
||||
|
||||
|
||||
if roles:
|
||||
non_holder_list.append((_(u'Roles'), _as_choice_list(list(roles))))
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -28,5 +24,5 @@ def object_w_content_type_icon(obj):
|
||||
label = obj.get_full_name()
|
||||
else:
|
||||
label = unicode(obj)
|
||||
|
||||
|
||||
return mark_safe('%s<span>%s</span>' % (content_type_icon(content_type), capfirst(label)))
|
||||
|
||||
@@ -24,11 +24,11 @@ class CompressedFile(object):
|
||||
self._open(file_input)
|
||||
else:
|
||||
self._create()
|
||||
|
||||
|
||||
def _create(self):
|
||||
self.descriptor = StringIO()
|
||||
self.zf = zipfile.ZipFile(self.descriptor, mode='w')
|
||||
|
||||
|
||||
def _open(self, file_input):
|
||||
try:
|
||||
# Is it a file like object?
|
||||
@@ -37,7 +37,7 @@ class CompressedFile(object):
|
||||
# If not, try open it.
|
||||
self.descriptor = open(file_input, 'r+b')
|
||||
else:
|
||||
self.descriptor = file_input
|
||||
self.descriptor = file_input
|
||||
|
||||
try:
|
||||
test = zipfile.ZipFile(self.descriptor, mode='r')
|
||||
@@ -54,23 +54,23 @@ class CompressedFile(object):
|
||||
file_input.seek(0)
|
||||
except AttributeError:
|
||||
# If not, keep it
|
||||
self.zf.write(file_input, arcname=arcname, compress_type=COMPRESSION)
|
||||
self.zf.write(file_input, arcname=arcname, compress_type=COMPRESSION)
|
||||
else:
|
||||
self.zf.writestr(arcname, file_input.read())
|
||||
|
||||
def contents(self):
|
||||
return [filename for filename in self.zf.namelist() if not filename.endswith('/')]
|
||||
|
||||
|
||||
def get_content(self, filename):
|
||||
return self.zf.read(filename)
|
||||
|
||||
|
||||
def write(self, filename=None):
|
||||
# fix for Linux zip files read in Windows
|
||||
for file in self.zf.filelist:
|
||||
# fix for Linux zip files read in Windows
|
||||
for file in self.zf.filelist:
|
||||
file.create_system = 0
|
||||
|
||||
self.descriptor.seek(0)
|
||||
|
||||
|
||||
if filename:
|
||||
descriptor = open(filename, 'w')
|
||||
descriptor.write(self.descriptor.read())
|
||||
|
||||
@@ -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'}
|
||||
)
|
||||
|
||||
@@ -34,14 +34,14 @@ class AnonymousUserSingletonManager(SingletonManager):
|
||||
return self.model.objects.get()
|
||||
else:
|
||||
return user
|
||||
|
||||
|
||||
|
||||
class AnonymousUserSingleton(Singleton):
|
||||
objects = AnonymousUserSingletonManager()
|
||||
|
||||
def __unicode__(self):
|
||||
return ugettext('Anonymous user')
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _(u'anonymous user')
|
||||
verbose_name_plural = _(u'anonymous user')
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from django import template
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
|
||||
class SetVarNode(template.Node):
|
||||
def __init__(self, var_name, var_value):
|
||||
self.var_name = var_name
|
||||
self.var_value = var_value
|
||||
|
||||
|
||||
def render(self, context):
|
||||
try:
|
||||
value = template.Variable(self.var_value).resolve(context)
|
||||
@@ -17,7 +18,8 @@ class SetVarNode(template.Node):
|
||||
context.dicts[0][self.var_name] = value
|
||||
|
||||
return u""
|
||||
|
||||
|
||||
|
||||
def set_var(parser, token):
|
||||
"""
|
||||
{% set <var_name> = <var_value> %}
|
||||
@@ -26,5 +28,5 @@ def set_var(parser, token):
|
||||
if len(parts) < 4:
|
||||
raise template.TemplateSyntaxError("'set' tag must be of the form: {% set <var_name> = <var_value> %}")
|
||||
return SetVarNode(parts[1], parts[3])
|
||||
|
||||
|
||||
register.tag('set', set_var)
|
||||
|
||||
@@ -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 = [
|
||||
@@ -330,7 +330,7 @@ def generate_choices_w_labels(choices, display_object_type=True):
|
||||
return sorted(results, key=lambda x: x[1])
|
||||
|
||||
|
||||
def get_object_name(obj, display_object_type=True):
|
||||
def get_object_name(obj, display_object_type=True):
|
||||
ct_label = ContentType.objects.get_for_model(obj).name
|
||||
if isinstance(obj, User):
|
||||
label = obj.get_full_name() if obj.get_full_name() else obj
|
||||
@@ -342,7 +342,7 @@ def get_object_name(obj, display_object_type=True):
|
||||
verbose_name = unicode(obj._meta.verbose_name)
|
||||
except AttributeError:
|
||||
verbose_name = ct_label
|
||||
|
||||
|
||||
return u'%s: %s' % (verbose_name, label)
|
||||
else:
|
||||
return u'%s' % (label)
|
||||
|
||||
@@ -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', '/')))
|
||||
|
||||
@@ -83,7 +83,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
flat_list.extend(group[1])
|
||||
else:
|
||||
flat_list = left_list()
|
||||
|
||||
|
||||
label = dict(flat_list)[selection]
|
||||
if decode_content_type:
|
||||
selection_obj = get_obj_from_content_type_string(selection)
|
||||
@@ -109,7 +109,7 @@ def assign_remove(request, left_list, right_list, add_method, remove_method, lef
|
||||
flat_list.extend(group[1])
|
||||
else:
|
||||
flat_list = right_list()
|
||||
|
||||
|
||||
label = dict(flat_list)[selection]
|
||||
if decode_content_type:
|
||||
selection = get_obj_from_content_type_string(selection)
|
||||
@@ -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,15 +199,15 @@ def current_user_edit(request):
|
||||
|
||||
|
||||
def login_view(request):
|
||||
'''
|
||||
Control how the use is to be authenticated, options are 'email' and
|
||||
"""
|
||||
Control how the use is to be authenticated, options are 'email' and
|
||||
'username'
|
||||
'''
|
||||
"""
|
||||
kwargs = {'template_name': 'login.html'}
|
||||
|
||||
|
||||
if LOGIN_METHOD == 'email':
|
||||
kwargs['authentication_form'] = EmailAuthenticationForm
|
||||
|
||||
|
||||
if not request.user.is_authenticated():
|
||||
context = {'web_theme_view_type': 'plain'}
|
||||
else:
|
||||
@@ -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,11 +74,11 @@ 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.
|
||||
default_attrs = {'class': 'text_area_div'}
|
||||
@@ -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
|
||||
"""
|
||||
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 = []
|
||||
@@ -142,5 +142,5 @@ class ScrollableCheckboxSelectMultiple(forms.widgets.CheckboxSelectMultiple):
|
||||
option_label = conditional_escape(force_unicode(option_label))
|
||||
output.append(u'<li><label%s>%s %s</label></li>' % (label_for, rendered_cb, option_label))
|
||||
output.append(u'</ul>')
|
||||
|
||||
|
||||
return mark_safe(u'<div class="text_area_div">%s</div>' % u'\n'.join(output))
|
||||
|
||||
@@ -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,20 +52,20 @@ 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)
|
||||
|
||||
def render(self, form, request, step, context=None):
|
||||
|
||||
@@ -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
|
||||
@@ -70,7 +68,7 @@ SIGNATURE_STATES = {
|
||||
'text': _(u'Document is signed with a valid signature.'),
|
||||
'icon': 'document_signature.png'
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Key(object):
|
||||
@@ -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,17 +1,16 @@
|
||||
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):
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
return acl_list_for(
|
||||
request,
|
||||
document,
|
||||
extra_context={
|
||||
'object': document,
|
||||
}
|
||||
)
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
return acl_list_for(
|
||||
request,
|
||||
document,
|
||||
extra_context={
|
||||
'object': document,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
@@ -16,7 +15,7 @@ if 'django.contrib.comments' not in settings.INSTALLED_APPS:
|
||||
|
||||
from .permissions import (PERMISSION_COMMENT_CREATE,
|
||||
PERMISSION_COMMENT_DELETE, PERMISSION_COMMENT_VIEW)
|
||||
|
||||
|
||||
comment_delete = {'text': _('delete'), 'view': 'comment_delete', 'args': 'object.pk', 'famfam': 'comment_delete', 'permissions': [PERMISSION_COMMENT_DELETE]}
|
||||
comment_multiple_delete = {'text': _('delete'), 'view': 'comment_multiple_delete', 'args': 'object.pk', 'famfam': 'comments_delete', 'permissions': [PERMISSION_COMMENT_DELETE]}
|
||||
comment_add = {'text': _('add comment'), 'view': 'comment_add', 'args': 'object.pk', 'famfam': 'comment_add', 'permissions': [PERMISSION_COMMENT_CREATE]}
|
||||
|
||||
@@ -31,7 +31,7 @@ def comment_delete(request, comment_id=None, comment_id_list=None):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_COMMENT_DELETE])
|
||||
except PermissionDenied:
|
||||
comments = AccessEntry.objects.filter_objects_by_access(PERMISSION_COMMENT_DELETE, request.user, comments, related='content_object')
|
||||
|
||||
|
||||
if not comments:
|
||||
messages.error(request, _(u'Must provide at least one comment.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
@@ -81,7 +81,7 @@ def comment_add(request, document_id):
|
||||
Permission.objects.check_permissions(request.user, [PERMISSION_COMMENT_CREATE])
|
||||
except PermissionDenied:
|
||||
AccessEntry.objects.check_access(PERMISSION_COMMENT_CREATE, request.user, document)
|
||||
|
||||
|
||||
post_action_redirect = None
|
||||
|
||||
next = request.POST.get('next', request.GET.get('next', post_action_redirect if post_action_redirect else request.META.get('HTTP_REFERER', '/')))
|
||||
|
||||
@@ -40,7 +40,7 @@ def fs_create_document_link(index_instance, document, suffix=0):
|
||||
if FILESERVING_ENABLE:
|
||||
filename = assemble_suffixed_filename(document.file.name, suffix)
|
||||
filepath = assemble_path_from_list([FILESERVING_PATH, get_instance_path(index_instance), filename])
|
||||
|
||||
|
||||
try:
|
||||
os.symlink(document.file.path, filepath)
|
||||
except OSError, exc:
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -72,7 +72,7 @@ def document_post_save_hook(instance):
|
||||
if not instance.pk:
|
||||
document_signature, created = DocumentVersionSignature.objects.get_or_create(
|
||||
document_version=instance.latest_version,
|
||||
)
|
||||
)
|
||||
#DocumentVersionSignature.objects.update_signed_state(instance.document)
|
||||
|
||||
#@receiver(post_save, dispatch_uid='check_document_signature_state', sender=DocumentVersion)
|
||||
|
||||
@@ -43,7 +43,7 @@ class DocumentVersionSignatureManager(models.Manager):
|
||||
logger.debug('document: %s' % document)
|
||||
|
||||
document_signature = self.get_document_signature(document)
|
||||
|
||||
|
||||
return document_signature.has_embedded_signature
|
||||
|
||||
def detached_signature(self, document):
|
||||
|
||||
@@ -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>')
|
||||
|
||||
|
||||
@@ -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 = {}
|
||||
@@ -46,7 +44,7 @@ def register_links(src, links, menu_name=None, position=None):
|
||||
object_navigation[menu_name][src]['links'].extend(links)
|
||||
|
||||
|
||||
def register_top_menu(name, link, children_views=None,
|
||||
def register_top_menu(name, link, children_views=None,
|
||||
children_path_regex=None, children_view_regex=None,
|
||||
position=None):
|
||||
"""
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -27,7 +25,8 @@ def button_navigation_widget(request, link):
|
||||
return u''
|
||||
else:
|
||||
return render_widget(request, link)
|
||||
|
||||
|
||||
|
||||
def render_widget(request, link):
|
||||
context = RequestContext(request)
|
||||
|
||||
@@ -37,7 +36,7 @@ def render_widget(request, link):
|
||||
|
||||
query_string = urlparse.urlparse(request.get_full_path()).query or urlparse.urlparse(request.META.get('HTTP_REFERER', u'/')).query
|
||||
parsed_query_string = urlparse.parse_qs(query_string)
|
||||
|
||||
|
||||
links = resolve_links(context, [link], current_view, current_path, parsed_query_string)
|
||||
if links:
|
||||
link = links[0]
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -39,7 +39,7 @@ class StagingDocumentForm(DocumentForm):
|
||||
staging_list_index = self.fields.keyOrder.index('staging_file_id')
|
||||
staging_list = self.fields.keyOrder.pop(staging_list_index)
|
||||
self.fields.keyOrder.insert(0, staging_list)
|
||||
|
||||
|
||||
staging_file_id = forms.ChoiceField(label=_(u'Staging file'))
|
||||
|
||||
class Meta(DocumentForm.Meta):
|
||||
@@ -63,7 +63,7 @@ class WebFormForm(DocumentForm):
|
||||
# Move the file filed to the top
|
||||
self.fields.keyOrder.remove('file')
|
||||
self.fields.keyOrder.insert(0, 'file')
|
||||
|
||||
|
||||
def clean_file(self):
|
||||
data = self.cleaned_data['file']
|
||||
validate_whitelist_blacklist(data.name, self.source.whitelist.split(','), self.source.blacklist.split(','))
|
||||
|
||||
@@ -22,5 +22,5 @@ class SourceTransformationManager(models.Manager):
|
||||
)
|
||||
except (ValueError, SyntaxError), e:
|
||||
warnings.append(e)
|
||||
|
||||
|
||||
return transformations, warnings
|
||||
|
||||
@@ -9,7 +9,7 @@ from django.contrib.contenttypes import generic
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from converter.api import get_available_transformations_choices
|
||||
from converter.literals import DIMENSION_SEPARATOR
|
||||
from converter.literals import DIMENSION_SEPARATOR
|
||||
from documents.models import DocumentType, Document
|
||||
from documents.literals import HISTORY_DOCUMENT_CREATED
|
||||
from document_indexing.api import update_indexes
|
||||
@@ -33,7 +33,7 @@ class BaseModel(models.Model):
|
||||
whitelist = models.TextField(blank=True, verbose_name=_(u'whitelist'), editable=False)
|
||||
blacklist = models.TextField(blank=True, verbose_name=_(u'blacklist'), editable=False)
|
||||
#document_type = models.ForeignKey(DocumentType, blank=True, null=True, verbose_name=_(u'document type'), help_text=(u'Optional document type to be applied to documents uploaded from this source.'))
|
||||
|
||||
|
||||
@classmethod
|
||||
def class_fullname(cls):
|
||||
return unicode(dict(SOURCE_CHOICES).get(cls.source_type))
|
||||
@@ -44,10 +44,10 @@ class BaseModel(models.Model):
|
||||
|
||||
def __unicode__(self):
|
||||
return u'%s' % self.title
|
||||
|
||||
|
||||
def fullname(self):
|
||||
return u' '.join([self.class_fullname(), '"%s"' % self.title])
|
||||
|
||||
|
||||
def internal_name(self):
|
||||
return u'%s_%d' % (self.source_type, self.pk)
|
||||
|
||||
@@ -66,15 +66,15 @@ class BaseModel(models.Model):
|
||||
self.upload_single_file(file_object, filename, document_type, metadata_dict_list, user)
|
||||
else:
|
||||
self.upload_single_file(file_object, filename, use_file_name, document_type, metadata_dict_list, user, document, new_version_data)
|
||||
|
||||
|
||||
file_object.close()
|
||||
|
||||
|
||||
def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None):
|
||||
if not document:
|
||||
document = Document()
|
||||
if document_type:
|
||||
document.document_type = document_type
|
||||
document.save()
|
||||
document.save()
|
||||
|
||||
if metadata_dict_list:
|
||||
save_metadata_list(metadata_dict_list, document, create=True)
|
||||
@@ -93,7 +93,7 @@ class BaseModel(models.Model):
|
||||
|
||||
if not new_version_data:
|
||||
new_version_data = {}
|
||||
|
||||
|
||||
new_version = document.new_version(file=file_object, **new_version_data)
|
||||
if filename:
|
||||
new_version.filename = filename
|
||||
@@ -103,7 +103,7 @@ class BaseModel(models.Model):
|
||||
|
||||
new_version.apply_default_transformations(transformations)
|
||||
#TODO: new HISTORY for version updates
|
||||
|
||||
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
abstract = True
|
||||
@@ -120,12 +120,12 @@ class InteractiveBaseModel(BaseModel):
|
||||
class Meta(BaseModel.Meta):
|
||||
abstract = True
|
||||
|
||||
|
||||
|
||||
class StagingFolder(InteractiveBaseModel):
|
||||
is_interactive = True
|
||||
source_type = SOURCE_CHOICE_STAGING
|
||||
default_icon = SOURCE_ICON_DRIVE
|
||||
|
||||
|
||||
folder_path = models.CharField(max_length=255, verbose_name=_(u'folder path'), help_text=_(u'Server side filesystem path.'))
|
||||
preview_width = models.IntegerField(blank=True, null=True, verbose_name=_(u'preview width'), help_text=_(u'Width value to be passed to the converter backend.'))
|
||||
preview_height = models.IntegerField(blank=True, null=True, verbose_name=_(u'preview height'), help_text=_(u'Height value to be passed to the converter backend.'))
|
||||
@@ -173,16 +173,16 @@ class WebForm(InteractiveBaseModel):
|
||||
verbose_name = _(u'web form')
|
||||
verbose_name_plural = _(u'web forms')
|
||||
|
||||
|
||||
|
||||
class WatchFolder(BaseModel):
|
||||
is_interactive = False
|
||||
source_type = SOURCE_CHOICE_WATCH
|
||||
|
||||
|
||||
folder_path = models.CharField(max_length=255, verbose_name=_(u'folder path'), help_text=_(u'Server side filesystem path.'))
|
||||
uncompress = models.CharField(max_length=1, choices=SOURCE_UNCOMPRESS_CHOICES, verbose_name=_(u'uncompress'), help_text=_(u'Whether to expand or not compressed archives.'))
|
||||
delete_after_upload = models.BooleanField(default=True, verbose_name=_(u'delete after upload'), help_text=_(u'Delete the file after is has been successfully uploaded.'))
|
||||
interval = models.PositiveIntegerField(verbose_name=_(u'interval'), help_text=_(u'Inverval in seconds where the watch folder path is checked for new documents.'))
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.pk:
|
||||
remove_job(self.internal_name())
|
||||
@@ -191,11 +191,11 @@ class WatchFolder(BaseModel):
|
||||
|
||||
def schedule(self):
|
||||
if self.enabled:
|
||||
register_interval_job(self.internal_name(),
|
||||
title=self.fullname(), func=self.execute,
|
||||
register_interval_job(self.internal_name(),
|
||||
title=self.fullname(), func=self.execute,
|
||||
kwargs={'source_id': self.pk}, seconds=self.interval
|
||||
)
|
||||
|
||||
|
||||
def execute(self, source_id):
|
||||
source = WatchFolder.objects.get(pk=source_id)
|
||||
if source.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y:
|
||||
@@ -203,11 +203,11 @@ class WatchFolder(BaseModel):
|
||||
else:
|
||||
expand = False
|
||||
print 'execute: %s' % self.internal_name()
|
||||
|
||||
|
||||
class Meta(BaseModel.Meta):
|
||||
verbose_name = _(u'watch folder')
|
||||
verbose_name_plural = _(u'watch folders')
|
||||
|
||||
|
||||
|
||||
class ArgumentsValidator(object):
|
||||
message = _(u'Enter a valid value.')
|
||||
|
||||
@@ -9,28 +9,28 @@ def accept_item(value, whitelist, blacklist, default_accept=True):
|
||||
"""
|
||||
return true if this item is either whitelisted or
|
||||
not blacklisted
|
||||
"""
|
||||
"""
|
||||
if not whitelist:
|
||||
whitelist = []
|
||||
|
||||
|
||||
if not blacklist:
|
||||
blacklist = []
|
||||
|
||||
# note the order
|
||||
for reject, item_list in ([False, whitelist], [True, blacklist]):
|
||||
# note the order
|
||||
for reject, item_list in ([False, whitelist], [True, blacklist]):
|
||||
#print 'item_list: %s' % item_list
|
||||
#print 'reject: %s' % reject
|
||||
for okpattern in item_list:
|
||||
#print 'okpattern: %s' % okpattern
|
||||
if re.findall(okpattern.replace('*', '\S+'), value, re.I):
|
||||
# match!
|
||||
if re.findall(okpattern.replace('*', '\S+'), value, re.I):
|
||||
# match!
|
||||
#print 'MATCH'
|
||||
if reject:
|
||||
return False
|
||||
else:
|
||||
if reject:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
# default is to accept all
|
||||
# default is to accept all
|
||||
return default_accept
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -47,7 +47,7 @@ def get_tab_link_for_source(source, document=None):
|
||||
else:
|
||||
view = u'upload_interactive'
|
||||
args = [u'"%s"' % source.source_type, source.pk]
|
||||
|
||||
|
||||
return {
|
||||
'text': source.title,
|
||||
'view': view,
|
||||
@@ -55,19 +55,19 @@ def get_tab_link_for_source(source, document=None):
|
||||
'famfam': source.icon,
|
||||
'keep_query': True,
|
||||
'conditional_highlight': return_function(source),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_active_tab_links(document=None):
|
||||
tab_links = []
|
||||
|
||||
|
||||
web_forms = WebForm.objects.filter(enabled=True)
|
||||
for web_form in web_forms:
|
||||
tab_links.append(get_tab_link_for_source(web_form, document))
|
||||
|
||||
staging_folders = StagingFolder.objects.filter(enabled=True)
|
||||
for staging_folder in staging_folders:
|
||||
tab_links.append(get_tab_link_for_source(staging_folder, document))
|
||||
tab_links.append(get_tab_link_for_source(staging_folder, document))
|
||||
|
||||
return {
|
||||
'tab_links': tab_links,
|
||||
@@ -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