PEP8 cleanups
This commit is contained in:
@@ -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 = []
|
||||
|
||||
Reference in New Issue
Block a user