Code cleanup
This commit is contained in:
@@ -29,6 +29,7 @@ if common_settings.AUTO_CREATE_ADMIN:
|
||||
# the "syncdb" command during database creation.)
|
||||
#
|
||||
# Create our own test user automatically.
|
||||
|
||||
def create_testuser(app, created_models, verbosity, **kwargs):
|
||||
USERNAME = common_settings.AUTO_ADMIN_USERNAME
|
||||
PASSWORD = common_settings.AUTO_ADMIN_PASSWORD
|
||||
|
||||
@@ -111,4 +111,3 @@ class UserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ('first_name', 'last_name')
|
||||
|
||||
|
||||
@@ -129,6 +129,9 @@ class ConverterClass(ConverterBase):
|
||||
for format_name in Image.ID:
|
||||
formats.append((format_name, u''))
|
||||
|
||||
#if USE_GHOSTSCRIPT:
|
||||
#PDF, PS
|
||||
|
||||
return formats
|
||||
|
||||
def get_available_transformations(self):
|
||||
@@ -171,6 +174,6 @@ class ConverterClass(ConverterBase):
|
||||
|
||||
if out:
|
||||
#save it into a file-like object
|
||||
img.save(out, "JPEG", quality=75)
|
||||
img.save(out, 'JPEG', quality=75)
|
||||
else:
|
||||
return img
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
|
||||
from common.utils import validate_path
|
||||
from navigation.api import register_links, register_top_menu, \
|
||||
@@ -28,6 +26,7 @@ from documents.conf.settings import ZOOM_MIN_LEVEL
|
||||
from documents.conf.settings import CACHE_PATH
|
||||
from documents.widgets import document_thumbnail
|
||||
|
||||
|
||||
# Document page links expressions
|
||||
def is_first_page(context):
|
||||
return context['object'].page_number <= 1
|
||||
|
||||
@@ -13,7 +13,7 @@ from taggit.managers import TaggableManager
|
||||
from dynamic_search.api import register
|
||||
from converter.api import get_page_count
|
||||
from converter.api import get_available_transformations_choices
|
||||
from converter.api import create_image_cache_filename, convert
|
||||
from converter.api import convert
|
||||
from converter.exceptions import UnknownFormat, UnkownConvertError
|
||||
|
||||
from documents.utils import get_document_mimetype
|
||||
@@ -21,7 +21,6 @@ from documents.conf.settings import CHECKSUM_FUNCTION
|
||||
from documents.conf.settings import UUID_FUNCTION
|
||||
from documents.conf.settings import STORAGE_BACKEND
|
||||
from documents.conf.settings import PREVIEW_SIZE
|
||||
from documents.conf.settings import THUMBNAIL_SIZE
|
||||
from documents.conf.settings import CACHE_PATH
|
||||
|
||||
from documents.managers import RecentDocumentManager, \
|
||||
@@ -30,7 +29,7 @@ from documents.utils import document_save_to_temp_dir
|
||||
from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
|
||||
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
|
||||
from converter.literals import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \
|
||||
DEFAULT_FILE_FORMAT, DEFAULT_PAGE_NUMBER
|
||||
DEFAULT_PAGE_NUMBER
|
||||
|
||||
# document image cache name hash function
|
||||
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
|
||||
@@ -243,7 +242,7 @@ class Document(models.Model):
|
||||
output_file = os.path.join(settings.MEDIA_ROOT, u'images', PICTURE_UNKNOWN_SMALL)
|
||||
except UnkownConvertError:
|
||||
output_file = os.path.join(settings.MEDIA_ROOT, u'images', PICTURE_ERROR_SMALL)
|
||||
except Exception, e:
|
||||
except:
|
||||
output_file = os.path.join(settings.MEDIA_ROOT, u'images', PICTURE_ERROR_SMALL)
|
||||
return output_file
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.template import Library, Node, Variable
|
||||
|
||||
from converter.api import get_document_dimensions
|
||||
|
||||
from documents.views import calculate_converter_arguments
|
||||
from documents.conf.settings import PRINT_SIZE
|
||||
|
||||
register = Library()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
import urlparse
|
||||
import copy
|
||||
|
||||
@@ -10,7 +9,6 @@ from django.contrib import messages
|
||||
from django.views.generic.list_detail import object_list
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.views.generic.create_update import delete_object, update_object
|
||||
from django.conf import settings
|
||||
from django.utils.http import urlencode
|
||||
|
||||
import sendfile
|
||||
@@ -24,8 +22,6 @@ from converter.literals import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \
|
||||
DEFAULT_FILE_FORMAT, DEFAULT_PAGE_NUMBER
|
||||
from filetransfers.api import serve_file
|
||||
from grouping.utils import get_document_group_subtemplate
|
||||
from metadata.api import save_metadata_list, \
|
||||
decode_metadata_from_url, metadata_repr_as_list
|
||||
from metadata.forms import MetadataFormSet, MetadataSelectionForm
|
||||
from navigation.utils import resolve_to_name
|
||||
from permissions.api import check_permissions
|
||||
@@ -33,7 +29,6 @@ from document_indexing.api import update_indexes, delete_indexes
|
||||
from history.api import create_history
|
||||
|
||||
from documents.conf.settings import PREVIEW_SIZE
|
||||
from documents.conf.settings import THUMBNAIL_SIZE
|
||||
from documents.conf.settings import STORAGE_BACKEND
|
||||
from documents.conf.settings import ZOOM_PERCENT_STEP
|
||||
from documents.conf.settings import ZOOM_MAX_LEVEL
|
||||
@@ -52,7 +47,7 @@ from documents.literals import HISTORY_DOCUMENT_CREATED, \
|
||||
HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED
|
||||
|
||||
from documents.forms import DocumentTypeSelectForm, \
|
||||
DocumentForm, DocumentForm_edit, DocumentPropertiesForm, \
|
||||
DocumentForm_edit, DocumentPropertiesForm, \
|
||||
DocumentPreviewForm, \
|
||||
DocumentPageForm, DocumentPageTransformationForm, \
|
||||
DocumentContentForm, DocumentPageForm_edit, \
|
||||
@@ -61,8 +56,6 @@ from documents.forms import DocumentTypeSelectForm, \
|
||||
from documents.wizards import DocumentCreateWizard
|
||||
from documents.models import Document, DocumentType, DocumentPage, \
|
||||
DocumentPageTransformation, RecentDocument, DocumentTypeFilename
|
||||
from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
|
||||
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM
|
||||
|
||||
# Document type permissions
|
||||
from documents.literals import PERMISSION_DOCUMENT_TYPE_EDIT, \
|
||||
@@ -779,10 +772,10 @@ def document_hard_copy(request, document_id):
|
||||
|
||||
RecentDocument.objects.add_document_for_user(request.user, document)
|
||||
|
||||
arguments, warnings = calculate_converter_arguments(document, size=PRINT_SIZE, file_format=DEFAULT_FILE_FORMAT)
|
||||
#arguments, warnings = calculate_converter_arguments(document, size=PRINT_SIZE, file_format=DEFAULT_FILE_FORMAT)
|
||||
|
||||
# Pre-generate
|
||||
convert_document(document, **arguments)
|
||||
#convert_document(document, **arguments)
|
||||
|
||||
# Extract dimension values ignoring any unit
|
||||
page_width = request.GET.get('page_width', dict(PAGE_SIZE_DIMENSIONS)[DEFAULT_PAPER_SIZE][0])
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import urlparse
|
||||
from datetime import datetime
|
||||
|
||||
from django.db import models
|
||||
from django.utils.http import urlencode
|
||||
|
||||
@@ -8,8 +8,6 @@ from django.template import TemplateSyntaxError, Library, \
|
||||
from django.utils.text import unescape_string_literal
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from django.template import Context
|
||||
|
||||
from common.utils import urlquote
|
||||
|
||||
from navigation.api import object_navigation, multi_object_navigation, \
|
||||
@@ -203,7 +201,6 @@ def _get_object_navigation_links(context, menu_name=None, links_dict=object_navi
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
return context_links
|
||||
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ def do_document_ocr(queue_document):
|
||||
#im.save(unpaper_output_filepath)
|
||||
|
||||
# Convert to TIFF
|
||||
pre_ocr_filepath = output_filepath=convert(input_filepath=unpaper_output_filepath, file_format=DEFAULT_OCR_FILE_FORMAT)
|
||||
pre_ocr_filepath = convert(input_filepath=unpaper_output_filepath, file_format=DEFAULT_OCR_FILE_FORMAT)
|
||||
# Tesseract needs an explicit file extension
|
||||
pre_ocr_filepath_w_ext = os.extsep.join([pre_ocr_filepath, DEFAULT_OCR_FILE_EXTENSION])
|
||||
os.rename(pre_ocr_filepath, pre_ocr_filepath_w_ext)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
|
||||
from ocr.models import QueueTransformation
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
import codecs
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import sys
|
||||
|
||||
import slate
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
@@ -18,5 +18,4 @@ urlpatterns = patterns('ocr.views',
|
||||
url(r'^queue/(?P<document_queue_id>\w+)/transformation/create/$', 'setup_queue_transformation_create', (), 'setup_queue_transformation_create'),
|
||||
url(r'^queue/transformation/(?P<transformation_id>\w+)/edit/$', 'setup_queue_transformation_edit', (), 'setup_queue_transformation_edit'),
|
||||
url(r'^queue/transformation/(?P<transformation_id>\w+)/delete/$', 'setup_queue_transformation_delete', (), 'setup_queue_transformation_delete'),
|
||||
|
||||
)
|
||||
|
||||
@@ -429,7 +429,6 @@ def setup_queue_transformation_create(request, document_queue_id):
|
||||
document_queue = get_object_or_404(DocumentQueue, pk=document_queue_id)
|
||||
|
||||
redirect_view = reverse('setup_queue_transformation_list', args=[document_queue.pk])
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = QueueTransformationForm_create(request.POST)
|
||||
@@ -458,4 +457,3 @@ def setup_queue_transformation_create(request, document_queue_id):
|
||||
'navigation_object_name': 'queue',
|
||||
'title': _(u'Create new transformation for queue: %s') % document_queue,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.template import RequestContext
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib.contenttypes import generic
|
||||
|
||||
from documents.models import DocumentType
|
||||
from documents.managers import RecentDocumentManager
|
||||
from metadata.models import MetadataType
|
||||
from converter.api import get_available_transformations_choices
|
||||
from converter.literals import DIMENSION_SEPARATOR
|
||||
|
||||
@@ -5,7 +5,6 @@ import hashlib
|
||||
from django.core.files.base import File
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.utils.translation import ugettext
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from converter.api import convert, cache_cleanup
|
||||
|
||||
@@ -596,24 +596,7 @@ def setup_source_transformation_create(request, source_type, source_id):
|
||||
|
||||
source = get_object_or_404(cls, pk=source_id)
|
||||
|
||||
context = {
|
||||
'object_list': SourceTransformation.objects.get_for_object(source),
|
||||
'title': _(u'transformations for: %s') % source.fullname(),
|
||||
'source': source,
|
||||
'object_name': _(u'source'),
|
||||
'navigation_object_name': 'source',
|
||||
'list_object_variable_name': 'transformation',
|
||||
'extra_columns': [
|
||||
{'name': _(u'order'), 'attribute': 'order'},
|
||||
{'name': _(u'transformation'), 'attribute': lambda x: x.get_transformation_display()},
|
||||
{'name': _(u'arguments'), 'attribute': 'arguments'}
|
||||
],
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
}
|
||||
|
||||
redirect_view = reverse('setup_source_transformation_list', args=[source.source_type, source.pk])
|
||||
previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', redirect_view)))
|
||||
|
||||
if request.method == 'POST':
|
||||
form = SourceTransformationForm_create(request.POST)
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from navigation.api import register_links, register_top_menu, \
|
||||
register_model_list_columns, register_multi_item_links
|
||||
from permissions.api import register_permission, set_namespace_title
|
||||
from navigation.api import register_sidebar_template
|
||||
|
||||
from documents.models import Document
|
||||
|
||||
|
||||
@@ -284,4 +284,3 @@ def tag_remove(request, document_id, tag_id=None, tag_id_list=None):
|
||||
|
||||
def tag_multiple_remove(request, document_id):
|
||||
return tag_remove(request, document_id=document_id, tag_id_list=request.GET.get('id_list', []))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user