PEP8, pylint cleanups and removal of relative imports
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from re import compile
|
||||
import re
|
||||
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.conf import settings
|
||||
|
||||
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
|
||||
EXEMPT_URLS = [re.compile(settings.LOGIN_URL.lstrip('/'))]
|
||||
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
|
||||
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
|
||||
EXEMPT_URLS += [re.compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]
|
||||
|
||||
|
||||
class LoginRequiredMiddleware:
|
||||
|
||||
@@ -4,6 +4,6 @@ from django.utils.html import strip_spaces_between_tags as short
|
||||
|
||||
class SpacelessMiddleware(object):
|
||||
def process_response(self, request, response):
|
||||
if 'text/html' in response['Content-Type']:
|
||||
if u'text/html' in response['Content-Type']:
|
||||
response.content = short(response.content)
|
||||
return response
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
import types
|
||||
@@ -9,7 +9,7 @@ from django.utils.datastructures import MultiValueDict
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
def urlquote(link=None, get={}):
|
||||
def urlquote(link=None, get=None):
|
||||
u'''
|
||||
This method does both: urlquote() and urlencode()
|
||||
|
||||
@@ -26,6 +26,9 @@ def urlquote(link=None, get={}):
|
||||
urlquote('/mypath/', {'key': ['value1', 'value2']}) --> '/mypath/?key=value1&key=value2'
|
||||
urlquote({'key': ['value1', 'value2']}) --> 'key=value1&key=value2'
|
||||
'''
|
||||
if get is None:
|
||||
get = []
|
||||
|
||||
assert link or get
|
||||
if isinstance(link, dict):
|
||||
# urlqoute({'key': 'value', 'key2': 'value2'}) --> key=value&key2=value2
|
||||
@@ -48,7 +51,7 @@ def urlquote(link=None, get={}):
|
||||
return django_urlquote(link)
|
||||
|
||||
|
||||
def return_attrib(obj, attrib, arguments={}):
|
||||
def return_attrib(obj, attrib, arguments=None):
|
||||
try:
|
||||
if isinstance(attrib, types.FunctionType):
|
||||
return attrib(obj)
|
||||
|
||||
@@ -14,7 +14,7 @@ from django.utils.hashcompat import md5_constructor
|
||||
__all__ = ('security_hash', 'BoundFormWizard')
|
||||
|
||||
|
||||
def security_hash(request, form, exclude=None, *args):
|
||||
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
|
||||
@@ -60,7 +60,7 @@ class BoundFormWizard(FormWizard):
|
||||
Subclasses may want to take into account request-specific information,
|
||||
such as the IP address.
|
||||
"""
|
||||
return security_hash(request, form)
|
||||
return security_hash_new(form)
|
||||
|
||||
def render(self, form, request, step, context=None):
|
||||
"Renders the given Form object, returning an HttpResponse."
|
||||
|
||||
@@ -12,7 +12,7 @@ from converter.conf.settings import LOW_QUALITY_OPTIONS
|
||||
from converter.conf.settings import HIGH_QUALITY_OPTIONS
|
||||
from converter.conf.settings import GRAPHICS_BACKEND
|
||||
|
||||
from exceptions import UnpaperError
|
||||
from converter.exceptions import UnpaperError
|
||||
|
||||
#from converter.conf.settings import UNOCONV_PATH
|
||||
from common import TEMPORARY_DIRECTORY
|
||||
@@ -78,8 +78,8 @@ def execute_unoconv(input_filepath, output_filepath, arguments=''):
|
||||
"""
|
||||
|
||||
|
||||
def cache_cleanup(input_filepath, size, quality=QUALITY_DEFAULT, page=0, format=u'jpg', extra_options=u''):
|
||||
filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options)
|
||||
def cache_cleanup(input_filepath, size, quality=QUALITY_DEFAULT, page=0, file_format=u'jpg', extra_options=u''):
|
||||
filepath = create_image_cache_filename(input_filepath, size=size, page=page, file_format=file_format, quality=quality, extra_options=extra_options)
|
||||
try:
|
||||
os.remove(filepath)
|
||||
except OSError:
|
||||
@@ -102,17 +102,17 @@ def create_image_cache_filename(input_filepath, *args, **kwargs):
|
||||
return None
|
||||
|
||||
|
||||
def in_image_cache(input_filepath, size, page=0, format=u'jpg', quality=QUALITY_DEFAULT, extra_options=u'', zoom=100, rotation=0):
|
||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options, zoom=zoom, rotation=rotation)
|
||||
def in_image_cache(input_filepath, size, page=0, file_format=u'jpg', quality=QUALITY_DEFAULT, extra_options=u'', zoom=100, rotation=0):
|
||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, file_format=file_format, quality=quality, extra_options=extra_options, zoom=zoom, rotation=rotation)
|
||||
if os.path.exists(output_filepath):
|
||||
return output_filepath
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, format=u'jpg', extra_options=u'', mimetype=None, extension=None, cleanup_files=True, zoom=100, rotation=0):
|
||||
def convert(input_filepath, size, quality=QUALITY_DEFAULT, page=0, file_format=u'jpg', extra_options=u'', cleanup_files=True, zoom=100, rotation=0):
|
||||
unoconv_output = None
|
||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, format=format, quality=quality, extra_options=extra_options, zoom=zoom, rotation=rotation)
|
||||
output_filepath = create_image_cache_filename(input_filepath, size=size, page=page, file_format=file_format, quality=quality, extra_options=extra_options, zoom=zoom, rotation=rotation)
|
||||
if os.path.exists(output_filepath):
|
||||
return output_filepath
|
||||
'''
|
||||
@@ -138,7 +138,7 @@ def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, f
|
||||
if format == u'jpg':
|
||||
extra_options += u' -quality 85'
|
||||
|
||||
backend.execute_convert(input_filepath=input_arg, arguments=extra_options, output_filepath=u'%s:%s' % (format, output_filepath), quality=quality)
|
||||
backend.execute_convert(input_filepath=input_arg, arguments=extra_options, output_filepath=u'%s:%s' % (file_format, output_filepath), quality=quality)
|
||||
finally:
|
||||
if cleanup_files:
|
||||
cleanup(input_filepath)
|
||||
@@ -156,7 +156,7 @@ def get_page_count(input_filepath):
|
||||
return 1
|
||||
|
||||
|
||||
def convert_document_for_ocr(document, page=0, format='tif'):
|
||||
def convert_document_for_ocr(document, page=0, file_format=u'tif'):
|
||||
#Extract document file
|
||||
input_filepath = document_save_to_temp_dir(document, document.uuid)
|
||||
|
||||
@@ -166,7 +166,7 @@ def convert_document_for_ocr(document, page=0, format='tif'):
|
||||
transformation_output_file = u'%s_trans%s%s%s' % (temp_path, page, os.extsep, format)
|
||||
unpaper_input_file = u'%s_unpaper_in%s%spnm' % (temp_path, page, os.extsep)
|
||||
unpaper_output_file = u'%s_unpaper_out%s%spnm' % (temp_path, page, os.extsep)
|
||||
convert_output_file = u'%s_ocr%s%s%s' % (temp_path, page, os.extsep, format)
|
||||
convert_output_file = u'%s_ocr%s%s%s' % (temp_path, page, os.extsep, file_format)
|
||||
|
||||
input_arg = u'%s[%s]' % (input_filepath, page)
|
||||
|
||||
@@ -195,4 +195,5 @@ def convert_document_for_ocr(document, page=0, format='tif'):
|
||||
cleanup(transformation_output_file)
|
||||
cleanup(unpaper_input_file)
|
||||
cleanup(unpaper_output_file)
|
||||
|
||||
return convert_output_file
|
||||
|
||||
@@ -10,9 +10,9 @@ from common.conf import settings as common_settings
|
||||
from main.api import register_diagnostic
|
||||
from permissions.api import register_permissions
|
||||
|
||||
from models import Document, DocumentPage, DocumentPageTransformation
|
||||
from staging import StagingFile
|
||||
from conf.settings import ENABLE_SINGLE_DOCUMENT_UPLOAD
|
||||
from documents.models import Document, DocumentPage, DocumentPageTransformation
|
||||
from documents.staging import StagingFile
|
||||
from documents.conf.settings import ENABLE_SINGLE_DOCUMENT_UPLOAD
|
||||
|
||||
PERMISSION_DOCUMENT_CREATE = 'document_create'
|
||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT = 'document_properties_edit'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import MetadataType, DocumentType, Document, \
|
||||
from documents.models import MetadataType, DocumentType, Document, \
|
||||
DocumentTypeMetadataType, DocumentMetadata, DocumentTypeFilename, \
|
||||
MetadataIndex, DocumentPage, MetadataGroup, \
|
||||
MetadataGroupItem, DocumentPageTransformation, RecentDocument
|
||||
@@ -34,7 +34,10 @@ class DocumentTypeFilenameInline(admin.StackedInline):
|
||||
|
||||
|
||||
class DocumentTypeAdmin(admin.ModelAdmin):
|
||||
inlines = [DocumentTypeFilenameInline, DocumentTypeMetadataTypeInline, MetadataIndexInline]
|
||||
inlines = [
|
||||
DocumentTypeFilenameInline, DocumentTypeMetadataTypeInline,
|
||||
MetadataIndexInline
|
||||
]
|
||||
|
||||
|
||||
class DocumentMetadataInline(admin.StackedInline):
|
||||
@@ -56,8 +59,10 @@ class DocumentPageInline(admin.StackedInline):
|
||||
|
||||
|
||||
class DocumentAdmin(admin.ModelAdmin):
|
||||
inlines = [DocumentMetadataInline, DocumentMetadataIndexInline,
|
||||
DocumentPageInline]
|
||||
inlines = [
|
||||
DocumentMetadataInline, DocumentMetadataIndexInline,
|
||||
DocumentPageInline
|
||||
]
|
||||
list_display = ('uuid', 'file_filename', 'file_extension')
|
||||
|
||||
|
||||
@@ -85,5 +90,6 @@ admin.site.register(MetadataType, MetadataTypeAdmin)
|
||||
admin.site.register(DocumentType, DocumentTypeAdmin)
|
||||
admin.site.register(Document, DocumentAdmin)
|
||||
admin.site.register(MetadataGroup, MetadataGroupAdmin)
|
||||
admin.site.register(DocumentPageTransformation, DocumentPageTransformationAdmin)
|
||||
admin.site.register(DocumentPageTransformation,
|
||||
DocumentPageTransformationAdmin)
|
||||
admin.site.register(RecentDocument, RecentDocumentAdmin)
|
||||
|
||||
@@ -21,15 +21,15 @@ def default_uuid():
|
||||
return unicode(uuid.uuid4())
|
||||
|
||||
default_available_functions = {
|
||||
'current_date':datetime.datetime.now().date,
|
||||
'current_date': datetime.datetime.now().date,
|
||||
}
|
||||
|
||||
default_available_models = {
|
||||
'User':User
|
||||
'User': User
|
||||
}
|
||||
|
||||
available_transformations = {
|
||||
'rotate': {'label':_(u'Rotate [degrees]'), 'arguments':[{'name':'degrees'}]}
|
||||
'rotate': {'label': _(u'Rotate [degrees]'), 'arguments': [{'name': 'degrees'}]}
|
||||
}
|
||||
|
||||
available_indexing_functions = {
|
||||
|
||||
@@ -8,12 +8,12 @@ from django.utils.safestring import mark_safe
|
||||
from django.forms.formsets import formset_factory
|
||||
from django.template.defaultfilters import capfirst
|
||||
|
||||
from staging import StagingFile
|
||||
from documents.staging import StagingFile
|
||||
|
||||
from common.wizard import BoundFormWizard
|
||||
from common.forms import DetailForm
|
||||
|
||||
from models import Document, DocumentType, DocumentTypeMetadataType, \
|
||||
from documents.models import Document, DocumentType, DocumentTypeMetadataType, \
|
||||
DocumentPage, DocumentPageTransformation
|
||||
|
||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||
@@ -62,7 +62,9 @@ class DocumentPageForm(DetailForm):
|
||||
'rotation': rotation
|
||||
})
|
||||
|
||||
page_image = forms.CharField(label=_(u'Page image'), widget=DocumentPageImageWidget())
|
||||
page_image = forms.CharField(
|
||||
label=_(u'Page image'), widget=DocumentPageImageWidget()
|
||||
)
|
||||
|
||||
|
||||
class DocumentPageForm_text(DetailForm):
|
||||
@@ -72,7 +74,9 @@ class DocumentPageForm_text(DetailForm):
|
||||
|
||||
content = forms.CharField(
|
||||
label=_(u'Contents'),
|
||||
widget=forms.widgets.Textarea(attrs={'rows': 18, 'cols': 80, 'readonly': 'readonly'}))
|
||||
widget=forms.widgets.Textarea(attrs={
|
||||
'rows': 18, 'cols': 80, 'readonly': 'readonly'
|
||||
}))
|
||||
|
||||
|
||||
class DocumentPageForm_edit(forms.ModelForm):
|
||||
@@ -88,7 +92,9 @@ class DocumentPageForm_edit(forms.ModelForm):
|
||||
'page_label',
|
||||
'content',
|
||||
]
|
||||
page_image = forms.CharField(required=False, widget=DocumentPageImageWidget())
|
||||
page_image = forms.CharField(
|
||||
required=False, widget=DocumentPageImageWidget()
|
||||
)
|
||||
|
||||
|
||||
class ImageWidget(forms.widgets.Widget):
|
||||
@@ -145,7 +151,9 @@ class DocumentForm(forms.ModelForm):
|
||||
model = Document
|
||||
exclude = ('description',)
|
||||
|
||||
new_filename = forms.CharField(label=_('New document filename'), required=False)
|
||||
new_filename = forms.CharField(
|
||||
label=_('New document filename'), required=False
|
||||
)
|
||||
|
||||
|
||||
class DocumentPreviewForm(forms.Form):
|
||||
@@ -173,7 +181,9 @@ class DocumentContentForm(forms.Form):
|
||||
|
||||
contents = forms.CharField(
|
||||
label=_(u'Contents'),
|
||||
widget=forms.widgets.Textarea(attrs={'rows': 14, 'cols': 80, 'readonly': 'readonly'})
|
||||
widget=forms.widgets.Textarea(attrs={
|
||||
'rows': 14, 'cols': 80, 'readonly': 'readonly'
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -193,7 +203,9 @@ class StagingDocumentForm(forms.Form):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(StagingDocumentForm, self).__init__(*args, **kwargs)
|
||||
try:
|
||||
self.fields['staging_file_id'].choices = [(staging_file.id, staging_file) for staging_file in StagingFile.get_all()]
|
||||
self.fields['staging_file_id'].choices = [
|
||||
(staging_file.id, staging_file) for staging_file in StagingFile.get_all()
|
||||
]
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -207,7 +219,9 @@ class StagingDocumentForm(forms.Form):
|
||||
label=_(u'Quick document rename'))
|
||||
|
||||
staging_file_id = forms.ChoiceField(label=_(u'Staging file'))
|
||||
new_filename = forms.CharField(label=_('New document filename'), required=False)
|
||||
new_filename = forms.CharField(
|
||||
label=_('New document filename'), required=False
|
||||
)
|
||||
|
||||
|
||||
class DocumentTypeSelectForm(forms.Form):
|
||||
@@ -286,7 +300,9 @@ class DocumentCreateWizard(BoundFormWizard):
|
||||
|
||||
def render_template(self, request, form, previous_fields, step, context=None):
|
||||
context = {'step_title': self.extra_context['step_titles'][step]}
|
||||
return super(DocumentCreateWizard, self).render_template(request, form, previous_fields, step, context)
|
||||
return super(DocumentCreateWizard, self).render_template(
|
||||
request, form, previous_fields, step, context
|
||||
)
|
||||
|
||||
def parse_params(self, request, *args, **kwargs):
|
||||
self.extra_context = {'step_titles': self.step_titles}
|
||||
|
||||
@@ -6,8 +6,7 @@ from urllib import unquote_plus
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
|
||||
from models import DocumentMetadata, MetadataType
|
||||
from documents.models import DocumentMetadata, MetadataType
|
||||
|
||||
|
||||
def decode_metadata_from_url(url_dict):
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.db.models import Q
|
||||
@@ -81,7 +79,7 @@ class Document(models.Model):
|
||||
|
||||
@models.permalink
|
||||
def get_absolute_url(self):
|
||||
return ('document_view_simple', [self.id])
|
||||
return ('document_view_simple', [self.pk])
|
||||
|
||||
def get_fullname(self):
|
||||
return os.extsep.join([self.file_filename, self.file_extension])
|
||||
@@ -276,7 +274,7 @@ class DocumentPage(models.Model):
|
||||
|
||||
@models.permalink
|
||||
def get_absolute_url(self):
|
||||
return ('document_page_view', [self.id])
|
||||
return ('document_page_view', [self.pk])
|
||||
|
||||
|
||||
class MetadataGroupManager(models.Manager):
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from common.utils import pretty_size, pretty_size_10
|
||||
from permissions.api import check_permissions
|
||||
|
||||
from documents.conf.settings import STORAGE_BACKEND
|
||||
from models import Document, DocumentType, DocumentPage
|
||||
from documents.models import Document, DocumentType, DocumentPage
|
||||
|
||||
|
||||
def get_used_size(path, file_list):
|
||||
@@ -17,6 +16,7 @@ def get_used_size(path, file_list):
|
||||
|
||||
return total_size
|
||||
|
||||
|
||||
def storage_count(path=u'.'):
|
||||
directories, files = STORAGE_BACKEND().listdir(path)
|
||||
total_count = len(files)
|
||||
@@ -31,31 +31,30 @@ def storage_count(path=u'.'):
|
||||
|
||||
|
||||
def get_statistics():
|
||||
total_db_documents = Document.objects.only('id',).count()
|
||||
total_db_documents = Document.objects.only('pk',).count()
|
||||
|
||||
paragraphs = [
|
||||
_(u'Document types: %d') % DocumentType.objects.count(),
|
||||
_(u'Documents in database: %d') % total_db_documents,
|
||||
]
|
||||
|
||||
|
||||
try:
|
||||
total_storage_documents, storage_used_space = storage_count()
|
||||
paragraphs.append(_(u'Documents in storage: %d') %
|
||||
total_storage_documents)
|
||||
paragraphs.append(_(u'Space used in storage: %(base_2)s (base 2), %(base_10)s (base 10), %(bytes)d bytes') % {
|
||||
'base_2':pretty_size(storage_used_space),
|
||||
'base_10':pretty_size_10(storage_used_space),
|
||||
'bytes':storage_used_space
|
||||
'base_2': pretty_size(storage_used_space),
|
||||
'base_10': pretty_size_10(storage_used_space),
|
||||
'bytes': storage_used_space
|
||||
})
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
||||
paragraphs.append(
|
||||
_(u'Document pages in database: %d') % DocumentPage.objects.only('id',).count(),
|
||||
_(u'Document pages in database: %d') % DocumentPage.objects.only('pk',).count(),
|
||||
)
|
||||
|
||||
return {
|
||||
'title':_(u'Document statistics'),
|
||||
'title': _(u'Document statistics'),
|
||||
'paragraphs': paragraphs
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic.create_update import create_object, update_object
|
||||
|
||||
from documents.conf.settings import PREVIEW_SIZE
|
||||
from documents.conf.settings import THUMBNAIL_SIZE
|
||||
@@ -10,7 +8,6 @@ from documents.conf.settings import ENABLE_SINGLE_DOCUMENT_UPLOAD
|
||||
|
||||
from converter.api import QUALITY_HIGH
|
||||
|
||||
|
||||
urlpatterns = patterns('documents.views',
|
||||
url(r'^document/list/$', 'document_list', (), 'document_list'),
|
||||
url(r'^document/list/recent/$', 'document_list_recent', (), 'document_list_recent'),
|
||||
|
||||
@@ -3,14 +3,13 @@ import urlparse
|
||||
import urllib
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
from django.views.generic.list_detail import object_detail, object_list
|
||||
from django.views.generic.list_detail import object_list
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.generic.create_update import create_object, delete_object, update_object
|
||||
from django.core.files.base import File
|
||||
from django.views.generic.create_update import delete_object, update_object
|
||||
from django.conf import settings
|
||||
from django.utils.http import urlencode
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
@@ -31,9 +30,7 @@ from documents.conf.settings import DELETE_STAGING_FILE_AFTER_UPLOAD
|
||||
from documents.conf.settings import USE_STAGING_DIRECTORY
|
||||
from documents.conf.settings import PREVIEW_SIZE
|
||||
from documents.conf.settings import THUMBNAIL_SIZE
|
||||
from documents.conf.settings import GROUP_MAX_RESULTS
|
||||
from documents.conf.settings import GROUP_SHOW_EMPTY
|
||||
from documents.conf.settings import DEFAULT_TRANSFORMATIONS
|
||||
from documents.conf.settings import UNCOMPRESS_COMPRESSED_LOCAL_FILES
|
||||
from documents.conf.settings import UNCOMPRESS_COMPRESSED_STAGING_FILES
|
||||
from documents.conf.settings import STORAGE_BACKEND
|
||||
@@ -46,23 +43,22 @@ from documents import PERMISSION_DOCUMENT_CREATE, \
|
||||
PERMISSION_DOCUMENT_CREATE, PERMISSION_DOCUMENT_PROPERTIES_EDIT, \
|
||||
PERMISSION_DOCUMENT_METADATA_EDIT, PERMISSION_DOCUMENT_VIEW, \
|
||||
PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD, \
|
||||
PERMISSION_DOCUMENT_TRANSFORM, PERMISSION_DOCUMENT_TOOLS, \
|
||||
PERMISSION_DOCUMENT_TRANSFORM, \
|
||||
PERMISSION_DOCUMENT_EDIT
|
||||
|
||||
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
||||
MetadataForm, DocumentForm, DocumentForm_edit, DocumentForm_view, \
|
||||
from documents.forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
||||
DocumentForm, DocumentForm_edit, DocumentForm_view, \
|
||||
StagingDocumentForm, DocumentTypeMetadataType, DocumentPreviewForm, \
|
||||
MetadataFormSet, DocumentPageForm, DocumentPageTransformationForm, \
|
||||
DocumentContentForm, DocumentPageForm_edit, MetaDataGroupForm, \
|
||||
DocumentPageForm_text
|
||||
|
||||
from metadata import save_metadata_list, \
|
||||
from documents.metadata import save_metadata_list, \
|
||||
decode_metadata_from_url, metadata_repr_as_list
|
||||
from models import Document, DocumentMetadata, DocumentType, MetadataType, \
|
||||
DocumentPage, DocumentPageTransformation, RecentDocument, \
|
||||
MetadataGroup
|
||||
from staging import StagingFile
|
||||
from utils import document_save_to_temp_dir
|
||||
from documents.models import Document, DocumentType, DocumentPage, \
|
||||
DocumentPageTransformation, RecentDocument, MetadataGroup
|
||||
from documents.staging import StagingFile
|
||||
from documents.utils import document_save_to_temp_dir
|
||||
from documents import metadata_group_link
|
||||
|
||||
PICTURE_ERROR_SMALL = u'picture_error.png'
|
||||
@@ -107,10 +103,10 @@ def document_create_sibling(request, document_id, multiple=True):
|
||||
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
urldata = []
|
||||
for id, metadata in enumerate(document.documentmetadata_set.all()):
|
||||
for pk, metadata in enumerate(document.documentmetadata_set.all()):
|
||||
if hasattr(metadata, 'value'):
|
||||
urldata.append(('metadata%s_id' % id, metadata.metadata_type_id))
|
||||
urldata.append(('metadata%s_value' % id, metadata.value))
|
||||
urldata.append(('metadata%s_id' % pk, metadata.metadata_type_id))
|
||||
urldata.append(('metadata%s_value' % pk, metadata.value))
|
||||
|
||||
if multiple:
|
||||
view = 'upload_multiple_documents_with_type'
|
||||
@@ -318,9 +314,10 @@ def document_view(request, document_id):
|
||||
if metadata_groups:
|
||||
subtemplates_dict.append(
|
||||
{
|
||||
'title':_(u'metadata groups (%s)') % len(metadata_groups.keys()),
|
||||
'title': _(u'metadata groups (%s)') % len(metadata_groups.keys()),
|
||||
'form': MetaDataGroupForm(groups=metadata_groups, current_document=document, links=[
|
||||
metadata_group_link]),
|
||||
metadata_group_link
|
||||
]),
|
||||
'name': 'generic_form_subtemplate.html',
|
||||
'form_action': reverse('metadatagroup_action'),
|
||||
'submit_method': 'GET',
|
||||
@@ -332,7 +329,8 @@ def document_view(request, document_id):
|
||||
'name': 'generic_list_subtemplate.html',
|
||||
'title': _(u'index links'),
|
||||
'object_list': document.documentmetadataindex_set.all(),
|
||||
'hide_link': True})
|
||||
'hide_link': True
|
||||
})
|
||||
|
||||
return render_to_response('generic_detail.html', {
|
||||
'form_list': form_list,
|
||||
@@ -365,7 +363,8 @@ def document_delete(request, document_id=None, document_id_list=None):
|
||||
messages.success(request, _(u'Document: %s deleted successfully.') % document)
|
||||
except Exception, e:
|
||||
messages.error(request, _(u'Document: %(document)s delete error: %(error)s') % {
|
||||
'document': document, 'error': e})
|
||||
'document': document, 'error': e
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(next)
|
||||
|
||||
@@ -386,11 +385,15 @@ def document_delete(request, document_id=None, document_id_list=None):
|
||||
|
||||
|
||||
def document_multiple_delete(request):
|
||||
return document_delete(request, document_id_list=request.GET.get('id_list', []))
|
||||
return document_delete(
|
||||
request, document_id_list=request.GET.get('id_list', [])
|
||||
)
|
||||
|
||||
|
||||
def document_edit(request, document_id):
|
||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_PROPERTIES_EDIT])
|
||||
check_permissions(
|
||||
request.user, 'documents', [PERMISSION_DOCUMENT_PROPERTIES_EDIT]
|
||||
)
|
||||
|
||||
document = get_object_or_404(Document, pk=document_id)
|
||||
|
||||
@@ -560,12 +563,12 @@ def get_document_image(request, document_id, size=PREVIEW_SIZE, quality=QUALITY_
|
||||
rotation = int(request.GET.get('rotation', 0)) % 360
|
||||
|
||||
try:
|
||||
filepath = in_image_cache(document.checksum, size=size, format=u'jpg', quality=quality, extra_options=tranformation_string, page=page - 1, zoom=zoom, rotation=rotation)
|
||||
filepath = in_image_cache(document.checksum, size=size, file_format=u'jpg', quality=quality, extra_options=tranformation_string, page=page - 1, zoom=zoom, rotation=rotation)
|
||||
if filepath:
|
||||
return sendfile.sendfile(request, filename=filepath)
|
||||
#Save to a temporary location
|
||||
filepath = document_save_to_temp_dir(document, filename=document.checksum)
|
||||
output_file = convert(filepath, size=size, format=u'jpg', quality=quality, extra_options=tranformation_string, page=page - 1, zoom=zoom, rotation=rotation)
|
||||
output_file = convert(filepath, size=size, file_format=u'jpg', quality=quality, extra_options=tranformation_string, page=page - 1, zoom=zoom, rotation=rotation)
|
||||
return sendfile.sendfile(request, filename=output_file)
|
||||
except UnkownConvertError, e:
|
||||
if request.user.is_staff or request.user.is_superuser:
|
||||
@@ -611,9 +614,10 @@ def staging_file_preview(request, staging_file_id):
|
||||
try:
|
||||
output_file, errors = StagingFile.get(staging_file_id).preview()
|
||||
if errors and (request.user.is_staff or request.user.is_superuser):
|
||||
messages.warning(request, _(u'Error for transformation %(transformation)s:, %(error)s') %
|
||||
{'transformation': page_transformation.get_transformation_display(),
|
||||
'error': e})
|
||||
for error in errors:
|
||||
messages.warning(request, _(u'Staging file transformation error:, %(error)s') % {
|
||||
'error': error
|
||||
})
|
||||
|
||||
return sendfile.sendfile(request, filename=output_file)
|
||||
except UnkownConvertError, e:
|
||||
@@ -868,9 +872,13 @@ def document_view_simple(request, document_id):
|
||||
if metadata_groups:
|
||||
subtemplates_dict.append(
|
||||
{
|
||||
'title':_(u'metadata groups (%s)') % len(metadata_groups.keys()),
|
||||
'form': MetaDataGroupForm(groups=metadata_groups, current_document=document, links=[
|
||||
metadata_group_link]),
|
||||
'title': _(u'metadata groups (%s)') % len(metadata_groups.keys()),
|
||||
'form': MetaDataGroupForm(
|
||||
groups=metadata_groups, current_document=document,
|
||||
links=[
|
||||
metadata_group_link
|
||||
]
|
||||
),
|
||||
'name': 'generic_form_subtemplate.html',
|
||||
'form_action': reverse('metadatagroup_action'),
|
||||
'submit_method': 'GET',
|
||||
@@ -1056,7 +1064,7 @@ def document_page_zoom_in(request, document_page_id):
|
||||
return transform_page(
|
||||
request,
|
||||
document_page_id,
|
||||
zoom_function = lambda x: ZOOM_MAX_LEVEL if x + ZOOM_PERCENT_STEP > ZOOM_MAX_LEVEL else x + ZOOM_PERCENT_STEP
|
||||
zoom_function=lambda x: ZOOM_MAX_LEVEL if x + ZOOM_PERCENT_STEP > ZOOM_MAX_LEVEL else x + ZOOM_PERCENT_STEP
|
||||
)
|
||||
|
||||
|
||||
@@ -1064,7 +1072,7 @@ def document_page_zoom_out(request, document_page_id):
|
||||
return transform_page(
|
||||
request,
|
||||
document_page_id,
|
||||
zoom_function = lambda x: ZOOM_MIN_LEVEL if x - ZOOM_PERCENT_STEP < ZOOM_MIN_LEVEL else x - ZOOM_PERCENT_STEP
|
||||
zoom_function=lambda x: ZOOM_MIN_LEVEL if x - ZOOM_PERCENT_STEP < ZOOM_MIN_LEVEL else x - ZOOM_PERCENT_STEP
|
||||
)
|
||||
|
||||
|
||||
@@ -1072,7 +1080,7 @@ def document_page_rotate_right(request, document_page_id):
|
||||
return transform_page(
|
||||
request,
|
||||
document_page_id,
|
||||
rotation_function = lambda x: (x + ROTATION_STEP) % 360
|
||||
rotation_function=lambda x: (x + ROTATION_STEP) % 360
|
||||
)
|
||||
|
||||
|
||||
@@ -1080,7 +1088,7 @@ def document_page_rotate_left(request, document_page_id):
|
||||
return transform_page(
|
||||
request,
|
||||
document_page_id,
|
||||
rotation_function = lambda x: (x - ROTATION_STEP) % 360
|
||||
rotation_function=lambda x: (x - ROTATION_STEP) % 360
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
# original code from:
|
||||
# http://www.julienphalip.com/blog/2008/08/16/adding-search-django-site-snap/
|
||||
|
||||
import re
|
||||
import types
|
||||
import datetime
|
||||
|
||||
from django.db.models import Q
|
||||
|
||||
from conf.settings import LIMIT
|
||||
from dynamic_search.conf.settings import LIMIT
|
||||
|
||||
search_list = {}
|
||||
|
||||
@@ -15,29 +18,26 @@ def register(model, text, field_list):
|
||||
else:
|
||||
search_list[model] = {'fields': field_list, 'text': text}
|
||||
|
||||
#original code from:
|
||||
#http://www.julienphalip.com/blog/2008/08/16/adding-search-django-site-snap/
|
||||
|
||||
|
||||
def normalize_query(query_string,
|
||||
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
|
||||
normspace=re.compile(r'\s{2,}').sub):
|
||||
''' Splits the query string in invidual keywords, getting rid of unecessary spaces
|
||||
""" Splits the query string in invidual keywords, getting rid of unecessary spaces
|
||||
and grouping quoted words together.
|
||||
Example:
|
||||
|
||||
>>> normalize_query(' some random words "with quotes " and spaces')
|
||||
['some', 'random', 'words', 'with quotes', 'and', 'spaces']
|
||||
|
||||
'''
|
||||
"""
|
||||
return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)]
|
||||
|
||||
|
||||
def get_query(query_string, terms, search_fields):
|
||||
''' Returns a query, that is a combination of Q objects. That combination
|
||||
def get_query(terms, search_fields):
|
||||
"""
|
||||
Returns a query, that is a combination of Q objects. That combination
|
||||
aims to search keywords within a model by testing the given search fields.
|
||||
|
||||
'''
|
||||
"""
|
||||
queries = []
|
||||
for term in terms:
|
||||
or_query = None
|
||||
@@ -47,7 +47,7 @@ def get_query(query_string, terms, search_fields):
|
||||
field_name = field
|
||||
elif isinstance(field, types.DictType):
|
||||
comparison = field.get('comparison', u'icontains')
|
||||
field_name = field.get('field_name', '')
|
||||
field_name = field.get('field_name', u'')
|
||||
|
||||
if field_name:
|
||||
q = Q(**{'%s__%s' % (field_name, comparison): term})
|
||||
@@ -72,7 +72,7 @@ def perform_search(query_string):
|
||||
terms = normalize_query(query_string)
|
||||
|
||||
for model, data in search_list.items():
|
||||
queries = get_query(query_string, terms, data['fields'])
|
||||
queries = get_query(terms, data['fields'])
|
||||
|
||||
model_result_ids = None
|
||||
for query in queries:
|
||||
|
||||
@@ -4,9 +4,9 @@ from django.utils.translation import ugettext as _
|
||||
from django.contrib import messages
|
||||
from django.conf import settings
|
||||
|
||||
from api import perform_search
|
||||
from forms import SearchForm
|
||||
from conf.settings import SHOW_OBJECT_TYPE
|
||||
from dynamic_search.api import perform_search
|
||||
from dynamic_search.forms import SearchForm
|
||||
from dynamic_search.conf.settings import SHOW_OBJECT_TYPE
|
||||
|
||||
|
||||
def results(request, form=None):
|
||||
|
||||
@@ -7,8 +7,8 @@ from permissions.api import register_permissions
|
||||
FILESYSTEM_SERVING_RECREATE_LINKS = 'recreate_links'
|
||||
|
||||
register_permissions('filesystem_serving', [
|
||||
{'name':FILESYSTEM_SERVING_RECREATE_LINKS, 'label':_(u'Recreate filesystem links.')},
|
||||
{'name': FILESYSTEM_SERVING_RECREATE_LINKS, 'label':_(u'Recreate filesystem links.')},
|
||||
])
|
||||
|
||||
|
||||
filesystem_serving_recreate_all_links = {'text':_('recreate index links'), 'view':'recreate_all_links', 'famfam':'page_link', 'permissions':{'namespace':'filesystem_serving', 'permissions':[FILESYSTEM_SERVING_RECREATE_LINKS]}}
|
||||
filesystem_serving_recreate_all_links = {'text': _('recreate index links'), 'view': 'recreate_all_links', 'famfam': 'page_link', 'permissions': {'namespace': 'filesystem_serving', 'permissions': [FILESYSTEM_SERVING_RECREATE_LINKS]}}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import DocumentMetadataIndex
|
||||
from filesystem_serving.models import DocumentMetadataIndex
|
||||
|
||||
|
||||
class DocumentMetadataIndexInline(admin.StackedInline):
|
||||
model = DocumentMetadataIndex
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import errno
|
||||
import os
|
||||
|
||||
from django.template.defaultfilters import slugify
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -10,7 +11,7 @@ from filesystem_serving.conf.settings import FILESERVING_PATH
|
||||
from filesystem_serving.conf.settings import SLUGIFY_PATHS
|
||||
from filesystem_serving.conf.settings import MAX_RENAME_COUNT
|
||||
|
||||
from models import DocumentMetadataIndex, Document
|
||||
from filesystem_serving.models import DocumentMetadataIndex, Document
|
||||
|
||||
if SLUGIFY_PATHS == False:
|
||||
#Do not slugify path or filenames and extensions
|
||||
|
||||
@@ -4,12 +4,10 @@ from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
from permissions.api import check_permissions
|
||||
|
||||
|
||||
from filesystem_serving import FILESYSTEM_SERVING_RECREATE_LINKS
|
||||
from api import do_recreate_all_links
|
||||
from filesystem_serving.api import do_recreate_all_links
|
||||
|
||||
|
||||
def recreate_all_links(request):
|
||||
|
||||
@@ -5,7 +5,7 @@ from navigation.api import register_links, register_menu, \
|
||||
from permissions.api import register_permissions
|
||||
from navigation.api import register_sidebar_template
|
||||
|
||||
from models import Folder
|
||||
from folders.models import Folder
|
||||
|
||||
folder_list = {'text': _(u'folder list'), 'view': 'folder_list', 'famfam': 'folder'}
|
||||
folder_create = {'text': _('create folder'), 'view': 'folder_create', 'famfam': 'folder_add'}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import Folder, FolderDocument
|
||||
from folders.models import Folder, FolderDocument
|
||||
|
||||
|
||||
class FolderDocumentInline(admin.StackedInline):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from models import Folder
|
||||
from folders.models import Folder
|
||||
|
||||
|
||||
class FolderForm(forms.ModelForm):
|
||||
@@ -21,5 +21,3 @@ class AddDocumentForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Folder
|
||||
fields = ('title',)
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||
from django.template import TemplateSyntaxError, Library, \
|
||||
VariableDoesNotExist, Node, Variable
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import Library
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from folders.forms import AddDocumentForm
|
||||
@@ -13,7 +13,7 @@ def get_add_document_to_folder_form(context):
|
||||
context.update({
|
||||
'form': AddDocumentForm(user=context['request'].user),
|
||||
'request': context['request'],
|
||||
'form_action': reverse('folder_add_document' ,args=[context['object'].pk]),
|
||||
'form_action': reverse('folder_add_document', args=[context['object'].pk]),
|
||||
'title': _('Add document to a folder')
|
||||
})
|
||||
return context
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
from django.contrib import messages
|
||||
from django.views.generic.list_detail import object_detail, object_list
|
||||
from django.views.generic.list_detail import object_list
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.generic.create_update import create_object, delete_object, update_object
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from documents import PERMISSION_DOCUMENT_VIEW
|
||||
from documents.models import Document
|
||||
from permissions.api import check_permissions
|
||||
|
||||
from models import Folder, FolderDocument
|
||||
from forms import FolderForm, AddDocumentForm
|
||||
from folders.models import Folder, FolderDocument
|
||||
from folders.forms import FolderForm, AddDocumentForm
|
||||
|
||||
|
||||
def folder_list(request):
|
||||
@@ -61,7 +60,7 @@ def folder_edit(request, folder_id):
|
||||
if request.method == 'POST':
|
||||
form = FolderForm(request.POST)
|
||||
if form.is_valid():
|
||||
folder.title=form.cleaned_data['title']
|
||||
folder.title = form.cleaned_data['title']
|
||||
try:
|
||||
folder.save()
|
||||
messages.success(request, _(u'Folder edited successfully'))
|
||||
|
||||
@@ -151,12 +151,14 @@ def statistics(request):
|
||||
|
||||
return render_to_response('statistics.html', {
|
||||
'blocks': blocks,
|
||||
'title': _(u'Statistics') },
|
||||
'title': _(u'Statistics')
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
|
||||
def diagnostics_view(request):
|
||||
return render_to_response('diagnostics.html', {
|
||||
'blocks': diagnostics,
|
||||
'title': _(u'Diagnostics') },
|
||||
'title': _(u'Diagnostics')
|
||||
},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@@ -62,7 +62,7 @@ class NavigationNode(Node):
|
||||
|
||||
@register.tag
|
||||
def main_navigation(parser, token):
|
||||
args = token.split_contents()
|
||||
#args = token.split_contents()
|
||||
|
||||
# if len(args) != 3 or args[1] != 'as':
|
||||
# raise TemplateSyntaxError("'get_all_states' requires 'as variable' (got %r)" % args)
|
||||
|
||||
@@ -10,8 +10,8 @@ from permissions.api import register_permissions
|
||||
from documents.models import Document
|
||||
|
||||
from ocr.conf.settings import AUTOMATIC_OCR
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from literals import QUEUEDOCUMENT_STATE_PROCESSING, \
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
from ocr.literals import QUEUEDOCUMENT_STATE_PROCESSING, \
|
||||
QUEUEDOCUMENT_STATE_PENDING, DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
DOCUMENTQUEUE_STATE_ACTIVE
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
|
||||
|
||||
class QueueDocumentInline(admin.StackedInline):
|
||||
|
||||
@@ -15,7 +15,7 @@ from documents.models import DocumentPage
|
||||
from ocr.conf.settings import TESSERACT_PATH
|
||||
from ocr.conf.settings import TESSERACT_LANGUAGE
|
||||
from ocr.conf.settings import PDFTOTEXT_PATH
|
||||
from exceptions import TesseractError, PdftotextError
|
||||
from ocr.exceptions import TesseractError, PdftotextError
|
||||
|
||||
|
||||
def get_language_backend():
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
|
||||
|
||||
def check_word(word):
|
||||
ALL_ALPHANUM = re.compile('([0-9a-z])', re.I)
|
||||
NON_ALPHANUM = re.compile('([^0-9a-z])', re.I)
|
||||
@@ -35,4 +36,3 @@ def check_word(word):
|
||||
return None
|
||||
|
||||
return word
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
|
||||
def check_word(word):
|
||||
ALL_ALPHANUM = re.compile('([0-9a-záéíóúüñ])', re.I)
|
||||
NON_ALPHANUM = re.compile('([^0-9a-záéíóúüñ])', re.I)
|
||||
@@ -36,4 +37,3 @@ def check_word(word):
|
||||
return None
|
||||
|
||||
return word
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from documents.models import Document
|
||||
|
||||
from literals import DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
from ocr.literals import DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
DOCUMENTQUEUE_STATE_CHOICES, QUEUEDOCUMENT_STATE_PENDING, \
|
||||
QUEUEDOCUMENT_STATE_CHOICES
|
||||
from exceptions import AlreadyQueued
|
||||
from ocr.exceptions import AlreadyQueued
|
||||
|
||||
|
||||
class DocumentQueueManager(models.Manager):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
|
||||
|
||||
def get_statistics():
|
||||
|
||||
@@ -9,10 +9,10 @@ from celery.task import PeriodicTask
|
||||
from celery.decorators import task
|
||||
|
||||
from ocr.api import do_document_ocr
|
||||
from literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
QUEUEDOCUMENT_STATE_PROCESSING, DOCUMENTQUEUE_STATE_ACTIVE, \
|
||||
QUEUEDOCUMENT_STATE_ERROR
|
||||
from models import QueueDocument, DocumentQueue
|
||||
from ocr.models import QueueDocument, DocumentQueue
|
||||
from ocr.conf.settings import NODE_CONCURRENT_EXECUTION
|
||||
from ocr.conf.settings import REPLICATION_DELAY
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@ from documents.models import Document
|
||||
from ocr import PERMISSION_OCR_DOCUMENT, PERMISSION_OCR_DOCUMENT_DELETE, \
|
||||
PERMISSION_OCR_QUEUE_ENABLE_DISABLE, PERMISSION_OCR_CLEAN_ALL_PAGES
|
||||
|
||||
from models import DocumentQueue, QueueDocument
|
||||
from literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
from ocr.models import DocumentQueue, QueueDocument
|
||||
from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||
QUEUEDOCUMENT_STATE_PROCESSING, DOCUMENTQUEUE_STATE_STOPPED, \
|
||||
DOCUMENTQUEUE_STATE_ACTIVE
|
||||
from exceptions import AlreadyQueued
|
||||
from api import clean_pages
|
||||
from ocr.exceptions import AlreadyQueued
|
||||
from ocr.api import clean_pages
|
||||
|
||||
|
||||
def _display_thumbnail(ocr_document):
|
||||
@@ -65,15 +65,13 @@ def queue_document_list(request, queue_name='default'):
|
||||
)
|
||||
|
||||
|
||||
def queue_document_delete(request, queue_document_id=None, queue_document_id_list=[]):
|
||||
def queue_document_delete(request, queue_document_id=None, queue_document_id_list=None):
|
||||
check_permissions(request.user, 'ocr', [PERMISSION_OCR_DOCUMENT_DELETE])
|
||||
|
||||
if queue_document_id:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
||||
post_redirect = None
|
||||
elif queue_document_id_list:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id) for queue_document_id in queue_document_id_list.split(',')]
|
||||
post_redirect = None
|
||||
else:
|
||||
messages.error(request, _(u'Must provide at least one queue document.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
@@ -138,15 +136,13 @@ def submit_document_to_queue(request, document, post_submit_redirect=None):
|
||||
return HttpResponseRedirect(post_submit_redirect)
|
||||
|
||||
|
||||
def re_queue_document(request, queue_document_id=None, queue_document_id_list=[]):
|
||||
def re_queue_document(request, queue_document_id=None, queue_document_id_list=None):
|
||||
check_permissions(request.user, 'ocr', [PERMISSION_OCR_DOCUMENT])
|
||||
|
||||
if queue_document_id:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
||||
post_redirect = None
|
||||
elif queue_document_id_list:
|
||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id) for queue_document_id in queue_document_id_list.split(',')]
|
||||
post_redirect = None
|
||||
else:
|
||||
messages.error(request, _(u'Must provide at least one queue document.'))
|
||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from navigation.api import register_links, register_menu
|
||||
|
||||
from permissions.conf.settings import DEFAULT_ROLES
|
||||
from models import Role
|
||||
from permissions.models import Role
|
||||
|
||||
PERMISSION_ROLE_VIEW = 'role_view'
|
||||
PERMISSION_ROLE_EDIT = 'role_edit'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from models import Permission, PermissionHolder, Role, RoleMember
|
||||
from permissions.models import Permission, PermissionHolder, Role, RoleMember
|
||||
|
||||
|
||||
class PermissionHolderInline(admin.StackedInline):
|
||||
model = PermissionHolder
|
||||
@@ -28,4 +29,3 @@ class RoleAdmin(admin.ModelAdmin):
|
||||
|
||||
admin.site.register(Permission, PermissionAdmin)
|
||||
admin.site.register(Role, RoleAdmin)
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from permissions import PERMISSION_ROLE_VIEW, PERMISSION_ROLE_EDIT, \
|
||||
PERMISSION_ROLE_CREATE, PERMISSION_ROLE_DELETE, \
|
||||
PERMISSION_PERMISSION_GRANT, PERMISSION_PERMISSION_REVOKE
|
||||
|
||||
from models import Permission, Role
|
||||
from permissions.models import Permission, Role
|
||||
|
||||
|
||||
def register_permissions(namespace, permissions):
|
||||
@@ -66,7 +66,7 @@ def check_requester(requester, permission_holder):
|
||||
|
||||
#TODO: a role may contain groups, make recursive
|
||||
def check_elements(requester, requester_list):
|
||||
ct = ContentType.objects.get_for_model(requester)
|
||||
#ct = ContentType.objects.get_for_model(requester)
|
||||
for requester_object in requester_list:
|
||||
if requester == requester_object:
|
||||
return True
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
from django.conf import settings
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.forms import DetailForm
|
||||
|
||||
from models import Role, RoleMember
|
||||
from permissions.models import Role
|
||||
|
||||
|
||||
class RoleForm(forms.ModelForm):
|
||||
@@ -24,6 +23,6 @@ class ChoiceForm(forms.Form):
|
||||
super(ChoiceForm, self).__init__(*args, **kwargs)
|
||||
self.fields['selection'].choices = choices
|
||||
self.fields['selection'].label = label
|
||||
self.fields['selection'].widget.attrs.update({'size':14})
|
||||
self.fields['selection'].widget.attrs.update({'size': 14})
|
||||
|
||||
selection = forms.MultipleChoiceField()
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.contrib.contenttypes import generic
|
||||
class PermissionManager(models.Manager):
|
||||
def get_for_holder(self, holder):
|
||||
ct = ContentType.objects.get_for_model(holder)
|
||||
return [Permission.objects.get(id=id) for id in PermissionHolder.objects.filter(holder_type=ct, holder_id=holder.id).values_list('permission_id', flat=True)]
|
||||
return [Permission.objects.get(pk=pk) for pk in PermissionHolder.objects.filter(holder_type=ct, holder_id=holder.pk).values_list('permission_id', flat=True)]
|
||||
|
||||
|
||||
class Permission(models.Model):
|
||||
@@ -56,7 +56,7 @@ class Role(models.Model):
|
||||
role_member, created = RoleMember.objects.get_or_create(
|
||||
role=self,
|
||||
member_type=ContentType.objects.get_for_model(member),
|
||||
member_id=member.id)
|
||||
member_id=member.pk)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.label
|
||||
|
||||
@@ -10,12 +10,12 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from models import Role, Permission, PermissionHolder, RoleMember
|
||||
from forms import RoleForm, RoleForm_view, ChoiceForm
|
||||
from permissions.models import Role, Permission, PermissionHolder, RoleMember
|
||||
from permissions.forms import RoleForm, RoleForm_view, ChoiceForm
|
||||
from permissions import PERMISSION_ROLE_VIEW, PERMISSION_ROLE_EDIT, \
|
||||
PERMISSION_ROLE_CREATE, PERMISSION_ROLE_DELETE, PERMISSION_PERMISSION_GRANT, \
|
||||
PERMISSION_PERMISSION_REVOKE
|
||||
from api import check_permissions
|
||||
from permissions.api import check_permissions
|
||||
|
||||
|
||||
def role_list(request):
|
||||
|
||||
@@ -6,7 +6,6 @@ from django.utils.encoding import force_unicode
|
||||
from pymongo import Connection
|
||||
from gridfs import GridFS
|
||||
|
||||
|
||||
from storage.conf import settings
|
||||
|
||||
|
||||
@@ -18,7 +17,6 @@ class GridFSStorage(Storage):
|
||||
port=settings.GRIDFS_PORT)[settings.GRIDFS_DATABASE_NAME]
|
||||
self.fs = GridFS(self.db)
|
||||
|
||||
|
||||
def save(self, name, content):
|
||||
#TODO: if exists add _ plus a counter
|
||||
while True:
|
||||
@@ -37,7 +35,7 @@ class GridFSStorage(Storage):
|
||||
newfile.write(chunk)
|
||||
finally:
|
||||
newfile.close()
|
||||
except Exception, e:#OSError, e:
|
||||
except Exception, e: # OSError, e:
|
||||
# if e.errno == errno.EEXIST:
|
||||
# # Ooops, the file exists. We need a new file name.
|
||||
# name = self.get_available_name(name)
|
||||
@@ -51,29 +49,23 @@ class GridFSStorage(Storage):
|
||||
|
||||
return name
|
||||
|
||||
|
||||
def open(self, name, *args, **kwars):
|
||||
return self.fs.get_last_version(name)
|
||||
|
||||
|
||||
def delete(self, name):
|
||||
oid = self.fs.get_last_version(name)._id
|
||||
self.fs.delete(oid)
|
||||
|
||||
|
||||
def exists(self, name):
|
||||
return self.fs.exists(filename=name)
|
||||
|
||||
|
||||
def path(self, name):
|
||||
return force_unicode(name)
|
||||
|
||||
|
||||
def size(self, name):
|
||||
return self.fs.get_last_version(name).length
|
||||
|
||||
|
||||
def move(self, old_file_name, name, chunk_size=1024*64):
|
||||
def move(self, old_file_name, name, chunk_size=1024 * 64):
|
||||
# first open the old file, so that it won't go away
|
||||
old_file = open(old_file_name, 'rb')
|
||||
try:
|
||||
@@ -98,4 +90,3 @@ class GridFSStorage(Storage):
|
||||
# on close anyway.)
|
||||
if getattr(e, 'winerror', 0) != 32 and getattr(e, 'errno', 0) != 13:
|
||||
raise
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from django import forms
|
||||
from django.template import TemplateSyntaxError, Library, \
|
||||
VariableDoesNotExist, Node, Variable
|
||||
from django.conf import settings
|
||||
from django.template import Library, Node, Variable
|
||||
|
||||
register = Library()
|
||||
|
||||
@@ -15,17 +13,16 @@ class StylingNode(Node):
|
||||
for field_name, field in form.fields.items():
|
||||
|
||||
if isinstance(field.widget, forms.widgets.TextInput):
|
||||
field.widget.attrs['class'] = 'text_field'
|
||||
field.widget.attrs['class'] = u'text_field'
|
||||
elif isinstance(field.widget, forms.widgets.PasswordInput):
|
||||
field.widget.attrs['class'] = 'text_field'
|
||||
field.widget.attrs['class'] = u'text_field'
|
||||
elif isinstance(field.widget, forms.widgets.Textarea):
|
||||
field.widget.attrs['class'] = 'text_area'
|
||||
field.widget.attrs['class'] = u'text_area'
|
||||
|
||||
context[self.form_name] = form
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
@register.tag
|
||||
def add_classes_to_form(parser, token):
|
||||
args = token.split_contents()
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import types
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||
from django.core.urlresolvers import RegexURLResolver, RegexURLPattern, Resolver404, get_resolver
|
||||
from django.template import TemplateSyntaxError, Library, \
|
||||
VariableDoesNotExist, Node, Variable
|
||||
from django.utils.text import unescape_string_literal
|
||||
from django.template import Library, Node, TemplateSyntaxError
|
||||
|
||||
from web_theme.conf import settings as web_theme_settings
|
||||
|
||||
@@ -29,12 +24,12 @@ def get_theme(parser, token):
|
||||
# Splitting by None == splitting by spaces.
|
||||
tag_name, arg = token.contents.split(None, 1)
|
||||
except ValueError:
|
||||
raise template.TemplateSyntaxError, "%r tag requires arguments" % token.contents.split()[0]
|
||||
raise TemplateSyntaxError('%r tag requires arguments' % token.contents.split()[0])
|
||||
|
||||
#m = re.search(r'(.*?) as (\w+)', arg)
|
||||
m = re.search(r'as (\w+)', arg)
|
||||
if not m:
|
||||
raise template.TemplateSyntaxError, "%r tag had invalid arguments" % tag_name
|
||||
raise TemplateSyntaxError('%r tag had invalid arguments' % tag_name)
|
||||
#format_string, var_name = m.groups()
|
||||
var_name = m.groups()
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ BROKER_PORT = 5672
|
||||
BROKER_USER = "guest"
|
||||
BROKER_PASSWORD = "guest"
|
||||
BROKER_VHOST = "/"
|
||||
CELERYBEAT_SCHEDULER='djcelery.schedulers.DatabaseScheduler'
|
||||
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
|
||||
#======== End of user configuration options =======
|
||||
#--------- Web theme ---------------
|
||||
WEB_THEME_ENABLE_SCROLL_JS = False
|
||||
@@ -305,7 +305,7 @@ if DEVELOPMENT:
|
||||
|
||||
try:
|
||||
import django_extensions
|
||||
INSTALLED_APPS +=('django_extensions',)
|
||||
INSTALLED_APPS += ('django_extensions',)
|
||||
except ImportError:
|
||||
#print 'django_extensions is not installed'
|
||||
pass
|
||||
@@ -322,6 +322,6 @@ if DEVELOPMENT:
|
||||
WSGI_AUTO_RELOAD = True
|
||||
if 'debug_toolbar' in INSTALLED_APPS:
|
||||
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
|
||||
DEBUG_TOOLBAR_CONFIG={
|
||||
'INTERCEPT_REDIRECTS' : False,
|
||||
DEBUG_TOOLBAR_CONFIG = {
|
||||
'INTERCEPT_REDIRECTS': False,
|
||||
}
|
||||
|
||||
9
urls.py
9
urls.py
@@ -1,8 +1,6 @@
|
||||
from django.conf.urls.defaults import *
|
||||
from django.conf.urls.defaults import patterns, include, url
|
||||
from django.contrib import admin
|
||||
from django.conf import settings
|
||||
from django.conf.urls.defaults import *
|
||||
from django.views.defaults import page_not_found, server_error
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
@@ -21,6 +19,7 @@ urlpatterns = patterns('',
|
||||
(r'^sentry/', include('sentry.urls')),
|
||||
)
|
||||
|
||||
|
||||
def handler500(request):
|
||||
"""
|
||||
500 error handler which includes ``request`` in the context.
|
||||
@@ -40,12 +39,10 @@ if settings.DEVELOPMENT:
|
||||
urlpatterns += patterns('',
|
||||
(r'^%s-site_media/(?P<path>.*)$' % settings.PROJECT_NAME,
|
||||
'django.views.static.serve',
|
||||
{'document_root':'site_media', 'show_indexes':True}),
|
||||
{'document_root': 'site_media', 'show_indexes': True}),
|
||||
)
|
||||
|
||||
if 'rosetta' in settings.INSTALLED_APPS:
|
||||
urlpatterns += patterns('',
|
||||
url(r'^rosetta/', include('rosetta.urls'), name='rosetta'),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user