PEP8 cleanups
This commit is contained in:
@@ -49,7 +49,7 @@ def rebuild_index_instances(request):
|
||||
'previous': previous,
|
||||
'next': next,
|
||||
'message': _(u'On large databases this operation may take some time to execute.'),
|
||||
'form_icon': u'folder_link.png',
|
||||
'form_icon': u'folder_link.png',
|
||||
}, context_instance=RequestContext(request))
|
||||
else:
|
||||
try:
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.conf import settings
|
||||
@@ -14,6 +13,7 @@ from common.conf.settings import DEFAULT_PAGE_ORIENTATION
|
||||
from documents.models import Document, DocumentType, \
|
||||
DocumentPage, DocumentPageTransformation
|
||||
|
||||
|
||||
# Document page forms
|
||||
class DocumentPageTransformationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
import tempfile
|
||||
|
||||
from django.db import models
|
||||
|
||||
@@ -17,8 +17,8 @@ from documents.conf.settings import STAGING_FILES_PREVIEW_SIZE
|
||||
from documents.conf.settings import USER_STAGING_DIRECTORY_ROOT
|
||||
from documents.conf.settings import USER_STAGING_DIRECTORY_EXPRESSION
|
||||
|
||||
from documents.literals import UPLOAD_SOURCE_LOCAL, \
|
||||
UPLOAD_SOURCE_STAGING, UPLOAD_SOURCE_USER_STAGING
|
||||
from documents.literals import UPLOAD_SOURCE_STAGING, \
|
||||
UPLOAD_SOURCE_USER_STAGING
|
||||
|
||||
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
|
||||
#TODO: Do benchmarks
|
||||
@@ -30,6 +30,7 @@ STAGING_FILE_FUNCTIONS = {
|
||||
UPLOAD_SOURCE_USER_STAGING: lambda x: os.path.join(USER_STAGING_DIRECTORY_ROOT, eval(USER_STAGING_DIRECTORY_EXPRESSION, {'user': x.user}))
|
||||
}
|
||||
|
||||
|
||||
def evaluate_user_staging_path(request, source):
|
||||
try:
|
||||
return STAGING_FILE_FUNCTIONS[source](request)
|
||||
@@ -43,17 +44,17 @@ def get_all_files(path):
|
||||
return sorted([os.path.normcase(f) for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))])
|
||||
except OSError, exc:
|
||||
raise OSError(ugettext(u'Unable get list of staging files: %s') % exc)
|
||||
|
||||
|
||||
|
||||
|
||||
def _return_new_class():
|
||||
return type('StagingFile', (StagingFile,), dict(StagingFile.__dict__))
|
||||
|
||||
|
||||
|
||||
|
||||
def create_staging_file_class(request, source):
|
||||
cls = _return_new_class()
|
||||
cls.set_path(evaluate_user_staging_path(request, source))
|
||||
return cls
|
||||
|
||||
|
||||
|
||||
class StagingFile(object):
|
||||
"""
|
||||
@@ -64,8 +65,8 @@ class StagingFile(object):
|
||||
|
||||
@classmethod
|
||||
def set_path(cls, path):
|
||||
cls.path = path
|
||||
|
||||
cls.path = path
|
||||
|
||||
@classmethod
|
||||
def get_all(cls):
|
||||
staging_files = []
|
||||
|
||||
@@ -72,11 +72,11 @@ from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
|
||||
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
|
||||
from documents.literals import UPLOAD_SOURCE_LOCAL, \
|
||||
UPLOAD_SOURCE_STAGING, UPLOAD_SOURCE_USER_STAGING
|
||||
|
||||
|
||||
|
||||
def document_list(request, object_list=None, title=None, extra_context=None):
|
||||
check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
|
||||
|
||||
|
||||
context = {
|
||||
'object_list': object_list if not (object_list is None) else Document.objects.only('file_filename', 'file_extension').all(),
|
||||
'title': title if title else _(u'documents'),
|
||||
@@ -85,7 +85,7 @@ def document_list(request, object_list=None, title=None, extra_context=None):
|
||||
}
|
||||
if extra_context:
|
||||
context.update(extra_context)
|
||||
|
||||
|
||||
return render_to_response('generic_list.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -155,7 +155,7 @@ def _handle_zip_file(request, uploaded_file, document_type=None):
|
||||
|
||||
def upload_document_with_type(request, source):
|
||||
check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
|
||||
|
||||
|
||||
document_type_id = request.GET.get('document_type_id', None)
|
||||
if document_type_id:
|
||||
document_type = get_object_or_404(DocumentType, pk=document_type_id[0])
|
||||
@@ -187,7 +187,7 @@ def upload_document_with_type(request, source):
|
||||
if (not UNCOMPRESS_COMPRESSED_STAGING_FILES) or (UNCOMPRESS_COMPRESSED_STAGING_FILES and not _handle_zip_file(request, staging_file.upload(), document_type)):
|
||||
document = Document(file=staging_file.upload())
|
||||
if document_type:
|
||||
document.document_type=document_type
|
||||
document.document_type = document_type
|
||||
document.save()
|
||||
_handle_save_document(request, document, form)
|
||||
messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename)
|
||||
@@ -206,7 +206,6 @@ def upload_document_with_type(request, source):
|
||||
StagingFile = create_staging_file_class(request, source)
|
||||
form = StagingDocumentForm(cls=StagingFile,
|
||||
initial={'document_type': document_type})
|
||||
|
||||
|
||||
subtemplates_list = []
|
||||
|
||||
@@ -386,7 +385,7 @@ def document_view_advanced(request, document_id):
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
subtemplates_list.append(
|
||||
{
|
||||
'name': 'generic_form_subtemplate.html',
|
||||
@@ -776,7 +775,7 @@ def _find_duplicate_list(request, source_document_list=Document.objects.all(), i
|
||||
return render_to_response('generic_confirm.html', {
|
||||
'previous': previous,
|
||||
'message': _(u'On large databases this operation may take some time to execute.'),
|
||||
'form_icon': u'page_refresh.png',
|
||||
'form_icon': u'page_refresh.png',
|
||||
}, context_instance=RequestContext(request))
|
||||
else:
|
||||
duplicated = []
|
||||
|
||||
@@ -12,5 +12,5 @@ class DocumentGroupItemInline(admin.StackedInline):
|
||||
|
||||
class DocumentGroupAdmin(admin.ModelAdmin):
|
||||
inlines = [DocumentGroupItemInline]
|
||||
|
||||
|
||||
admin.site.register(DocumentGroup, DocumentGroupAdmin)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.contrib import messages
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from documents.models import Document
|
||||
from documents.views import document_list
|
||||
@@ -26,7 +25,7 @@ def document_group_view(request, document_id, document_group_id):
|
||||
object_list, errors = DocumentGroup.objects.get_groups_for(document, document_group)
|
||||
|
||||
return document_list(
|
||||
request,
|
||||
request,
|
||||
title=_(u'documents in group: %(group)s') % {
|
||||
'group': object_list['title']
|
||||
},
|
||||
|
||||
@@ -81,4 +81,3 @@ class MetadataSelectionForm(forms.Form):
|
||||
)
|
||||
|
||||
MetadataRemoveFormSet = formset_factory(MetadataRemoveForm, extra=0)
|
||||
|
||||
|
||||
@@ -2,7 +2,12 @@ from django.db import models
|
||||
|
||||
from ocr.exceptions import AlreadyQueued
|
||||
|
||||
|
||||
class DocumentQueueManager(models.Manager):
|
||||
"""
|
||||
Module manager class to handle adding documents to an OCR document
|
||||
queue
|
||||
"""
|
||||
def queue_document(self, document, queue_name='default'):
|
||||
document_queue = self.model.objects.get(name=queue_name)
|
||||
if document_queue.queuedocument_set.filter(document=document):
|
||||
|
||||
@@ -8,12 +8,12 @@ from navigation.api import register_links
|
||||
from permissions.conf.settings import DEFAULT_ROLES
|
||||
from permissions.models import Role
|
||||
|
||||
PERMISSION_ROLE_VIEW = {'namespace': 'permissions', 'name': 'role_view', 'label':_(u'View roles')}
|
||||
PERMISSION_ROLE_EDIT = {'namespace': 'permissions', 'name': 'role_edit', 'label':_(u'Edit roles')}
|
||||
PERMISSION_ROLE_CREATE = {'namespace': 'permissions', 'name': 'role_create', 'label':_(u'Create roles')}
|
||||
PERMISSION_ROLE_DELETE = {'namespace': 'permissions', 'name': 'role_delete', 'label':_(u'Delete roles')}
|
||||
PERMISSION_PERMISSION_GRANT = {'namespace': 'permissions', 'name': 'permission_grant', 'label':_(u'Grant permissions')}
|
||||
PERMISSION_PERMISSION_REVOKE = {'namespace': 'permissions', 'name': 'permission_revoke', 'label':_(u'Revoke permissions')}
|
||||
PERMISSION_ROLE_VIEW = {'namespace': 'permissions', 'name': 'role_view', 'label': _(u'View roles')}
|
||||
PERMISSION_ROLE_EDIT = {'namespace': 'permissions', 'name': 'role_edit', 'label': _(u'Edit roles')}
|
||||
PERMISSION_ROLE_CREATE = {'namespace': 'permissions', 'name': 'role_create', 'label': _(u'Create roles')}
|
||||
PERMISSION_ROLE_DELETE = {'namespace': 'permissions', 'name': 'role_delete', 'label': _(u'Delete roles')}
|
||||
PERMISSION_PERMISSION_GRANT = {'namespace': 'permissions', 'name': 'permission_grant', 'label': _(u'Grant permissions')}
|
||||
PERMISSION_PERMISSION_REVOKE = {'namespace': 'permissions', 'name': 'permission_revoke', 'label': _(u'Revoke permissions')}
|
||||
|
||||
|
||||
role_list = {'text': _(u'roles'), 'view': 'role_list', 'famfam': 'medal_gold_1', 'permissions': [PERMISSION_ROLE_VIEW]}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from django.db.utils import DatabaseError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
@@ -31,7 +30,6 @@ def check_permissions(requester, permission_list):
|
||||
|
||||
raise PermissionDenied(ugettext(u'Insufficient permissions.'))
|
||||
|
||||
|
||||
register_permission(PERMISSION_ROLE_VIEW)
|
||||
register_permission(PERMISSION_ROLE_EDIT)
|
||||
register_permission(PERMISSION_ROLE_CREATE)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.forms import DetailForm
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ def remove_role_member(role, selection):
|
||||
model, pk = selection.split(u',')
|
||||
ct = ContentType.objects.get(model=model)
|
||||
member = RoleMember.objects.get(role=role, member_type=ct, member_id=pk)
|
||||
member.delete()
|
||||
member.delete()
|
||||
|
||||
|
||||
def role_members(request, role_id):
|
||||
|
||||
@@ -116,7 +116,7 @@ def tag_delete(request, tag_id=None, tag_id_list=None):
|
||||
'delete_view': True,
|
||||
'previous': previous,
|
||||
'next': next,
|
||||
'form_icon': u'tag_blue_delete.png',
|
||||
'form_icon': u'tag_blue_delete.png',
|
||||
}
|
||||
if len(tags) == 1:
|
||||
context['object'] = tags[0]
|
||||
|
||||
@@ -130,7 +130,7 @@ def user_delete(request, user_id=None, user_id_list=None):
|
||||
'delete_view': True,
|
||||
'previous': previous,
|
||||
'next': next,
|
||||
'form_icon': u'user_delete.png',
|
||||
'form_icon': u'user_delete.png',
|
||||
}
|
||||
if len(users) == 1:
|
||||
context['object'] = users[0]
|
||||
@@ -305,7 +305,7 @@ def group_delete(request, group_id=None, group_id_list=None):
|
||||
'delete_view': True,
|
||||
'previous': previous,
|
||||
'next': next,
|
||||
'form_icon': u'group_delete.png',
|
||||
'form_icon': u'group_delete.png',
|
||||
}
|
||||
if len(groups) == 1:
|
||||
context['object'] = groups[0]
|
||||
|
||||
Reference in New Issue
Block a user