PEP8 cleanups

This commit is contained in:
Roberto Rosario
2011-05-25 00:00:23 -04:00
parent 2721512514
commit 53cb857a8f
15 changed files with 37 additions and 38 deletions

View File

@@ -49,7 +49,7 @@ def rebuild_index_instances(request):
'previous': previous, 'previous': previous,
'next': next, 'next': next,
'message': _(u'On large databases this operation may take some time to execute.'), '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)) }, context_instance=RequestContext(request))
else: else:
try: try:

View File

@@ -1,7 +1,6 @@
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext from django.utils.translation import ugettext
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.conf import settings from django.conf import settings
@@ -14,6 +13,7 @@ from common.conf.settings import DEFAULT_PAGE_ORIENTATION
from documents.models import Document, DocumentType, \ from documents.models import Document, DocumentType, \
DocumentPage, DocumentPageTransformation DocumentPage, DocumentPageTransformation
# Document page forms # Document page forms
class DocumentPageTransformationForm(forms.ModelForm): class DocumentPageTransformationForm(forms.ModelForm):
class Meta: class Meta:

View File

@@ -1,5 +1,4 @@
import os import os
from datetime import datetime
import tempfile import tempfile
from django.db import models from django.db import models

View File

@@ -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_ROOT
from documents.conf.settings import USER_STAGING_DIRECTORY_EXPRESSION from documents.conf.settings import USER_STAGING_DIRECTORY_EXPRESSION
from documents.literals import UPLOAD_SOURCE_LOCAL, \ from documents.literals import UPLOAD_SOURCE_STAGING, \
UPLOAD_SOURCE_STAGING, UPLOAD_SOURCE_USER_STAGING UPLOAD_SOURCE_USER_STAGING
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest() HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
#TODO: Do benchmarks #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})) 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): def evaluate_user_staging_path(request, source):
try: try:
return STAGING_FILE_FUNCTIONS[source](request) 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))]) return sorted([os.path.normcase(f) for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))])
except OSError, exc: except OSError, exc:
raise OSError(ugettext(u'Unable get list of staging files: %s') % exc) raise OSError(ugettext(u'Unable get list of staging files: %s') % exc)
def _return_new_class(): def _return_new_class():
return type('StagingFile', (StagingFile,), dict(StagingFile.__dict__)) return type('StagingFile', (StagingFile,), dict(StagingFile.__dict__))
def create_staging_file_class(request, source): def create_staging_file_class(request, source):
cls = _return_new_class() cls = _return_new_class()
cls.set_path(evaluate_user_staging_path(request, source)) cls.set_path(evaluate_user_staging_path(request, source))
return cls return cls
class StagingFile(object): class StagingFile(object):
""" """
@@ -64,8 +65,8 @@ class StagingFile(object):
@classmethod @classmethod
def set_path(cls, path): def set_path(cls, path):
cls.path = path cls.path = path
@classmethod @classmethod
def get_all(cls): def get_all(cls):
staging_files = [] staging_files = []

View File

@@ -72,11 +72,11 @@ from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
from documents.literals import UPLOAD_SOURCE_LOCAL, \ from documents.literals import UPLOAD_SOURCE_LOCAL, \
UPLOAD_SOURCE_STAGING, UPLOAD_SOURCE_USER_STAGING UPLOAD_SOURCE_STAGING, UPLOAD_SOURCE_USER_STAGING
def document_list(request, object_list=None, title=None, extra_context=None): def document_list(request, object_list=None, title=None, extra_context=None):
check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW])
context = { context = {
'object_list': object_list if not (object_list is None) else Document.objects.only('file_filename', 'file_extension').all(), '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'), '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: if extra_context:
context.update(extra_context) context.update(extra_context)
return render_to_response('generic_list.html', context, return render_to_response('generic_list.html', context,
context_instance=RequestContext(request)) 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): def upload_document_with_type(request, source):
check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE]) check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE])
document_type_id = request.GET.get('document_type_id', None) document_type_id = request.GET.get('document_type_id', None)
if document_type_id: if document_type_id:
document_type = get_object_or_404(DocumentType, pk=document_type_id[0]) 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)): 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()) document = Document(file=staging_file.upload())
if document_type: if document_type:
document.document_type=document_type document.document_type = document_type
document.save() document.save()
_handle_save_document(request, document, form) _handle_save_document(request, document, form)
messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename) 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) StagingFile = create_staging_file_class(request, source)
form = StagingDocumentForm(cls=StagingFile, form = StagingDocumentForm(cls=StagingFile,
initial={'document_type': document_type}) initial={'document_type': document_type})
subtemplates_list = [] subtemplates_list = []
@@ -386,7 +385,7 @@ def document_view_advanced(request, document_id):
}, },
} }
) )
subtemplates_list.append( subtemplates_list.append(
{ {
'name': 'generic_form_subtemplate.html', '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', { return render_to_response('generic_confirm.html', {
'previous': previous, 'previous': previous,
'message': _(u'On large databases this operation may take some time to execute.'), '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)) }, context_instance=RequestContext(request))
else: else:
duplicated = [] duplicated = []

View File

@@ -12,5 +12,5 @@ class DocumentGroupItemInline(admin.StackedInline):
class DocumentGroupAdmin(admin.ModelAdmin): class DocumentGroupAdmin(admin.ModelAdmin):
inlines = [DocumentGroupItemInline] inlines = [DocumentGroupItemInline]
admin.site.register(DocumentGroup, DocumentGroupAdmin) admin.site.register(DocumentGroup, DocumentGroupAdmin)

View File

@@ -1,8 +1,7 @@
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.contrib import messages from django.contrib import messages
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import get_object_or_404
from django.template import RequestContext
from documents.models import Document from documents.models import Document
from documents.views import document_list 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) object_list, errors = DocumentGroup.objects.get_groups_for(document, document_group)
return document_list( return document_list(
request, request,
title=_(u'documents in group: %(group)s') % { title=_(u'documents in group: %(group)s') % {
'group': object_list['title'] 'group': object_list['title']
}, },

View File

@@ -81,4 +81,3 @@ class MetadataSelectionForm(forms.Form):
) )
MetadataRemoveFormSet = formset_factory(MetadataRemoveForm, extra=0) MetadataRemoveFormSet = formset_factory(MetadataRemoveForm, extra=0)

View File

@@ -2,7 +2,12 @@ from django.db import models
from ocr.exceptions import AlreadyQueued from ocr.exceptions import AlreadyQueued
class DocumentQueueManager(models.Manager): class DocumentQueueManager(models.Manager):
"""
Module manager class to handle adding documents to an OCR document
queue
"""
def queue_document(self, document, queue_name='default'): def queue_document(self, document, queue_name='default'):
document_queue = self.model.objects.get(name=queue_name) document_queue = self.model.objects.get(name=queue_name)
if document_queue.queuedocument_set.filter(document=document): if document_queue.queuedocument_set.filter(document=document):

View File

@@ -8,12 +8,12 @@ from navigation.api import register_links
from permissions.conf.settings import DEFAULT_ROLES from permissions.conf.settings import DEFAULT_ROLES
from permissions.models import Role from permissions.models import Role
PERMISSION_ROLE_VIEW = {'namespace': 'permissions', 'name': 'role_view', 'label':_(u'View roles')} 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_EDIT = {'namespace': 'permissions', 'name': 'role_edit', 'label': _(u'Edit roles')}
PERMISSION_ROLE_CREATE = {'namespace': 'permissions', 'name': 'role_create', 'label':_(u'Create 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_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_GRANT = {'namespace': 'permissions', 'name': 'permission_grant', 'label': _(u'Grant permissions')}
PERMISSION_PERMISSION_REVOKE = {'namespace': 'permissions', 'name': 'permission_revoke', 'label':_(u'Revoke 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]} role_list = {'text': _(u'roles'), 'view': 'role_list', 'famfam': 'medal_gold_1', 'permissions': [PERMISSION_ROLE_VIEW]}

View File

@@ -1,6 +1,5 @@
from django.db.utils import DatabaseError from django.db.utils import DatabaseError
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext from django.utils.translation import ugettext
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
@@ -31,7 +30,6 @@ def check_permissions(requester, permission_list):
raise PermissionDenied(ugettext(u'Insufficient permissions.')) raise PermissionDenied(ugettext(u'Insufficient permissions.'))
register_permission(PERMISSION_ROLE_VIEW) register_permission(PERMISSION_ROLE_VIEW)
register_permission(PERMISSION_ROLE_EDIT) register_permission(PERMISSION_ROLE_EDIT)
register_permission(PERMISSION_ROLE_CREATE) register_permission(PERMISSION_ROLE_CREATE)

View File

@@ -1,5 +1,4 @@
from django import forms from django import forms
from django.utils.translation import ugettext_lazy as _
from common.forms import DetailForm from common.forms import DetailForm

View File

@@ -200,7 +200,7 @@ def remove_role_member(role, selection):
model, pk = selection.split(u',') model, pk = selection.split(u',')
ct = ContentType.objects.get(model=model) ct = ContentType.objects.get(model=model)
member = RoleMember.objects.get(role=role, member_type=ct, member_id=pk) member = RoleMember.objects.get(role=role, member_type=ct, member_id=pk)
member.delete() member.delete()
def role_members(request, role_id): def role_members(request, role_id):

View File

@@ -116,7 +116,7 @@ def tag_delete(request, tag_id=None, tag_id_list=None):
'delete_view': True, 'delete_view': True,
'previous': previous, 'previous': previous,
'next': next, 'next': next,
'form_icon': u'tag_blue_delete.png', 'form_icon': u'tag_blue_delete.png',
} }
if len(tags) == 1: if len(tags) == 1:
context['object'] = tags[0] context['object'] = tags[0]

View File

@@ -130,7 +130,7 @@ def user_delete(request, user_id=None, user_id_list=None):
'delete_view': True, 'delete_view': True,
'previous': previous, 'previous': previous,
'next': next, 'next': next,
'form_icon': u'user_delete.png', 'form_icon': u'user_delete.png',
} }
if len(users) == 1: if len(users) == 1:
context['object'] = users[0] context['object'] = users[0]
@@ -305,7 +305,7 @@ def group_delete(request, group_id=None, group_id_list=None):
'delete_view': True, 'delete_view': True,
'previous': previous, 'previous': previous,
'next': next, 'next': next,
'form_icon': u'group_delete.png', 'form_icon': u'group_delete.png',
} }
if len(groups) == 1: if len(groups) == 1:
context['object'] = groups[0] context['object'] = groups[0]