PEP8, pylint cleanups and removal of relative imports
This commit is contained in:
@@ -86,7 +86,7 @@ class DetailForm(forms.ModelForm):
|
|||||||
queryset=getattr(field, 'queryset', None),
|
queryset=getattr(field, 'queryset', None),
|
||||||
)
|
)
|
||||||
self.fields[field_name].help_text = ''
|
self.fields[field_name].help_text = ''
|
||||||
|
|
||||||
for field_name, field in self.fields.items():
|
for field_name, field in self.fields.items():
|
||||||
self.fields[field_name].widget.attrs.update({'readonly': 'readonly'})
|
self.fields[field_name].widget.attrs.update({'readonly': 'readonly'})
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
from re import compile
|
import re
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.conf import settings
|
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'):
|
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:
|
class LoginRequiredMiddleware:
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ from django.utils.html import strip_spaces_between_tags as short
|
|||||||
|
|
||||||
class SpacelessMiddleware(object):
|
class SpacelessMiddleware(object):
|
||||||
def process_response(self, request, response):
|
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)
|
response.content = short(response.content)
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- coding: iso-8859-1 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import types
|
import types
|
||||||
@@ -9,7 +9,7 @@ from django.utils.datastructures import MultiValueDict
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
def urlquote(link=None, get={}):
|
def urlquote(link=None, get=None):
|
||||||
u'''
|
u'''
|
||||||
This method does both: urlquote() and urlencode()
|
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('/mypath/', {'key': ['value1', 'value2']}) --> '/mypath/?key=value1&key=value2'
|
||||||
urlquote({'key': ['value1', 'value2']}) --> 'key=value1&key=value2'
|
urlquote({'key': ['value1', 'value2']}) --> 'key=value1&key=value2'
|
||||||
'''
|
'''
|
||||||
|
if get is None:
|
||||||
|
get = []
|
||||||
|
|
||||||
assert link or get
|
assert link or get
|
||||||
if isinstance(link, dict):
|
if isinstance(link, dict):
|
||||||
# urlqoute({'key': 'value', 'key2': 'value2'}) --> key=value&key2=value2
|
# urlqoute({'key': 'value', 'key2': 'value2'}) --> key=value&key2=value2
|
||||||
@@ -48,7 +51,7 @@ def urlquote(link=None, get={}):
|
|||||||
return django_urlquote(link)
|
return django_urlquote(link)
|
||||||
|
|
||||||
|
|
||||||
def return_attrib(obj, attrib, arguments={}):
|
def return_attrib(obj, attrib, arguments=None):
|
||||||
try:
|
try:
|
||||||
if isinstance(attrib, types.FunctionType):
|
if isinstance(attrib, types.FunctionType):
|
||||||
return attrib(obj)
|
return attrib(obj)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from django.utils.hashcompat import md5_constructor
|
|||||||
__all__ = ('security_hash', 'BoundFormWizard')
|
__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.
|
"""Calculates a security hash for the given Form/FormSet instance.
|
||||||
|
|
||||||
This creates a list of the form field names/values in a deterministic
|
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,
|
Subclasses may want to take into account request-specific information,
|
||||||
such as the IP address.
|
such as the IP address.
|
||||||
"""
|
"""
|
||||||
return security_hash(request, form)
|
return security_hash_new(form)
|
||||||
|
|
||||||
def render(self, form, request, step, context=None):
|
def render(self, form, request, step, context=None):
|
||||||
"Renders the given Form object, returning an HttpResponse."
|
"Renders the given Form object, returning an HttpResponse."
|
||||||
|
|||||||
+14
-13
@@ -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 HIGH_QUALITY_OPTIONS
|
||||||
from converter.conf.settings import GRAPHICS_BACKEND
|
from converter.conf.settings import GRAPHICS_BACKEND
|
||||||
|
|
||||||
from exceptions import UnpaperError
|
from converter.exceptions import UnpaperError
|
||||||
|
|
||||||
#from converter.conf.settings import UNOCONV_PATH
|
#from converter.conf.settings import UNOCONV_PATH
|
||||||
from common import TEMPORARY_DIRECTORY
|
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''):
|
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, format=format, quality=quality, extra_options=extra_options)
|
filepath = create_image_cache_filename(input_filepath, size=size, page=page, file_format=file_format, quality=quality, extra_options=extra_options)
|
||||||
try:
|
try:
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
except OSError:
|
except OSError:
|
||||||
@@ -102,17 +102,17 @@ def create_image_cache_filename(input_filepath, *args, **kwargs):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def in_image_cache(input_filepath, size, page=0, format=u'jpg', quality=QUALITY_DEFAULT, extra_options=u'', zoom=100, rotation=0):
|
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, 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):
|
if os.path.exists(output_filepath):
|
||||||
return output_filepath
|
return output_filepath
|
||||||
else:
|
else:
|
||||||
return None
|
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
|
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):
|
if os.path.exists(output_filepath):
|
||||||
return output_filepath
|
return output_filepath
|
||||||
'''
|
'''
|
||||||
@@ -134,11 +134,11 @@ def convert(input_filepath, size, quality=QUALITY_DEFAULT, cache=True, page=0, f
|
|||||||
|
|
||||||
if rotation != 0 and rotation != 360:
|
if rotation != 0 and rotation != 360:
|
||||||
extra_options += u' -rotate %d ' % rotation
|
extra_options += u' -rotate %d ' % rotation
|
||||||
|
|
||||||
if format == u'jpg':
|
if format == u'jpg':
|
||||||
extra_options += u' -quality 85'
|
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:
|
finally:
|
||||||
if cleanup_files:
|
if cleanup_files:
|
||||||
cleanup(input_filepath)
|
cleanup(input_filepath)
|
||||||
@@ -156,7 +156,7 @@ def get_page_count(input_filepath):
|
|||||||
return 1
|
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
|
#Extract document file
|
||||||
input_filepath = document_save_to_temp_dir(document, document.uuid)
|
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)
|
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_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)
|
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)
|
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(transformation_output_file)
|
||||||
cleanup(unpaper_input_file)
|
cleanup(unpaper_input_file)
|
||||||
cleanup(unpaper_output_file)
|
cleanup(unpaper_output_file)
|
||||||
return convert_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 main.api import register_diagnostic
|
||||||
from permissions.api import register_permissions
|
from permissions.api import register_permissions
|
||||||
|
|
||||||
from models import Document, DocumentPage, DocumentPageTransformation
|
from documents.models import Document, DocumentPage, DocumentPageTransformation
|
||||||
from staging import StagingFile
|
from documents.staging import StagingFile
|
||||||
from conf.settings import ENABLE_SINGLE_DOCUMENT_UPLOAD
|
from documents.conf.settings import ENABLE_SINGLE_DOCUMENT_UPLOAD
|
||||||
|
|
||||||
PERMISSION_DOCUMENT_CREATE = 'document_create'
|
PERMISSION_DOCUMENT_CREATE = 'document_create'
|
||||||
PERMISSION_DOCUMENT_PROPERTIES_EDIT = 'document_properties_edit'
|
PERMISSION_DOCUMENT_PROPERTIES_EDIT = 'document_properties_edit'
|
||||||
|
|||||||
+11
-5
@@ -1,6 +1,6 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from models import MetadataType, DocumentType, Document, \
|
from documents.models import MetadataType, DocumentType, Document, \
|
||||||
DocumentTypeMetadataType, DocumentMetadata, DocumentTypeFilename, \
|
DocumentTypeMetadataType, DocumentMetadata, DocumentTypeFilename, \
|
||||||
MetadataIndex, DocumentPage, MetadataGroup, \
|
MetadataIndex, DocumentPage, MetadataGroup, \
|
||||||
MetadataGroupItem, DocumentPageTransformation, RecentDocument
|
MetadataGroupItem, DocumentPageTransformation, RecentDocument
|
||||||
@@ -34,7 +34,10 @@ class DocumentTypeFilenameInline(admin.StackedInline):
|
|||||||
|
|
||||||
|
|
||||||
class DocumentTypeAdmin(admin.ModelAdmin):
|
class DocumentTypeAdmin(admin.ModelAdmin):
|
||||||
inlines = [DocumentTypeFilenameInline, DocumentTypeMetadataTypeInline, MetadataIndexInline]
|
inlines = [
|
||||||
|
DocumentTypeFilenameInline, DocumentTypeMetadataTypeInline,
|
||||||
|
MetadataIndexInline
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class DocumentMetadataInline(admin.StackedInline):
|
class DocumentMetadataInline(admin.StackedInline):
|
||||||
@@ -56,8 +59,10 @@ class DocumentPageInline(admin.StackedInline):
|
|||||||
|
|
||||||
|
|
||||||
class DocumentAdmin(admin.ModelAdmin):
|
class DocumentAdmin(admin.ModelAdmin):
|
||||||
inlines = [DocumentMetadataInline, DocumentMetadataIndexInline,
|
inlines = [
|
||||||
DocumentPageInline]
|
DocumentMetadataInline, DocumentMetadataIndexInline,
|
||||||
|
DocumentPageInline
|
||||||
|
]
|
||||||
list_display = ('uuid', 'file_filename', 'file_extension')
|
list_display = ('uuid', 'file_filename', 'file_extension')
|
||||||
|
|
||||||
|
|
||||||
@@ -85,5 +90,6 @@ admin.site.register(MetadataType, MetadataTypeAdmin)
|
|||||||
admin.site.register(DocumentType, DocumentTypeAdmin)
|
admin.site.register(DocumentType, DocumentTypeAdmin)
|
||||||
admin.site.register(Document, DocumentAdmin)
|
admin.site.register(Document, DocumentAdmin)
|
||||||
admin.site.register(MetadataGroup, MetadataGroupAdmin)
|
admin.site.register(MetadataGroup, MetadataGroupAdmin)
|
||||||
admin.site.register(DocumentPageTransformation, DocumentPageTransformationAdmin)
|
admin.site.register(DocumentPageTransformation,
|
||||||
|
DocumentPageTransformationAdmin)
|
||||||
admin.site.register(RecentDocument, RecentDocumentAdmin)
|
admin.site.register(RecentDocument, RecentDocumentAdmin)
|
||||||
|
|||||||
@@ -19,17 +19,17 @@ def default_checksum(x):
|
|||||||
def default_uuid():
|
def default_uuid():
|
||||||
"""unicode(uuid.uuid4())"""
|
"""unicode(uuid.uuid4())"""
|
||||||
return unicode(uuid.uuid4())
|
return unicode(uuid.uuid4())
|
||||||
|
|
||||||
default_available_functions = {
|
default_available_functions = {
|
||||||
'current_date':datetime.datetime.now().date,
|
'current_date': datetime.datetime.now().date,
|
||||||
}
|
}
|
||||||
|
|
||||||
default_available_models = {
|
default_available_models = {
|
||||||
'User':User
|
'User': User
|
||||||
}
|
}
|
||||||
|
|
||||||
available_transformations = {
|
available_transformations = {
|
||||||
'rotate': {'label':_(u'Rotate [degrees]'), 'arguments':[{'name':'degrees'}]}
|
'rotate': {'label': _(u'Rotate [degrees]'), 'arguments': [{'name': 'degrees'}]}
|
||||||
}
|
}
|
||||||
|
|
||||||
available_indexing_functions = {
|
available_indexing_functions = {
|
||||||
|
|||||||
+30
-14
@@ -8,12 +8,12 @@ from django.utils.safestring import mark_safe
|
|||||||
from django.forms.formsets import formset_factory
|
from django.forms.formsets import formset_factory
|
||||||
from django.template.defaultfilters import capfirst
|
from django.template.defaultfilters import capfirst
|
||||||
|
|
||||||
from staging import StagingFile
|
from documents.staging import StagingFile
|
||||||
|
|
||||||
from common.wizard import BoundFormWizard
|
from common.wizard import BoundFormWizard
|
||||||
from common.forms import DetailForm
|
from common.forms import DetailForm
|
||||||
|
|
||||||
from models import Document, DocumentType, DocumentTypeMetadataType, \
|
from documents.models import Document, DocumentType, DocumentTypeMetadataType, \
|
||||||
DocumentPage, DocumentPageTransformation
|
DocumentPage, DocumentPageTransformation
|
||||||
|
|
||||||
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
from documents.conf.settings import AVAILABLE_FUNCTIONS
|
||||||
@@ -62,7 +62,9 @@ class DocumentPageForm(DetailForm):
|
|||||||
'rotation': rotation
|
'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):
|
class DocumentPageForm_text(DetailForm):
|
||||||
@@ -72,9 +74,11 @@ class DocumentPageForm_text(DetailForm):
|
|||||||
|
|
||||||
content = forms.CharField(
|
content = forms.CharField(
|
||||||
label=_(u'Contents'),
|
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):
|
class DocumentPageForm_edit(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DocumentPage
|
model = DocumentPage
|
||||||
@@ -88,7 +92,9 @@ class DocumentPageForm_edit(forms.ModelForm):
|
|||||||
'page_label',
|
'page_label',
|
||||||
'content',
|
'content',
|
||||||
]
|
]
|
||||||
page_image = forms.CharField(required=False, widget=DocumentPageImageWidget())
|
page_image = forms.CharField(
|
||||||
|
required=False, widget=DocumentPageImageWidget()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ImageWidget(forms.widgets.Widget):
|
class ImageWidget(forms.widgets.Widget):
|
||||||
@@ -145,7 +151,9 @@ class DocumentForm(forms.ModelForm):
|
|||||||
model = Document
|
model = Document
|
||||||
exclude = ('description',)
|
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):
|
class DocumentPreviewForm(forms.Form):
|
||||||
@@ -173,7 +181,9 @@ class DocumentContentForm(forms.Form):
|
|||||||
|
|
||||||
contents = forms.CharField(
|
contents = forms.CharField(
|
||||||
label=_(u'Contents'),
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
super(StagingDocumentForm, self).__init__(*args, **kwargs)
|
super(StagingDocumentForm, self).__init__(*args, **kwargs)
|
||||||
try:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -207,7 +219,9 @@ class StagingDocumentForm(forms.Form):
|
|||||||
label=_(u'Quick document rename'))
|
label=_(u'Quick document rename'))
|
||||||
|
|
||||||
staging_file_id = forms.ChoiceField(label=_(u'Staging file'))
|
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):
|
class DocumentTypeSelectForm(forms.Form):
|
||||||
@@ -286,7 +300,9 @@ class DocumentCreateWizard(BoundFormWizard):
|
|||||||
|
|
||||||
def render_template(self, request, form, previous_fields, step, context=None):
|
def render_template(self, request, form, previous_fields, step, context=None):
|
||||||
context = {'step_title': self.extra_context['step_titles'][step]}
|
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):
|
def parse_params(self, request, *args, **kwargs):
|
||||||
self.extra_context = {'step_titles': self.step_titles}
|
self.extra_context = {'step_titles': self.step_titles}
|
||||||
@@ -331,7 +347,7 @@ class MetaDataImageWidget(forms.widgets.Widget):
|
|||||||
'action': reverse('metadatagroup_view', args=[value['current_document'].pk, value['group'].pk])
|
'action': reverse('metadatagroup_view', args=[value['current_document'].pk, value['group'].pk])
|
||||||
})
|
})
|
||||||
output.append(u'</div>')
|
output.append(u'</div>')
|
||||||
|
|
||||||
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
output.append(u'<div style="white-space:nowrap; overflow: auto;">')
|
||||||
for document in value['group_data']:
|
for document in value['group_data']:
|
||||||
output.append(
|
output.append(
|
||||||
@@ -363,7 +379,7 @@ class MetaDataImageWidget(forms.widgets.Widget):
|
|||||||
ugettext(u'Click on the image for full size view of the first page.'))
|
ugettext(u'Click on the image for full size view of the first page.'))
|
||||||
|
|
||||||
return mark_safe(u''.join(output))
|
return mark_safe(u''.join(output))
|
||||||
|
|
||||||
|
|
||||||
class MetaDataGroupForm(forms.Form):
|
class MetaDataGroupForm(forms.Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ from urllib import unquote_plus
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
|
|
||||||
|
from documents.models import DocumentMetadata, MetadataType
|
||||||
from models import DocumentMetadata, MetadataType
|
|
||||||
|
|
||||||
|
|
||||||
def decode_metadata_from_url(url_dict):
|
def decode_metadata_from_url(url_dict):
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
@@ -81,7 +79,7 @@ class Document(models.Model):
|
|||||||
|
|
||||||
@models.permalink
|
@models.permalink
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return ('document_view_simple', [self.id])
|
return ('document_view_simple', [self.pk])
|
||||||
|
|
||||||
def get_fullname(self):
|
def get_fullname(self):
|
||||||
return os.extsep.join([self.file_filename, self.file_extension])
|
return os.extsep.join([self.file_filename, self.file_extension])
|
||||||
@@ -276,7 +274,7 @@ class DocumentPage(models.Model):
|
|||||||
|
|
||||||
@models.permalink
|
@models.permalink
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return ('document_page_view', [self.id])
|
return ('document_page_view', [self.pk])
|
||||||
|
|
||||||
|
|
||||||
class MetadataGroupManager(models.Manager):
|
class MetadataGroupManager(models.Manager):
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from common.utils import pretty_size, pretty_size_10
|
from common.utils import pretty_size, pretty_size_10
|
||||||
from permissions.api import check_permissions
|
|
||||||
|
|
||||||
from documents.conf.settings import STORAGE_BACKEND
|
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):
|
def get_used_size(path, file_list):
|
||||||
total_size = 0
|
total_size = 0
|
||||||
for filename in file_list:
|
for filename in file_list:
|
||||||
try:
|
try:
|
||||||
total_size += STORAGE_BACKEND().size(STORAGE_BACKEND.separator.join([path, filename]))
|
total_size += STORAGE_BACKEND().size(STORAGE_BACKEND.separator.join([path, filename]))
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return total_size
|
return total_size
|
||||||
|
|
||||||
|
|
||||||
def storage_count(path=u'.'):
|
def storage_count(path=u'.'):
|
||||||
directories, files = STORAGE_BACKEND().listdir(path)
|
directories, files = STORAGE_BACKEND().listdir(path)
|
||||||
total_count = len(files)
|
total_count = len(files)
|
||||||
total_size = get_used_size(path, files)
|
total_size = get_used_size(path, files)
|
||||||
|
|
||||||
for directory in directories:
|
for directory in directories:
|
||||||
file_count, files_size = storage_count(directory)
|
file_count, files_size = storage_count(directory)
|
||||||
total_count += file_count
|
total_count += file_count
|
||||||
@@ -31,31 +31,30 @@ def storage_count(path=u'.'):
|
|||||||
|
|
||||||
|
|
||||||
def get_statistics():
|
def get_statistics():
|
||||||
total_db_documents = Document.objects.only('id',).count()
|
total_db_documents = Document.objects.only('pk',).count()
|
||||||
|
|
||||||
paragraphs = [
|
paragraphs = [
|
||||||
_(u'Document types: %d') % DocumentType.objects.count(),
|
_(u'Document types: %d') % DocumentType.objects.count(),
|
||||||
_(u'Documents in database: %d') % total_db_documents,
|
_(u'Documents in database: %d') % total_db_documents,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
total_storage_documents, storage_used_space = storage_count()
|
total_storage_documents, storage_used_space = storage_count()
|
||||||
paragraphs.append(_(u'Documents in storage: %d') %
|
paragraphs.append(_(u'Documents in storage: %d') %
|
||||||
total_storage_documents)
|
total_storage_documents)
|
||||||
paragraphs.append(_(u'Space used in storage: %(base_2)s (base 2), %(base_10)s (base 10), %(bytes)d bytes') % {
|
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_2': pretty_size(storage_used_space),
|
||||||
'base_10':pretty_size_10(storage_used_space),
|
'base_10': pretty_size_10(storage_used_space),
|
||||||
'bytes':storage_used_space
|
'bytes': storage_used_space
|
||||||
})
|
})
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
paragraphs.append(
|
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 {
|
return {
|
||||||
'title':_(u'Document statistics'),
|
'title': _(u'Document statistics'),
|
||||||
'paragraphs': paragraphs
|
'paragraphs': paragraphs
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
from django.conf.urls.defaults import patterns, url
|
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 PREVIEW_SIZE
|
||||||
from documents.conf.settings import THUMBNAIL_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
|
from converter.api import QUALITY_HIGH
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = patterns('documents.views',
|
urlpatterns = patterns('documents.views',
|
||||||
url(r'^document/list/$', 'document_list', (), 'document_list'),
|
url(r'^document/list/$', 'document_list', (), 'document_list'),
|
||||||
url(r'^document/list/recent/$', 'document_list_recent', (), 'document_list_recent'),
|
url(r'^document/list/recent/$', 'document_list_recent', (), 'document_list_recent'),
|
||||||
@@ -57,7 +54,7 @@ urlpatterns = patterns('documents.views',
|
|||||||
|
|
||||||
url(r'^document/page/(?P<document_page_id>\d+)/transformation/list/$', 'document_page_transformation_list', (), 'document_page_transformation_list'),
|
url(r'^document/page/(?P<document_page_id>\d+)/transformation/list/$', 'document_page_transformation_list', (), 'document_page_transformation_list'),
|
||||||
url(r'^document/page/(?P<document_page_id>\d+)/transformation/create/$', 'document_page_transformation_create', (), 'document_page_transformation_create'),
|
url(r'^document/page/(?P<document_page_id>\d+)/transformation/create/$', 'document_page_transformation_create', (), 'document_page_transformation_create'),
|
||||||
|
|
||||||
url(r'^document/page/transformation/(?P<document_page_transformation_id>\d+)/edit/$', 'document_page_transformation_edit', (), 'document_page_transformation_edit'),
|
url(r'^document/page/transformation/(?P<document_page_transformation_id>\d+)/edit/$', 'document_page_transformation_edit', (), 'document_page_transformation_edit'),
|
||||||
url(r'^document/page/transformation/(?P<document_page_transformation_id>\d+)/delete/$', 'document_page_transformation_delete', (), 'document_page_transformation_delete'),
|
url(r'^document/page/transformation/(?P<document_page_transformation_id>\d+)/delete/$', 'document_page_transformation_delete', (), 'document_page_transformation_delete'),
|
||||||
|
|
||||||
|
|||||||
+65
-57
@@ -3,14 +3,13 @@ import urlparse
|
|||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from django.utils.translation import ugettext as _
|
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.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib import messages
|
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.core.urlresolvers import reverse
|
||||||
from django.views.generic.create_update import create_object, delete_object, update_object
|
from django.views.generic.create_update import delete_object, update_object
|
||||||
from django.core.files.base import File
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
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 USE_STAGING_DIRECTORY
|
||||||
from documents.conf.settings import PREVIEW_SIZE
|
from documents.conf.settings import PREVIEW_SIZE
|
||||||
from documents.conf.settings import THUMBNAIL_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 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_LOCAL_FILES
|
||||||
from documents.conf.settings import UNCOMPRESS_COMPRESSED_STAGING_FILES
|
from documents.conf.settings import UNCOMPRESS_COMPRESSED_STAGING_FILES
|
||||||
from documents.conf.settings import STORAGE_BACKEND
|
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_CREATE, PERMISSION_DOCUMENT_PROPERTIES_EDIT, \
|
||||||
PERMISSION_DOCUMENT_METADATA_EDIT, PERMISSION_DOCUMENT_VIEW, \
|
PERMISSION_DOCUMENT_METADATA_EDIT, PERMISSION_DOCUMENT_VIEW, \
|
||||||
PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD, \
|
PERMISSION_DOCUMENT_DELETE, PERMISSION_DOCUMENT_DOWNLOAD, \
|
||||||
PERMISSION_DOCUMENT_TRANSFORM, PERMISSION_DOCUMENT_TOOLS, \
|
PERMISSION_DOCUMENT_TRANSFORM, \
|
||||||
PERMISSION_DOCUMENT_EDIT
|
PERMISSION_DOCUMENT_EDIT
|
||||||
|
|
||||||
from forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
from documents.forms import DocumentTypeSelectForm, DocumentCreateWizard, \
|
||||||
MetadataForm, DocumentForm, DocumentForm_edit, DocumentForm_view, \
|
DocumentForm, DocumentForm_edit, DocumentForm_view, \
|
||||||
StagingDocumentForm, DocumentTypeMetadataType, DocumentPreviewForm, \
|
StagingDocumentForm, DocumentTypeMetadataType, DocumentPreviewForm, \
|
||||||
MetadataFormSet, DocumentPageForm, DocumentPageTransformationForm, \
|
MetadataFormSet, DocumentPageForm, DocumentPageTransformationForm, \
|
||||||
DocumentContentForm, DocumentPageForm_edit, MetaDataGroupForm, \
|
DocumentContentForm, DocumentPageForm_edit, MetaDataGroupForm, \
|
||||||
DocumentPageForm_text
|
DocumentPageForm_text
|
||||||
|
|
||||||
from metadata import save_metadata_list, \
|
from documents.metadata import save_metadata_list, \
|
||||||
decode_metadata_from_url, metadata_repr_as_list
|
decode_metadata_from_url, metadata_repr_as_list
|
||||||
from models import Document, DocumentMetadata, DocumentType, MetadataType, \
|
from documents.models import Document, DocumentType, DocumentPage, \
|
||||||
DocumentPage, DocumentPageTransformation, RecentDocument, \
|
DocumentPageTransformation, RecentDocument, MetadataGroup
|
||||||
MetadataGroup
|
from documents.staging import StagingFile
|
||||||
from staging import StagingFile
|
from documents.utils import document_save_to_temp_dir
|
||||||
from utils import document_save_to_temp_dir
|
|
||||||
from documents import metadata_group_link
|
from documents import metadata_group_link
|
||||||
|
|
||||||
PICTURE_ERROR_SMALL = u'picture_error.png'
|
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)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
urldata = []
|
urldata = []
|
||||||
for id, metadata in enumerate(document.documentmetadata_set.all()):
|
for pk, metadata in enumerate(document.documentmetadata_set.all()):
|
||||||
if hasattr(metadata, 'value'):
|
if hasattr(metadata, 'value'):
|
||||||
urldata.append(('metadata%s_id' % id, metadata.metadata_type_id))
|
urldata.append(('metadata%s_id' % pk, metadata.metadata_type_id))
|
||||||
urldata.append(('metadata%s_value' % id, metadata.value))
|
urldata.append(('metadata%s_value' % pk, metadata.value))
|
||||||
|
|
||||||
if multiple:
|
if multiple:
|
||||||
view = 'upload_multiple_documents_with_type'
|
view = 'upload_multiple_documents_with_type'
|
||||||
@@ -314,13 +310,14 @@ def document_view(request, document_id):
|
|||||||
#If GROUP_SHOW_EMPTY is False, remove empty groups from
|
#If GROUP_SHOW_EMPTY is False, remove empty groups from
|
||||||
#dictionary
|
#dictionary
|
||||||
metadata_groups = dict([(group, data) for group, data in metadata_groups.items() if data])
|
metadata_groups = dict([(group, data) for group, data in metadata_groups.items() if data])
|
||||||
|
|
||||||
if metadata_groups:
|
if metadata_groups:
|
||||||
subtemplates_dict.append(
|
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=[
|
'form': MetaDataGroupForm(groups=metadata_groups, current_document=document, links=[
|
||||||
metadata_group_link]),
|
metadata_group_link
|
||||||
|
]),
|
||||||
'name': 'generic_form_subtemplate.html',
|
'name': 'generic_form_subtemplate.html',
|
||||||
'form_action': reverse('metadatagroup_action'),
|
'form_action': reverse('metadatagroup_action'),
|
||||||
'submit_method': 'GET',
|
'submit_method': 'GET',
|
||||||
@@ -332,8 +329,9 @@ def document_view(request, document_id):
|
|||||||
'name': 'generic_list_subtemplate.html',
|
'name': 'generic_list_subtemplate.html',
|
||||||
'title': _(u'index links'),
|
'title': _(u'index links'),
|
||||||
'object_list': document.documentmetadataindex_set.all(),
|
'object_list': document.documentmetadataindex_set.all(),
|
||||||
'hide_link': True})
|
'hide_link': True
|
||||||
|
})
|
||||||
|
|
||||||
return render_to_response('generic_detail.html', {
|
return render_to_response('generic_detail.html', {
|
||||||
'form_list': form_list,
|
'form_list': form_list,
|
||||||
'object': document,
|
'object': document,
|
||||||
@@ -365,7 +363,8 @@ def document_delete(request, document_id=None, document_id_list=None):
|
|||||||
messages.success(request, _(u'Document: %s deleted successfully.') % document)
|
messages.success(request, _(u'Document: %s deleted successfully.') % document)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
messages.error(request, _(u'Document: %(document)s delete error: %(error)s') % {
|
messages.error(request, _(u'Document: %(document)s delete error: %(error)s') % {
|
||||||
'document': document, 'error': e})
|
'document': document, 'error': e
|
||||||
|
})
|
||||||
|
|
||||||
return HttpResponseRedirect(next)
|
return HttpResponseRedirect(next)
|
||||||
|
|
||||||
@@ -386,11 +385,15 @@ def document_delete(request, document_id=None, document_id_list=None):
|
|||||||
|
|
||||||
|
|
||||||
def document_multiple_delete(request):
|
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):
|
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)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
|
|
||||||
@@ -456,7 +459,7 @@ def document_edit_metadata(request, document_id=None, document_id_list=None):
|
|||||||
metadata = {}
|
metadata = {}
|
||||||
for document in documents:
|
for document in documents:
|
||||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||||
|
|
||||||
for item in DocumentTypeMetadataType.objects.filter(document_type=document.document_type):
|
for item in DocumentTypeMetadataType.objects.filter(document_type=document.document_type):
|
||||||
value = document.documentmetadata_set.get(metadata_type=item.metadata_type).value if document.documentmetadata_set.filter(metadata_type=item.metadata_type) else u''
|
value = document.documentmetadata_set.get(metadata_type=item.metadata_type).value if document.documentmetadata_set.filter(metadata_type=item.metadata_type) else u''
|
||||||
if item.metadata_type in metadata:
|
if item.metadata_type in metadata:
|
||||||
@@ -548,24 +551,24 @@ def get_document_image(request, document_id, size=PREVIEW_SIZE, quality=QUALITY_
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
tranformation_string = ' '.join(transformation_list)
|
tranformation_string = ' '.join(transformation_list)
|
||||||
|
|
||||||
zoom = int(request.GET.get('zoom', 100))
|
zoom = int(request.GET.get('zoom', 100))
|
||||||
|
|
||||||
if zoom < ZOOM_MIN_LEVEL:
|
if zoom < ZOOM_MIN_LEVEL:
|
||||||
zoom = ZOOM_MIN_LEVEL
|
zoom = ZOOM_MIN_LEVEL
|
||||||
|
|
||||||
if zoom > ZOOM_MAX_LEVEL:
|
if zoom > ZOOM_MAX_LEVEL:
|
||||||
zoom = ZOOM_MAX_LEVEL
|
zoom = ZOOM_MAX_LEVEL
|
||||||
|
|
||||||
rotation = int(request.GET.get('rotation', 0)) % 360
|
rotation = int(request.GET.get('rotation', 0)) % 360
|
||||||
|
|
||||||
try:
|
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:
|
if filepath:
|
||||||
return sendfile.sendfile(request, filename=filepath)
|
return sendfile.sendfile(request, filename=filepath)
|
||||||
#Save to a temporary location
|
#Save to a temporary location
|
||||||
filepath = document_save_to_temp_dir(document, filename=document.checksum)
|
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)
|
return sendfile.sendfile(request, filename=output_file)
|
||||||
except UnkownConvertError, e:
|
except UnkownConvertError, e:
|
||||||
if request.user.is_staff or request.user.is_superuser:
|
if request.user.is_staff or request.user.is_superuser:
|
||||||
@@ -611,9 +614,10 @@ def staging_file_preview(request, staging_file_id):
|
|||||||
try:
|
try:
|
||||||
output_file, errors = StagingFile.get(staging_file_id).preview()
|
output_file, errors = StagingFile.get(staging_file_id).preview()
|
||||||
if errors and (request.user.is_staff or request.user.is_superuser):
|
if errors and (request.user.is_staff or request.user.is_superuser):
|
||||||
messages.warning(request, _(u'Error for transformation %(transformation)s:, %(error)s') %
|
for error in errors:
|
||||||
{'transformation': page_transformation.get_transformation_display(),
|
messages.warning(request, _(u'Staging file transformation error:, %(error)s') % {
|
||||||
'error': e})
|
'error': error
|
||||||
|
})
|
||||||
|
|
||||||
return sendfile.sendfile(request, filename=output_file)
|
return sendfile.sendfile(request, filename=output_file)
|
||||||
except UnkownConvertError, e:
|
except UnkownConvertError, e:
|
||||||
@@ -827,9 +831,9 @@ def document_view_simple(request, document_id):
|
|||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
||||||
|
|
||||||
document = get_object_or_404(Document.objects.select_related(), pk=document_id)
|
document = get_object_or_404(Document.objects.select_related(), pk=document_id)
|
||||||
|
|
||||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||||
|
|
||||||
content_form = DocumentContentForm(document=document)
|
content_form = DocumentContentForm(document=document)
|
||||||
|
|
||||||
preview_form = DocumentPreviewForm(document=document)
|
preview_form = DocumentPreviewForm(document=document)
|
||||||
@@ -864,19 +868,23 @@ def document_view_simple(request, document_id):
|
|||||||
#If GROUP_SHOW_EMPTY is False, remove empty groups from
|
#If GROUP_SHOW_EMPTY is False, remove empty groups from
|
||||||
#dictionary
|
#dictionary
|
||||||
metadata_groups = dict([(group, data) for group, data in metadata_groups.items() if data])
|
metadata_groups = dict([(group, data) for group, data in metadata_groups.items() if data])
|
||||||
|
|
||||||
if metadata_groups:
|
if metadata_groups:
|
||||||
subtemplates_dict.append(
|
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=[
|
'form': MetaDataGroupForm(
|
||||||
metadata_group_link]),
|
groups=metadata_groups, current_document=document,
|
||||||
|
links=[
|
||||||
|
metadata_group_link
|
||||||
|
]
|
||||||
|
),
|
||||||
'name': 'generic_form_subtemplate.html',
|
'name': 'generic_form_subtemplate.html',
|
||||||
'form_action': reverse('metadatagroup_action'),
|
'form_action': reverse('metadatagroup_action'),
|
||||||
'submit_method': 'GET',
|
'submit_method': 'GET',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_to_response('generic_detail.html', {
|
return render_to_response('generic_detail.html', {
|
||||||
'form_list': form_list,
|
'form_list': form_list,
|
||||||
'object': document,
|
'object': document,
|
||||||
@@ -914,7 +922,7 @@ def document_page_view(request, document_page_id):
|
|||||||
zoom = int(request.GET.get('zoom', 100))
|
zoom = int(request.GET.get('zoom', 100))
|
||||||
rotation = int(request.GET.get('rotation', 0))
|
rotation = int(request.GET.get('rotation', 0))
|
||||||
document_page_form = DocumentPageForm(instance=document_page, zoom=zoom, rotation=rotation)
|
document_page_form = DocumentPageForm(instance=document_page, zoom=zoom, rotation=rotation)
|
||||||
|
|
||||||
form_list = [
|
form_list = [
|
||||||
{
|
{
|
||||||
'form': document_page_form,
|
'form': document_page_form,
|
||||||
@@ -926,7 +934,7 @@ def document_page_view(request, document_page_id):
|
|||||||
'object': document_page,
|
'object': document_page,
|
||||||
'web_theme_hide_menus': True,
|
'web_theme_hide_menus': True,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def document_page_text(request, document_page_id):
|
def document_page_text(request, document_page_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
||||||
@@ -945,8 +953,8 @@ def document_page_text(request, document_page_id):
|
|||||||
'object': document_page,
|
'object': document_page,
|
||||||
'web_theme_hide_menus': True,
|
'web_theme_hide_menus': True,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def document_page_edit(request, document_page_id):
|
def document_page_edit(request, document_page_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_EDIT])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_EDIT])
|
||||||
|
|
||||||
@@ -983,7 +991,7 @@ def document_page_navigation_next(request, document_page_id):
|
|||||||
document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number + 1)
|
document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number + 1)
|
||||||
return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
|
return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
|
||||||
|
|
||||||
|
|
||||||
def document_page_navigation_previous(request, document_page_id):
|
def document_page_navigation_previous(request, document_page_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
||||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path)
|
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path)
|
||||||
@@ -996,7 +1004,7 @@ def document_page_navigation_previous(request, document_page_id):
|
|||||||
document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number - 1)
|
document_page = get_object_or_404(DocumentPage, document=document_page.document, page_number=document_page.page_number - 1)
|
||||||
return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
|
return HttpResponseRedirect(reverse(view, args=[document_page.pk]))
|
||||||
|
|
||||||
|
|
||||||
def document_page_navigation_first(request, document_page_id):
|
def document_page_navigation_first(request, document_page_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
||||||
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path)
|
view = resolve_to_name(urlparse.urlparse(request.META.get('HTTP_REFERER', '/')).path)
|
||||||
@@ -1037,7 +1045,7 @@ def transform_page(request, document_page_id, zoom_function=None, rotation_funct
|
|||||||
# parse_qs return a dictionary whose values are lists
|
# parse_qs return a dictionary whose values are lists
|
||||||
zoom = int(urlparse.parse_qs(query).get('zoom', ['100'])[0])
|
zoom = int(urlparse.parse_qs(query).get('zoom', ['100'])[0])
|
||||||
rotation = int(urlparse.parse_qs(query).get('rotation', ['0'])[0])
|
rotation = int(urlparse.parse_qs(query).get('rotation', ['0'])[0])
|
||||||
|
|
||||||
if zoom_function:
|
if zoom_function:
|
||||||
zoom = zoom_function(zoom)
|
zoom = zoom_function(zoom)
|
||||||
|
|
||||||
@@ -1056,23 +1064,23 @@ def document_page_zoom_in(request, document_page_id):
|
|||||||
return transform_page(
|
return transform_page(
|
||||||
request,
|
request,
|
||||||
document_page_id,
|
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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def document_page_zoom_out(request, document_page_id):
|
def document_page_zoom_out(request, document_page_id):
|
||||||
return transform_page(
|
return transform_page(
|
||||||
request,
|
request,
|
||||||
document_page_id,
|
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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def document_page_rotate_right(request, document_page_id):
|
def document_page_rotate_right(request, document_page_id):
|
||||||
return transform_page(
|
return transform_page(
|
||||||
request,
|
request,
|
||||||
document_page_id,
|
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(
|
return transform_page(
|
||||||
request,
|
request,
|
||||||
document_page_id,
|
document_page_id,
|
||||||
rotation_function = lambda x: (x - ROTATION_STEP) % 360
|
rotation_function=lambda x: (x - ROTATION_STEP) % 360
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1101,7 +1109,7 @@ def metadatagroup_view(request, document_id, metadata_group_id):
|
|||||||
metadata_group = get_object_or_404(MetadataGroup, pk=metadata_group_id)
|
metadata_group = get_object_or_404(MetadataGroup, pk=metadata_group_id)
|
||||||
|
|
||||||
object_list, errors = document.get_metadata_groups(metadata_group)
|
object_list, errors = document.get_metadata_groups(metadata_group)
|
||||||
|
|
||||||
return render_to_response('generic_list.html', {
|
return render_to_response('generic_list.html', {
|
||||||
'object_list': object_list,
|
'object_list': object_list,
|
||||||
'title': _(u'documents in group: %s, for document: %s') % (metadata_group, document),
|
'title': _(u'documents in group: %s, for document: %s') % (metadata_group, document),
|
||||||
|
|||||||
+12
-12
@@ -1,10 +1,13 @@
|
|||||||
|
# original code from:
|
||||||
|
# http://www.julienphalip.com/blog/2008/08/16/adding-search-django-site-snap/
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import types
|
import types
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from conf.settings import LIMIT
|
from dynamic_search.conf.settings import LIMIT
|
||||||
|
|
||||||
search_list = {}
|
search_list = {}
|
||||||
|
|
||||||
@@ -15,29 +18,26 @@ def register(model, text, field_list):
|
|||||||
else:
|
else:
|
||||||
search_list[model] = {'fields': field_list, 'text': text}
|
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,
|
def normalize_query(query_string,
|
||||||
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
|
findterms=re.compile(r'"([^"]+)"|(\S+)').findall,
|
||||||
normspace=re.compile(r'\s{2,}').sub):
|
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.
|
and grouping quoted words together.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
>>> normalize_query(' some random words "with quotes " and spaces')
|
>>> normalize_query(' some random words "with quotes " and spaces')
|
||||||
['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)]
|
return [normspace(' ', (t[0] or t[1]).strip()) for t in findterms(query_string)]
|
||||||
|
|
||||||
|
|
||||||
def get_query(query_string, terms, search_fields):
|
def get_query(terms, search_fields):
|
||||||
''' Returns a query, that is a combination of Q objects. That combination
|
"""
|
||||||
|
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.
|
aims to search keywords within a model by testing the given search fields.
|
||||||
|
"""
|
||||||
'''
|
|
||||||
queries = []
|
queries = []
|
||||||
for term in terms:
|
for term in terms:
|
||||||
or_query = None
|
or_query = None
|
||||||
@@ -47,7 +47,7 @@ def get_query(query_string, terms, search_fields):
|
|||||||
field_name = field
|
field_name = field
|
||||||
elif isinstance(field, types.DictType):
|
elif isinstance(field, types.DictType):
|
||||||
comparison = field.get('comparison', u'icontains')
|
comparison = field.get('comparison', u'icontains')
|
||||||
field_name = field.get('field_name', '')
|
field_name = field.get('field_name', u'')
|
||||||
|
|
||||||
if field_name:
|
if field_name:
|
||||||
q = Q(**{'%s__%s' % (field_name, comparison): term})
|
q = Q(**{'%s__%s' % (field_name, comparison): term})
|
||||||
@@ -72,7 +72,7 @@ def perform_search(query_string):
|
|||||||
terms = normalize_query(query_string)
|
terms = normalize_query(query_string)
|
||||||
|
|
||||||
for model, data in search_list.items():
|
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
|
model_result_ids = None
|
||||||
for query in queries:
|
for query in queries:
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ from django.utils.translation import ugettext as _
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from api import perform_search
|
from dynamic_search.api import perform_search
|
||||||
from forms import SearchForm
|
from dynamic_search.forms import SearchForm
|
||||||
from conf.settings import SHOW_OBJECT_TYPE
|
from dynamic_search.conf.settings import SHOW_OBJECT_TYPE
|
||||||
|
|
||||||
|
|
||||||
def results(request, form=None):
|
def results(request, form=None):
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ from permissions.api import register_permissions
|
|||||||
FILESYSTEM_SERVING_RECREATE_LINKS = 'recreate_links'
|
FILESYSTEM_SERVING_RECREATE_LINKS = 'recreate_links'
|
||||||
|
|
||||||
register_permissions('filesystem_serving', [
|
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 django.contrib import admin
|
||||||
|
|
||||||
from models import DocumentMetadataIndex
|
from filesystem_serving.models import DocumentMetadataIndex
|
||||||
|
|
||||||
|
|
||||||
class DocumentMetadataIndexInline(admin.StackedInline):
|
class DocumentMetadataIndexInline(admin.StackedInline):
|
||||||
model = DocumentMetadataIndex
|
model = DocumentMetadataIndex
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import errno
|
import errno
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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 SLUGIFY_PATHS
|
||||||
from filesystem_serving.conf.settings import MAX_RENAME_COUNT
|
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:
|
if SLUGIFY_PATHS == False:
|
||||||
#Do not slugify path or filenames and extensions
|
#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.template import RequestContext
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
|
||||||
|
|
||||||
from permissions.api import check_permissions
|
from permissions.api import check_permissions
|
||||||
|
|
||||||
|
|
||||||
from filesystem_serving import FILESYSTEM_SERVING_RECREATE_LINKS
|
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):
|
def recreate_all_links(request):
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from navigation.api import register_links, register_menu, \
|
|||||||
from permissions.api import register_permissions
|
from permissions.api import register_permissions
|
||||||
from navigation.api import register_sidebar_template
|
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_list = {'text': _(u'folder list'), 'view': 'folder_list', 'famfam': 'folder'}
|
||||||
folder_create = {'text': _('create folder'), 'view': 'folder_create', 'famfam': 'folder_add'}
|
folder_create = {'text': _('create folder'), 'view': 'folder_create', 'famfam': 'folder_add'}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from models import Folder, FolderDocument
|
from folders.models import Folder, FolderDocument
|
||||||
|
|
||||||
|
|
||||||
class FolderDocumentInline(admin.StackedInline):
|
class FolderDocumentInline(admin.StackedInline):
|
||||||
@@ -8,10 +8,10 @@ class FolderDocumentInline(admin.StackedInline):
|
|||||||
extra = 1
|
extra = 1
|
||||||
classes = ('collapse-open',)
|
classes = ('collapse-open',)
|
||||||
allow_add = True
|
allow_add = True
|
||||||
|
|
||||||
|
|
||||||
class FolderAdmin(admin.ModelAdmin):
|
class FolderAdmin(admin.ModelAdmin):
|
||||||
inlines = [FolderDocumentInline]
|
inlines = [FolderDocumentInline]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Folder, FolderAdmin)
|
admin.site.register(Folder, FolderAdmin)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from models import Folder
|
from folders.models import Folder
|
||||||
|
|
||||||
|
|
||||||
class FolderForm(forms.ModelForm):
|
class FolderForm(forms.ModelForm):
|
||||||
@@ -17,9 +17,7 @@ class AddDocumentForm(forms.ModelForm):
|
|||||||
self.fields['existing_folder'] = forms.ModelChoiceField(required=False, queryset=Folder.objects.filter(user=user))
|
self.fields['existing_folder'] = forms.ModelChoiceField(required=False, queryset=Folder.objects.filter(user=user))
|
||||||
self.fields['title'].required = False
|
self.fields['title'].required = False
|
||||||
self.fields['title'].label = _(u'New folder')
|
self.fields['title'].label = _(u'New folder')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Folder
|
model = Folder
|
||||||
fields = ('title',)
|
fields = ('title',)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Folder(models.Model):
|
|||||||
title = models.CharField(max_length=32, verbose_name=_(u'title'), db_index=True)
|
title = models.CharField(max_length=32, verbose_name=_(u'title'), db_index=True)
|
||||||
user = models.ForeignKey(User, verbose_name=_(u'user'))
|
user = models.ForeignKey(User, verbose_name=_(u'user'))
|
||||||
datetime_created = models.DateTimeField(verbose_name=_(u'datetime created'))
|
datetime_created = models.DateTimeField(verbose_name=_(u'datetime created'))
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
@@ -29,12 +29,12 @@ class Folder(models.Model):
|
|||||||
ordering = ('title',)
|
ordering = ('title',)
|
||||||
verbose_name = _(u'folder')
|
verbose_name = _(u'folder')
|
||||||
verbose_name_plural = _(u'folders')
|
verbose_name_plural = _(u'folders')
|
||||||
|
|
||||||
|
|
||||||
class FolderDocument(models.Model):
|
class FolderDocument(models.Model):
|
||||||
folder = models.ForeignKey(Folder, verbose_name=_('folder'))
|
folder = models.ForeignKey(Folder, verbose_name=_('folder'))
|
||||||
document = models.ForeignKey(Document, verbose_name=_('document'))
|
document = models.ForeignKey(Document, verbose_name=_('document'))
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(self.document)
|
return unicode(self.document)
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
from django.core.urlresolvers import reverse
|
||||||
from django.template import TemplateSyntaxError, Library, \
|
from django.template import Library
|
||||||
VariableDoesNotExist, Node, Variable
|
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from folders.forms import AddDocumentForm
|
from folders.forms import AddDocumentForm
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('generic_form_subtemplate.html', takes_context=True)
|
@register.inclusion_tag('generic_form_subtemplate.html', takes_context=True)
|
||||||
def get_add_document_to_folder_form(context):
|
def get_add_document_to_folder_form(context):
|
||||||
context.update({
|
context.update({
|
||||||
'form': AddDocumentForm(user=context['request'].user),
|
'form': AddDocumentForm(user=context['request'].user),
|
||||||
'request': context['request'],
|
'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')
|
'title': _('Add document to a folder')
|
||||||
})
|
})
|
||||||
return context
|
return context
|
||||||
|
|||||||
+12
-13
@@ -1,19 +1,18 @@
|
|||||||
from django.utils.translation import ugettext as _
|
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.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.contrib import messages
|
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.core.urlresolvers import reverse
|
||||||
from django.views.generic.create_update import create_object, delete_object, update_object
|
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
from documents import PERMISSION_DOCUMENT_VIEW
|
from documents import PERMISSION_DOCUMENT_VIEW
|
||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
from permissions.api import check_permissions
|
from permissions.api import check_permissions
|
||||||
|
|
||||||
from models import Folder, FolderDocument
|
from folders.models import Folder, FolderDocument
|
||||||
from forms import FolderForm, AddDocumentForm
|
from folders.forms import FolderForm, AddDocumentForm
|
||||||
|
|
||||||
|
|
||||||
def folder_list(request):
|
def folder_list(request):
|
||||||
@@ -44,7 +43,7 @@ def folder_create(request):
|
|||||||
messages.error(request, _(u'A folder named: %s, already exists.') % form.cleaned_data['title'])
|
messages.error(request, _(u'A folder named: %s, already exists.') % form.cleaned_data['title'])
|
||||||
else:
|
else:
|
||||||
form = FolderForm()
|
form = FolderForm()
|
||||||
|
|
||||||
return render_to_response('generic_form.html', {
|
return render_to_response('generic_form.html', {
|
||||||
'title': _(u'create folder'),
|
'title': _(u'create folder'),
|
||||||
'form': form,
|
'form': form,
|
||||||
@@ -61,7 +60,7 @@ def folder_edit(request, folder_id):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = FolderForm(request.POST)
|
form = FolderForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
folder.title=form.cleaned_data['title']
|
folder.title = form.cleaned_data['title']
|
||||||
try:
|
try:
|
||||||
folder.save()
|
folder.save()
|
||||||
messages.success(request, _(u'Folder edited successfully'))
|
messages.success(request, _(u'Folder edited successfully'))
|
||||||
@@ -70,7 +69,7 @@ def folder_edit(request, folder_id):
|
|||||||
messages.error(request, _(u'Error editing folder; %s') % e)
|
messages.error(request, _(u'Error editing folder; %s') % e)
|
||||||
else:
|
else:
|
||||||
form = FolderForm(instance=folder)
|
form = FolderForm(instance=folder)
|
||||||
|
|
||||||
return render_to_response('generic_form.html', {
|
return render_to_response('generic_form.html', {
|
||||||
'title': _(u'edit folder: %s') % folder,
|
'title': _(u'edit folder: %s') % folder,
|
||||||
'form': form,
|
'form': form,
|
||||||
@@ -115,10 +114,10 @@ def folder_delete(request, folder_id):
|
|||||||
|
|
||||||
def folder_view(request, folder_id):
|
def folder_view(request, folder_id):
|
||||||
folder = get_object_or_404(Folder, pk=folder_id)
|
folder = get_object_or_404(Folder, pk=folder_id)
|
||||||
|
|
||||||
if not request.user.is_staff and not request.user.is_superuser and not request.user == folder.user:
|
if not request.user.is_staff and not request.user.is_superuser and not request.user == folder.user:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
||||||
return render_to_response('generic_list.html', {
|
return render_to_response('generic_list.html', {
|
||||||
'object_list': folder.folderdocument_set.all(),
|
'object_list': folder.folderdocument_set.all(),
|
||||||
'extra_columns': [
|
'extra_columns': [
|
||||||
@@ -137,8 +136,8 @@ def folder_view(request, folder_id):
|
|||||||
'object': folder,
|
'object': folder,
|
||||||
'object_name': _(u'folder'),
|
'object_name': _(u'folder'),
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def folder_add_document(request, document_id):
|
def folder_add_document(request, document_id):
|
||||||
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
|
||||||
document = get_object_or_404(Document, pk=document_id)
|
document = get_object_or_404(Document, pk=document_id)
|
||||||
@@ -173,7 +172,7 @@ def folder_add_document(request, document_id):
|
|||||||
|
|
||||||
def folder_document_remove(request, folder_document_id=None, folder_document_id_list=None):
|
def folder_document_remove(request, folder_document_id=None, folder_document_id_list=None):
|
||||||
post_action_redirect = None
|
post_action_redirect = None
|
||||||
|
|
||||||
if folder_document_id:
|
if folder_document_id:
|
||||||
folder_documents = [get_object_or_404(FolderDocument, pk=folder_document_id)]
|
folder_documents = [get_object_or_404(FolderDocument, pk=folder_document_id)]
|
||||||
elif folder_document_id_list:
|
elif folder_document_id_list:
|
||||||
|
|||||||
+5
-3
@@ -29,7 +29,7 @@ def check_settings(request):
|
|||||||
{'name': 'MAIN_SIDE_BAR_SEARCH',
|
{'name': 'MAIN_SIDE_BAR_SEARCH',
|
||||||
'value': main_settings.SIDE_BAR_SEARCH,
|
'value': main_settings.SIDE_BAR_SEARCH,
|
||||||
'description': main_settings.setting_description},
|
'description': main_settings.setting_description},
|
||||||
|
|
||||||
{'name': 'DOCUMENTS_METADATA_AVAILABLE_FUNCTIONS', 'value': documents_settings.AVAILABLE_FUNCTIONS},
|
{'name': 'DOCUMENTS_METADATA_AVAILABLE_FUNCTIONS', 'value': documents_settings.AVAILABLE_FUNCTIONS},
|
||||||
{'name': 'DOCUMENTS_METADATA_AVAILABLE_MODELS', 'value': documents_settings.AVAILABLE_MODELS},
|
{'name': 'DOCUMENTS_METADATA_AVAILABLE_MODELS', 'value': documents_settings.AVAILABLE_MODELS},
|
||||||
{'name': 'DOCUMENTS_INDEXING_AVAILABLE_INDEXING_FUNCTIONS', 'value': documents_settings.AVAILABLE_INDEXING_FUNCTIONS},
|
{'name': 'DOCUMENTS_INDEXING_AVAILABLE_INDEXING_FUNCTIONS', 'value': documents_settings.AVAILABLE_INDEXING_FUNCTIONS},
|
||||||
@@ -151,12 +151,14 @@ def statistics(request):
|
|||||||
|
|
||||||
return render_to_response('statistics.html', {
|
return render_to_response('statistics.html', {
|
||||||
'blocks': blocks,
|
'blocks': blocks,
|
||||||
'title': _(u'Statistics') },
|
'title': _(u'Statistics')
|
||||||
|
},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
def diagnostics_view(request):
|
def diagnostics_view(request):
|
||||||
return render_to_response('diagnostics.html', {
|
return render_to_response('diagnostics.html', {
|
||||||
'blocks': diagnostics,
|
'blocks': diagnostics,
|
||||||
'title': _(u'Diagnostics') },
|
'title': _(u'Diagnostics')
|
||||||
|
},
|
||||||
context_instance=RequestContext(request))
|
context_instance=RequestContext(request))
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ def register_model_list_columns(model, columns):
|
|||||||
model_list_columns[model].extend(columns)
|
model_list_columns[model].extend(columns)
|
||||||
else:
|
else:
|
||||||
model_list_columns[model] = copy.copy(columns)
|
model_list_columns[model] = copy.copy(columns)
|
||||||
|
|
||||||
|
|
||||||
def register_sidebar_template(source_list, template_name):
|
def register_sidebar_template(source_list, template_name):
|
||||||
for source in source_list:
|
for source in source_list:
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class NavigationNode(Node):
|
|||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
def main_navigation(parser, token):
|
def main_navigation(parser, token):
|
||||||
args = token.split_contents()
|
#args = token.split_contents()
|
||||||
|
|
||||||
# if len(args) != 3 or args[1] != 'as':
|
# if len(args) != 3 or args[1] != 'as':
|
||||||
# raise TemplateSyntaxError("'get_all_states' requires 'as variable' (got %r)" % args)
|
# 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 documents.models import Document
|
||||||
|
|
||||||
from ocr.conf.settings import AUTOMATIC_OCR
|
from ocr.conf.settings import AUTOMATIC_OCR
|
||||||
from models import DocumentQueue, QueueDocument
|
from ocr.models import DocumentQueue, QueueDocument
|
||||||
from literals import QUEUEDOCUMENT_STATE_PROCESSING, \
|
from ocr.literals import QUEUEDOCUMENT_STATE_PROCESSING, \
|
||||||
QUEUEDOCUMENT_STATE_PENDING, DOCUMENTQUEUE_STATE_STOPPED, \
|
QUEUEDOCUMENT_STATE_PENDING, DOCUMENTQUEUE_STATE_STOPPED, \
|
||||||
DOCUMENTQUEUE_STATE_ACTIVE
|
DOCUMENTQUEUE_STATE_ACTIVE
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from models import DocumentQueue, QueueDocument
|
from ocr.models import DocumentQueue, QueueDocument
|
||||||
|
|
||||||
|
|
||||||
class QueueDocumentInline(admin.StackedInline):
|
class QueueDocumentInline(admin.StackedInline):
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ from documents.models import DocumentPage
|
|||||||
from ocr.conf.settings import TESSERACT_PATH
|
from ocr.conf.settings import TESSERACT_PATH
|
||||||
from ocr.conf.settings import TESSERACT_LANGUAGE
|
from ocr.conf.settings import TESSERACT_LANGUAGE
|
||||||
from ocr.conf.settings import PDFTOTEXT_PATH
|
from ocr.conf.settings import PDFTOTEXT_PATH
|
||||||
from exceptions import TesseractError, PdftotextError
|
from ocr.exceptions import TesseractError, PdftotextError
|
||||||
|
|
||||||
|
|
||||||
def get_language_backend():
|
def get_language_backend():
|
||||||
@@ -59,7 +59,7 @@ def run_pdftotext(input_filename, output_filename, page_number=None):
|
|||||||
if return_code != 0:
|
if return_code != 0:
|
||||||
error_text = proc.stderr.read()
|
error_text = proc.stderr.read()
|
||||||
raise PdftotextError(error_text)
|
raise PdftotextError(error_text)
|
||||||
|
|
||||||
|
|
||||||
def do_document_ocr(document):
|
def do_document_ocr(document):
|
||||||
for page_index, document_page in enumerate(document.documentpage_set.all()):
|
for page_index, document_page in enumerate(document.documentpage_set.all()):
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class AlreadyQueued(Exception):
|
|||||||
|
|
||||||
class TesseractError(Exception):
|
class TesseractError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PdftotextError(Exception):
|
class PdftotextError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def check_word(word):
|
def check_word(word):
|
||||||
ALL_ALPHANUM = re.compile('([0-9a-z])', re.I)
|
ALL_ALPHANUM = re.compile('([0-9a-z])', re.I)
|
||||||
NON_ALPHANUM = re.compile('([^0-9a-z])', re.I)
|
NON_ALPHANUM = re.compile('([^0-9a-z])', re.I)
|
||||||
@@ -13,7 +14,7 @@ def check_word(word):
|
|||||||
if len(word) > 20:
|
if len(word) > 20:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#(A) If a string's ratio of alphanumeric characters to total
|
#(A) If a string's ratio of alphanumeric characters to total
|
||||||
#characters is less than 50%, the string is garbage
|
#characters is less than 50%, the string is garbage
|
||||||
if len(ALL_ALPHANUM.findall(word)) < len(word) / 2:
|
if len(ALL_ALPHANUM.findall(word)) < len(word) / 2:
|
||||||
return None
|
return None
|
||||||
@@ -21,18 +22,17 @@ def check_word(word):
|
|||||||
#Remove word if all the letters in the word are non alphanumeric
|
#Remove word if all the letters in the word are non alphanumeric
|
||||||
if len(NON_ALPHANUM.findall(word)) == len(word):
|
if len(NON_ALPHANUM.findall(word)) == len(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Removed words with too many consecutie vowels
|
#Removed words with too many consecutie vowels
|
||||||
if TOO_MANY_VOWELS.findall(word):
|
if TOO_MANY_VOWELS.findall(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Removed words with too many consecutie consonants
|
#Removed words with too many consecutie consonants
|
||||||
if TOO_MANY_CONSONANTS.findall(word):
|
if TOO_MANY_CONSONANTS.findall(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Only allow specific single letter words
|
#Only allow specific single letter words
|
||||||
if len(word) == 1 and not SINGLE_LETTER_WORDS.findall(word):
|
if len(word) == 1 and not SINGLE_LETTER_WORDS.findall(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return word
|
return word
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: iso-8859-1 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def check_word(word):
|
def check_word(word):
|
||||||
ALL_ALPHANUM = re.compile('([0-9a-záéíóúüñ])', re.I)
|
ALL_ALPHANUM = re.compile('([0-9a-záéíóúüñ])', re.I)
|
||||||
NON_ALPHANUM = re.compile('([^0-9a-záéíóúüñ])', re.I)
|
NON_ALPHANUM = re.compile('([^0-9a-záéíóúüñ])', re.I)
|
||||||
@@ -14,7 +15,7 @@ def check_word(word):
|
|||||||
if len(word) > 20:
|
if len(word) > 20:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#(A) If a string’s ratio of alphanumeric characters to total
|
#(A) If a string’s ratio of alphanumeric characters to total
|
||||||
#characters is less than 50%, the string is garbage
|
#characters is less than 50%, the string is garbage
|
||||||
if len(ALL_ALPHANUM.findall(word)) < len(word) / 2:
|
if len(ALL_ALPHANUM.findall(word)) < len(word) / 2:
|
||||||
return None
|
return None
|
||||||
@@ -22,18 +23,17 @@ def check_word(word):
|
|||||||
#Remove word if all the letters in the word are non alphanumeric
|
#Remove word if all the letters in the word are non alphanumeric
|
||||||
if len(NON_ALPHANUM.findall(word)) == len(word):
|
if len(NON_ALPHANUM.findall(word)) == len(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Removed words with too many consecutie vowels
|
#Removed words with too many consecutie vowels
|
||||||
if TOO_MANY_VOWELS.findall(word):
|
if TOO_MANY_VOWELS.findall(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Removed words with too many consecutie consonants
|
#Removed words with too many consecutie consonants
|
||||||
if TOO_MANY_CONSONANTS.findall(word):
|
if TOO_MANY_CONSONANTS.findall(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
#Only allow specific single letter words
|
#Only allow specific single letter words
|
||||||
if len(word) == 1 and not SINGLE_LETTER_WORDS.findall(word):
|
if len(word) == 1 and not SINGLE_LETTER_WORDS.findall(word):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return word
|
return word
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -5,10 +5,10 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||||||
|
|
||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
|
|
||||||
from literals import DOCUMENTQUEUE_STATE_STOPPED, \
|
from ocr.literals import DOCUMENTQUEUE_STATE_STOPPED, \
|
||||||
DOCUMENTQUEUE_STATE_CHOICES, QUEUEDOCUMENT_STATE_PENDING, \
|
DOCUMENTQUEUE_STATE_CHOICES, QUEUEDOCUMENT_STATE_PENDING, \
|
||||||
QUEUEDOCUMENT_STATE_CHOICES
|
QUEUEDOCUMENT_STATE_CHOICES
|
||||||
from exceptions import AlreadyQueued
|
from ocr.exceptions import AlreadyQueued
|
||||||
|
|
||||||
|
|
||||||
class DocumentQueueManager(models.Manager):
|
class DocumentQueueManager(models.Manager):
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
from ocr.models import DocumentQueue, QueueDocument
|
||||||
from models import DocumentQueue, QueueDocument
|
|
||||||
|
|
||||||
|
|
||||||
def get_statistics():
|
def get_statistics():
|
||||||
|
|||||||
+2
-2
@@ -9,10 +9,10 @@ from celery.task import PeriodicTask
|
|||||||
from celery.decorators import task
|
from celery.decorators import task
|
||||||
|
|
||||||
from ocr.api import do_document_ocr
|
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_PROCESSING, DOCUMENTQUEUE_STATE_ACTIVE, \
|
||||||
QUEUEDOCUMENT_STATE_ERROR
|
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 NODE_CONCURRENT_EXECUTION
|
||||||
from ocr.conf.settings import REPLICATION_DELAY
|
from ocr.conf.settings import REPLICATION_DELAY
|
||||||
|
|
||||||
|
|||||||
+6
-10
@@ -14,12 +14,12 @@ from documents.models import Document
|
|||||||
from ocr import PERMISSION_OCR_DOCUMENT, PERMISSION_OCR_DOCUMENT_DELETE, \
|
from ocr import PERMISSION_OCR_DOCUMENT, PERMISSION_OCR_DOCUMENT_DELETE, \
|
||||||
PERMISSION_OCR_QUEUE_ENABLE_DISABLE, PERMISSION_OCR_CLEAN_ALL_PAGES
|
PERMISSION_OCR_QUEUE_ENABLE_DISABLE, PERMISSION_OCR_CLEAN_ALL_PAGES
|
||||||
|
|
||||||
from models import DocumentQueue, QueueDocument
|
from ocr.models import DocumentQueue, QueueDocument
|
||||||
from literals import QUEUEDOCUMENT_STATE_PENDING, \
|
from ocr.literals import QUEUEDOCUMENT_STATE_PENDING, \
|
||||||
QUEUEDOCUMENT_STATE_PROCESSING, DOCUMENTQUEUE_STATE_STOPPED, \
|
QUEUEDOCUMENT_STATE_PROCESSING, DOCUMENTQUEUE_STATE_STOPPED, \
|
||||||
DOCUMENTQUEUE_STATE_ACTIVE
|
DOCUMENTQUEUE_STATE_ACTIVE
|
||||||
from exceptions import AlreadyQueued
|
from ocr.exceptions import AlreadyQueued
|
||||||
from api import clean_pages
|
from ocr.api import clean_pages
|
||||||
|
|
||||||
|
|
||||||
def _display_thumbnail(ocr_document):
|
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])
|
check_permissions(request.user, 'ocr', [PERMISSION_OCR_DOCUMENT_DELETE])
|
||||||
|
|
||||||
if queue_document_id:
|
if queue_document_id:
|
||||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
||||||
post_redirect = None
|
|
||||||
elif queue_document_id_list:
|
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(',')]
|
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:
|
else:
|
||||||
messages.error(request, _(u'Must provide at least one queue document.'))
|
messages.error(request, _(u'Must provide at least one queue document.'))
|
||||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
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)
|
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])
|
check_permissions(request.user, 'ocr', [PERMISSION_OCR_DOCUMENT])
|
||||||
|
|
||||||
if queue_document_id:
|
if queue_document_id:
|
||||||
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
queue_documents = [get_object_or_404(QueueDocument, pk=queue_document_id)]
|
||||||
post_redirect = None
|
|
||||||
elif queue_document_id_list:
|
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(',')]
|
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:
|
else:
|
||||||
messages.error(request, _(u'Must provide at least one queue document.'))
|
messages.error(request, _(u'Must provide at least one queue document.'))
|
||||||
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
|
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 navigation.api import register_links, register_menu
|
||||||
|
|
||||||
from permissions.conf.settings import DEFAULT_ROLES
|
from permissions.conf.settings import DEFAULT_ROLES
|
||||||
from models import Role
|
from permissions.models import Role
|
||||||
|
|
||||||
PERMISSION_ROLE_VIEW = 'role_view'
|
PERMISSION_ROLE_VIEW = 'role_view'
|
||||||
PERMISSION_ROLE_EDIT = 'role_edit'
|
PERMISSION_ROLE_EDIT = 'role_edit'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from models import Permission, PermissionHolder, Role, RoleMember
|
from permissions.models import Permission, PermissionHolder, Role, RoleMember
|
||||||
|
|
||||||
|
|
||||||
class PermissionHolderInline(admin.StackedInline):
|
class PermissionHolderInline(admin.StackedInline):
|
||||||
model = PermissionHolder
|
model = PermissionHolder
|
||||||
@@ -24,8 +25,7 @@ class RoleMemberInline(admin.StackedInline):
|
|||||||
|
|
||||||
class RoleAdmin(admin.ModelAdmin):
|
class RoleAdmin(admin.ModelAdmin):
|
||||||
inlines = [RoleMemberInline]
|
inlines = [RoleMemberInline]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Permission, PermissionAdmin)
|
admin.site.register(Permission, PermissionAdmin)
|
||||||
admin.site.register(Role, RoleAdmin)
|
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_ROLE_CREATE, PERMISSION_ROLE_DELETE, \
|
||||||
PERMISSION_PERMISSION_GRANT, PERMISSION_PERMISSION_REVOKE
|
PERMISSION_PERMISSION_GRANT, PERMISSION_PERMISSION_REVOKE
|
||||||
|
|
||||||
from models import Permission, Role
|
from permissions.models import Permission, Role
|
||||||
|
|
||||||
|
|
||||||
def register_permissions(namespace, permissions):
|
def register_permissions(namespace, permissions):
|
||||||
@@ -66,7 +66,7 @@ def check_requester(requester, permission_holder):
|
|||||||
|
|
||||||
#TODO: a role may contain groups, make recursive
|
#TODO: a role may contain groups, make recursive
|
||||||
def check_elements(requester, requester_list):
|
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:
|
for requester_object in requester_list:
|
||||||
if requester == requester_object:
|
if requester == requester_object:
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
from django.conf import settings
|
|
||||||
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 common.forms import DetailForm
|
from common.forms import DetailForm
|
||||||
|
|
||||||
from models import Role, RoleMember
|
from permissions.models import Role
|
||||||
|
|
||||||
|
|
||||||
class RoleForm(forms.ModelForm):
|
class RoleForm(forms.ModelForm):
|
||||||
@@ -24,6 +23,6 @@ class ChoiceForm(forms.Form):
|
|||||||
super(ChoiceForm, self).__init__(*args, **kwargs)
|
super(ChoiceForm, self).__init__(*args, **kwargs)
|
||||||
self.fields['selection'].choices = choices
|
self.fields['selection'].choices = choices
|
||||||
self.fields['selection'].label = label
|
self.fields['selection'].label = label
|
||||||
self.fields['selection'].widget.attrs.update({'size':14})
|
self.fields['selection'].widget.attrs.update({'size': 14})
|
||||||
|
|
||||||
selection = forms.MultipleChoiceField()
|
selection = forms.MultipleChoiceField()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from django.contrib.contenttypes import generic
|
|||||||
class PermissionManager(models.Manager):
|
class PermissionManager(models.Manager):
|
||||||
def get_for_holder(self, holder):
|
def get_for_holder(self, holder):
|
||||||
ct = ContentType.objects.get_for_model(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):
|
class Permission(models.Model):
|
||||||
@@ -56,7 +56,7 @@ class Role(models.Model):
|
|||||||
role_member, created = RoleMember.objects.get_or_create(
|
role_member, created = RoleMember.objects.get_or_create(
|
||||||
role=self,
|
role=self,
|
||||||
member_type=ContentType.objects.get_for_model(member),
|
member_type=ContentType.objects.get_for_model(member),
|
||||||
member_id=member.id)
|
member_id=member.pk)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.label
|
return self.label
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from models import Role, Permission, PermissionHolder, RoleMember
|
from permissions.models import Role, Permission, PermissionHolder, RoleMember
|
||||||
from forms import RoleForm, RoleForm_view, ChoiceForm
|
from permissions.forms import RoleForm, RoleForm_view, ChoiceForm
|
||||||
from permissions import PERMISSION_ROLE_VIEW, PERMISSION_ROLE_EDIT, \
|
from permissions import PERMISSION_ROLE_VIEW, PERMISSION_ROLE_EDIT, \
|
||||||
PERMISSION_ROLE_CREATE, PERMISSION_ROLE_DELETE, PERMISSION_PERMISSION_GRANT, \
|
PERMISSION_ROLE_CREATE, PERMISSION_ROLE_DELETE, PERMISSION_PERMISSION_GRANT, \
|
||||||
PERMISSION_PERMISSION_REVOKE
|
PERMISSION_PERMISSION_REVOKE
|
||||||
from api import check_permissions
|
from permissions.api import check_permissions
|
||||||
|
|
||||||
|
|
||||||
def role_list(request):
|
def role_list(request):
|
||||||
|
|||||||
@@ -6,19 +6,17 @@ from django.utils.encoding import force_unicode
|
|||||||
from pymongo import Connection
|
from pymongo import Connection
|
||||||
from gridfs import GridFS
|
from gridfs import GridFS
|
||||||
|
|
||||||
|
|
||||||
from storage.conf import settings
|
from storage.conf import settings
|
||||||
|
|
||||||
|
|
||||||
class GridFSStorage(Storage):
|
class GridFSStorage(Storage):
|
||||||
separator = u'/'
|
separator = u'/'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.db = Connection(host=settings.GRIDFS_HOST,
|
self.db = Connection(host=settings.GRIDFS_HOST,
|
||||||
port=settings.GRIDFS_PORT)[settings.GRIDFS_DATABASE_NAME]
|
port=settings.GRIDFS_PORT)[settings.GRIDFS_DATABASE_NAME]
|
||||||
self.fs = GridFS(self.db)
|
self.fs = GridFS(self.db)
|
||||||
|
|
||||||
|
|
||||||
def save(self, name, content):
|
def save(self, name, content):
|
||||||
#TODO: if exists add _ plus a counter
|
#TODO: if exists add _ plus a counter
|
||||||
while True:
|
while True:
|
||||||
@@ -37,7 +35,7 @@ class GridFSStorage(Storage):
|
|||||||
newfile.write(chunk)
|
newfile.write(chunk)
|
||||||
finally:
|
finally:
|
||||||
newfile.close()
|
newfile.close()
|
||||||
except Exception, e:#OSError, e:
|
except Exception, e: # OSError, e:
|
||||||
# if e.errno == errno.EEXIST:
|
# if e.errno == errno.EEXIST:
|
||||||
# # Ooops, the file exists. We need a new file name.
|
# # Ooops, the file exists. We need a new file name.
|
||||||
# name = self.get_available_name(name)
|
# name = self.get_available_name(name)
|
||||||
@@ -51,34 +49,28 @@ class GridFSStorage(Storage):
|
|||||||
|
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def open(self, name, *args, **kwars):
|
def open(self, name, *args, **kwars):
|
||||||
return self.fs.get_last_version(name)
|
return self.fs.get_last_version(name)
|
||||||
|
|
||||||
|
|
||||||
def delete(self, name):
|
def delete(self, name):
|
||||||
oid = self.fs.get_last_version(name)._id
|
oid = self.fs.get_last_version(name)._id
|
||||||
self.fs.delete(oid)
|
self.fs.delete(oid)
|
||||||
|
|
||||||
|
|
||||||
def exists(self, name):
|
def exists(self, name):
|
||||||
return self.fs.exists(filename=name)
|
return self.fs.exists(filename=name)
|
||||||
|
|
||||||
|
|
||||||
def path(self, name):
|
def path(self, name):
|
||||||
return force_unicode(name)
|
return force_unicode(name)
|
||||||
|
|
||||||
|
|
||||||
def size(self, name):
|
def size(self, name):
|
||||||
return self.fs.get_last_version(name).length
|
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
|
# first open the old file, so that it won't go away
|
||||||
old_file = open(old_file_name, 'rb')
|
old_file = open(old_file_name, 'rb')
|
||||||
try:
|
try:
|
||||||
newfile = self.fs.new_file(filename=name)
|
newfile = self.fs.new_file(filename=name)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_chunk = None
|
current_chunk = None
|
||||||
while current_chunk != '':
|
while current_chunk != '':
|
||||||
@@ -92,10 +84,9 @@ class GridFSStorage(Storage):
|
|||||||
try:
|
try:
|
||||||
os.remove(old_file_name)
|
os.remove(old_file_name)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
# Certain operating systems (Cygwin and Windows)
|
# Certain operating systems (Cygwin and Windows)
|
||||||
# fail when deleting opened files, ignore it. (For the
|
# fail when deleting opened files, ignore it. (For the
|
||||||
# systems where this happens, temporary files will be auto-deleted
|
# systems where this happens, temporary files will be auto-deleted
|
||||||
# on close anyway.)
|
# on close anyway.)
|
||||||
if getattr(e, 'winerror', 0) != 32 and getattr(e, 'errno', 0) != 13:
|
if getattr(e, 'winerror', 0) != 32 and getattr(e, 'errno', 0) != 13:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.template import TemplateSyntaxError, Library, \
|
from django.template import Library, Node, Variable
|
||||||
VariableDoesNotExist, Node, Variable
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
register = Library()
|
register = Library()
|
||||||
|
|
||||||
@@ -9,21 +7,20 @@ register = Library()
|
|||||||
class StylingNode(Node):
|
class StylingNode(Node):
|
||||||
def __init__(self, form_name, *args, **kwargs):
|
def __init__(self, form_name, *args, **kwargs):
|
||||||
self.form_name = form_name
|
self.form_name = form_name
|
||||||
|
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
form = Variable(self.form_name).resolve(context)
|
form = Variable(self.form_name).resolve(context)
|
||||||
for field_name, field in form.fields.items():
|
for field_name, field in form.fields.items():
|
||||||
|
|
||||||
if isinstance(field.widget, forms.widgets.TextInput):
|
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):
|
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):
|
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
|
context[self.form_name] = form
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
import types
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
from django.template import Library, Node, TemplateSyntaxError
|
||||||
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 web_theme.conf import settings as web_theme_settings
|
from web_theme.conf import settings as web_theme_settings
|
||||||
|
|
||||||
@@ -29,25 +24,25 @@ def get_theme(parser, token):
|
|||||||
# Splitting by None == splitting by spaces.
|
# Splitting by None == splitting by spaces.
|
||||||
tag_name, arg = token.contents.split(None, 1)
|
tag_name, arg = token.contents.split(None, 1)
|
||||||
except ValueError:
|
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)
|
||||||
m = re.search(r'as (\w+)', arg)
|
m = re.search(r'as (\w+)', arg)
|
||||||
if not m:
|
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()
|
#format_string, var_name = m.groups()
|
||||||
var_name = m.groups()
|
var_name = m.groups()
|
||||||
|
|
||||||
#if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
|
#if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
|
||||||
# raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
|
# raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
|
||||||
return GetThemeNode(var_name)
|
return GetThemeNode(var_name)
|
||||||
|
|
||||||
|
|
||||||
class LoginRedirectNode(Node):
|
class LoginRedirectNode(Node):
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
context['LOGIN_REDIRECT_URL'] = getattr(settings, 'LOGIN_REDIRECT_URL', '/')
|
context['LOGIN_REDIRECT_URL'] = getattr(settings, 'LOGIN_REDIRECT_URL', '/')
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
@register.tag
|
@register.tag
|
||||||
def get_login_redirect_url(parser, token):
|
def get_login_redirect_url(parser, token):
|
||||||
|
|||||||
+6
-6
@@ -23,7 +23,7 @@ MANAGERS = ADMINS
|
|||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
|
||||||
'NAME': os.path.join(PROJECT_ROOT, '%s.sqlite' % PROJECT_NAME), # Or path to database file if using sqlite3.
|
'NAME': os.path.join(PROJECT_ROOT, '%s.sqlite' % PROJECT_NAME), # Or path to database file if using sqlite3.
|
||||||
'USER': '', # Not used with sqlite3.
|
'USER': '', # Not used with sqlite3.
|
||||||
'PASSWORD': '', # Not used with sqlite3.
|
'PASSWORD': '', # Not used with sqlite3.
|
||||||
@@ -250,7 +250,7 @@ BROKER_PORT = 5672
|
|||||||
BROKER_USER = "guest"
|
BROKER_USER = "guest"
|
||||||
BROKER_PASSWORD = "guest"
|
BROKER_PASSWORD = "guest"
|
||||||
BROKER_VHOST = "/"
|
BROKER_VHOST = "/"
|
||||||
CELERYBEAT_SCHEDULER='djcelery.schedulers.DatabaseScheduler'
|
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
|
||||||
#======== End of user configuration options =======
|
#======== End of user configuration options =======
|
||||||
#--------- Web theme ---------------
|
#--------- Web theme ---------------
|
||||||
WEB_THEME_ENABLE_SCROLL_JS = False
|
WEB_THEME_ENABLE_SCROLL_JS = False
|
||||||
@@ -263,7 +263,7 @@ LOGIN_REDIRECT_URL = '/'
|
|||||||
LOGIN_EXEMPT_URLS = (
|
LOGIN_EXEMPT_URLS = (
|
||||||
r'^favicon\.ico$',
|
r'^favicon\.ico$',
|
||||||
r'^about\.html$',
|
r'^about\.html$',
|
||||||
r'^legal/', # allow the entire /legal/* subsection
|
r'^legal/', # allow the entire /legal/* subsection
|
||||||
r'^%s-site_media/' % PROJECT_NAME,
|
r'^%s-site_media/' % PROJECT_NAME,
|
||||||
|
|
||||||
r'^accounts/register/$',
|
r'^accounts/register/$',
|
||||||
@@ -305,7 +305,7 @@ if DEVELOPMENT:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
import django_extensions
|
import django_extensions
|
||||||
INSTALLED_APPS +=('django_extensions',)
|
INSTALLED_APPS += ('django_extensions',)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
#print 'django_extensions is not installed'
|
#print 'django_extensions is not installed'
|
||||||
pass
|
pass
|
||||||
@@ -322,6 +322,6 @@ if DEVELOPMENT:
|
|||||||
WSGI_AUTO_RELOAD = True
|
WSGI_AUTO_RELOAD = True
|
||||||
if 'debug_toolbar' in INSTALLED_APPS:
|
if 'debug_toolbar' in INSTALLED_APPS:
|
||||||
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
|
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
|
||||||
DEBUG_TOOLBAR_CONFIG={
|
DEBUG_TOOLBAR_CONFIG = {
|
||||||
'INTERCEPT_REDIRECTS' : False,
|
'INTERCEPT_REDIRECTS': False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.contrib import admin
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.conf.urls.defaults import *
|
|
||||||
from django.views.defaults import page_not_found, server_error
|
|
||||||
|
|
||||||
admin.autodiscover()
|
admin.autodiscover()
|
||||||
|
|
||||||
@@ -21,6 +19,7 @@ urlpatterns = patterns('',
|
|||||||
(r'^sentry/', include('sentry.urls')),
|
(r'^sentry/', include('sentry.urls')),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def handler500(request):
|
def handler500(request):
|
||||||
"""
|
"""
|
||||||
500 error handler which includes ``request`` in the context.
|
500 error handler which includes ``request`` in the context.
|
||||||
@@ -31,21 +30,19 @@ def handler500(request):
|
|||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
from django.http import HttpResponseServerError
|
from django.http import HttpResponseServerError
|
||||||
|
|
||||||
t = loader.get_template('500.html') # You need to create a 500.html template.
|
t = loader.get_template('500.html') # You need to create a 500.html template.
|
||||||
return HttpResponseServerError(t.render(Context({
|
return HttpResponseServerError(t.render(Context({
|
||||||
'request': request,
|
'request': request,
|
||||||
})))
|
})))
|
||||||
|
|
||||||
if settings.DEVELOPMENT:
|
if settings.DEVELOPMENT:
|
||||||
urlpatterns += patterns('',
|
urlpatterns += patterns('',
|
||||||
(r'^%s-site_media/(?P<path>.*)$' % settings.PROJECT_NAME,
|
(r'^%s-site_media/(?P<path>.*)$' % settings.PROJECT_NAME,
|
||||||
'django.views.static.serve',
|
'django.views.static.serve',
|
||||||
{'document_root':'site_media', 'show_indexes':True}),
|
{'document_root': 'site_media', 'show_indexes': True}),
|
||||||
)
|
)
|
||||||
|
|
||||||
if 'rosetta' in settings.INSTALLED_APPS:
|
if 'rosetta' in settings.INSTALLED_APPS:
|
||||||
urlpatterns += patterns('',
|
urlpatterns += patterns('',
|
||||||
url(r'^rosetta/', include('rosetta.urls'), name='rosetta'),
|
url(r'^rosetta/', include('rosetta.urls'), name='rosetta'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user