diff --git a/apps/common/auth/email_auth_backend.py b/apps/common/auth/email_auth_backend.py index 016634283e..1048e8c788 100644 --- a/apps/common/auth/email_auth_backend.py +++ b/apps/common/auth/email_auth_backend.py @@ -1,12 +1,12 @@ # From: http://www.micahcarrick.com/django-email-authentication.html -from django.contrib.auth.models import User, check_password +from django.contrib.auth.models import User from django.contrib.auth.backends import ModelBackend class EmailAuthBackend(ModelBackend): """ Email Authentication Backend - + Allows a user to sign in using an email/password pair rather than a username/password pair. """ diff --git a/apps/common/forms.py b/apps/common/forms.py index 3a98544f92..7c0c32ad60 100644 --- a/apps/common/forms.py +++ b/apps/common/forms.py @@ -51,7 +51,7 @@ class DetailForm(forms.ModelForm): self.fields[field_name].widget = TextAreaDiv( attrs=field.widget.attrs, ) - + for field_name, field in self.fields.items(): self.fields[field_name].widget.attrs.update({'readonly': 'readonly'}) @@ -128,10 +128,10 @@ class EmailAuthenticationForm(AuthenticationForm): Override the default authentication form to use email address authentication """ - email = forms.CharField(label=_(u'Email'), max_length=75, + email = forms.CharField(label=_(u'Email'), max_length=75, widget=EmailInput() ) - + def clean(self): email = self.cleaned_data.get('email') password = self.cleaned_data.get('password') @@ -145,7 +145,7 @@ class EmailAuthenticationForm(AuthenticationForm): self.check_for_test_cookie() return self.cleaned_data -# Remove the inherited username field +# Remove the inherited username field EmailAuthenticationForm.base_fields.keyOrder = ['email', 'password'] @@ -164,5 +164,4 @@ class ChangelogForm(forms.Form): changelog_path = os.path.join(settings.PROJECT_ROOT, CHANGELOG_DIRECTORY, CHANGELOG_FILENAME) fd = open(changelog_path) self.fields['text'].initial = fd.read() - fd.close() - + fd.close() diff --git a/apps/common/utils.py b/apps/common/utils.py index 8ae2c5f97b..61973996ac 100644 --- a/apps/common/utils.py +++ b/apps/common/utils.py @@ -358,12 +358,6 @@ def validate_path(path): return True - -#def encapsulate(function): -# def wrapper(): -# return function -# return wrapper - def encapsulate(function): # Workaround Django ticket 15791 # Changeset 16045 diff --git a/apps/common/views.py b/apps/common/views.py index aca1520479..6662342c15 100644 --- a/apps/common/views.py +++ b/apps/common/views.py @@ -1,5 +1,3 @@ -import os - from django.shortcuts import redirect from django.utils.translation import ugettext_lazy as _ from django.http import HttpResponseRedirect @@ -10,10 +8,8 @@ from django.contrib.contenttypes.models import ContentType from django.core.urlresolvers import reverse from django.utils.http import urlencode from django.contrib.auth.views import login -from django.conf import settings -from django.utils.safestring import mark_safe -from common.forms import ChoiceForm, UserForm, UserForm_view +from common.forms import ChoiceForm, UserForm, UserForm_view, ChangelogForm from common.forms import EmailAuthenticationForm from common.conf.settings import LOGIN_METHOD @@ -181,18 +177,15 @@ def login_view(request): if LOGIN_METHOD == 'email': kwargs['authentication_form'] = EmailAuthenticationForm - + return login(request, **kwargs) -from common.forms import ChangelogForm -def changelog(request): - - #changelog_widget = mark_safe(u'
' % changelog) +def changelog(request): form = ChangelogForm() return render_to_response( 'generic_detail.html', { 'form': form, 'title': _(u'Changelog'), }, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) diff --git a/apps/common/widgets.py b/apps/common/widgets.py index 1f56f3e409..9ad951c52e 100644 --- a/apps/common/widgets.py +++ b/apps/common/widgets.py @@ -4,8 +4,8 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.safestring import mark_safe from django import forms from django.forms.util import flatatt -from django.utils.html import escape, conditional_escape -from django.utils.encoding import StrAndUnicode, force_unicode +from django.utils.html import conditional_escape +from django.utils.encoding import force_unicode class PlainWidget(forms.widgets.Widget): @@ -77,11 +77,12 @@ class TextAreaDiv(forms.widgets.Widget): super(TextAreaDiv, self).__init__(default_attrs) def render(self, name, value, attrs=None): - if value is None: value = '' + if value is None: + value = '' final_attrs = self.build_attrs(attrs, name=name) result = mark_safe(u'%s' % (flatatt(final_attrs), conditional_escape(force_unicode(value)))) - + return mark_safe(result.replace('\n', '
')) diff --git a/apps/converter/api.py b/apps/converter/api.py index 8bc8cbd8dc..e34b26be08 100644 --- a/apps/converter/api.py +++ b/apps/converter/api.py @@ -5,16 +5,15 @@ import hashlib from common.conf.settings import TEMPORARY_DIRECTORY from converter.conf.settings import UNOCONV_PATH -from converter.exceptions import OfficeConversionError, UnknownFileFormat +from converter.exceptions import OfficeConversionError from converter.literals import DEFAULT_PAGE_NUMBER, \ DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, DEFAULT_FILE_FORMAT from converter import backend from converter.literals import TRANSFORMATION_CHOICES from converter.literals import TRANSFORMATION_RESIZE, \ - TRANSFORMATION_ROTATE, TRANSFORMATION_DENSITY, \ - TRANSFORMATION_ZOOM -from converter.literals import DIMENSION_SEPARATOR + TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM +from converter.literals import DIMENSION_SEPARATOR from converter.utils import cleanup HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest() @@ -51,7 +50,7 @@ def create_image_cache_filename(input_filepath, *args, **kwargs): return os.path.join(TEMPORARY_DIRECTORY, hash_value) else: return None - + def convert_office_document(input_filepath): if os.path.exists(UNOCONV_PATH): @@ -136,5 +135,5 @@ def get_available_transformations_choices(): for transformation in backend.get_available_transformations(): transformation_template = u'%s %s' % (TRANSFORMATION_CHOICES[transformation]['label'], u','.join(['<%s>' % argument['name'] if argument['required'] else '[%s]' % argument['name'] for argument in TRANSFORMATION_CHOICES[transformation]['arguments']])) result.append([transformation, transformation_template]) - + return result diff --git a/apps/converter/backends/__init__.py b/apps/converter/backends/__init__.py index a98881632b..89af0d8f77 100644 --- a/apps/converter/backends/__init__.py +++ b/apps/converter/backends/__init__.py @@ -13,6 +13,6 @@ class ConverterBase(object): def get_available_transformations(self): raise NotImplementedError("Your %s class has not defined a get_available_transformations() method, which is required." % self.__class__.__name__) - + def get_page_count(self): raise NotImplementedError("Your %s class has not defined a get_page_count() method, which is required." % self.__class__.__name__) diff --git a/apps/converter/backends/graphicsmagick/base.py b/apps/converter/backends/graphicsmagick/base.py index 559b31506d..67538d9815 100644 --- a/apps/converter/backends/graphicsmagick/base.py +++ b/apps/converter/backends/graphicsmagick/base.py @@ -7,8 +7,7 @@ from converter.exceptions import ConvertError, UnknownFileFormat, \ IdentifyError from converter.backends import ConverterBase from converter.literals import TRANSFORMATION_RESIZE, \ - TRANSFORMATION_ROTATE, TRANSFORMATION_DENSITY, \ - TRANSFORMATION_ZOOM + TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM from converter.literals import DIMENSION_SEPARATOR, DEFAULT_PAGE_NUMBER, \ DEFAULT_FILE_FORMAT diff --git a/apps/converter/backends/python/base.py b/apps/converter/backends/python/base.py index 4ba265f6bf..b7afa6e8c9 100644 --- a/apps/converter/backends/python/base.py +++ b/apps/converter/backends/python/base.py @@ -10,11 +10,9 @@ try: except RuntimeError: USE_GHOSTSCRIPT = False -from django.utils.translation import ugettext_lazy as _ - from mimetype.api import get_mimetype -from converter.exceptions import ConvertError, UnknownFileFormat, IdentifyError +from converter.exceptions import UnknownFileFormat from converter.backends import ConverterBase from converter.literals import TRANSFORMATION_RESIZE, \ TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM @@ -26,7 +24,7 @@ from converter.utils import cleanup class ConverterClass(ConverterBase): def get_page_count(self, input_filepath): page_count = 1 - + mimetype, encoding = get_mimetype(input_filepath) if mimetype == 'application/pdf': # If file is a PDF open it with slate to determine the page @@ -37,7 +35,7 @@ class ConverterClass(ConverterBase): try: im = Image.open(input_filepath) - except IOError: #cannot identify image file + except IOError: # cannot identify image file raise UnknownFileFormat try: @@ -46,10 +44,10 @@ class ConverterClass(ConverterBase): page_count += 1 # do something to im except EOFError: - pass # end of sequence + pass # end of sequence return page_count - + def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT): tmpfile = None mimetype, encoding = get_mimetype(input_filepath) @@ -79,12 +77,13 @@ class ConverterClass(ConverterBase): ] ghostscript.Ghostscript(*args) - page = 1 # Don't execute the following while loop + page = 1 # Don't execute the following while loop input_filepath = tmpfile try: im = Image.open(input_filepath) - except Exception: # Python Imaging Library doesn't recognize it as an image + except Exception: + # Python Imaging Library doesn't recognize it as an image raise UnknownFileFormat finally: if tmpfile: @@ -97,7 +96,8 @@ class ConverterClass(ConverterBase): current_page += 1 # do something to im except EOFError: - pass # end of sequence + # end of sequence + pass try: if transformations: diff --git a/apps/converter/literals.py b/apps/converter/literals.py index 66a17d0d67..db3b4e92e7 100644 --- a/apps/converter/literals.py +++ b/apps/converter/literals.py @@ -35,12 +35,12 @@ TRANSFORMATION_CHOICES = { {'name': 'width', 'label': _(u'width'), 'required': True}, {'name': 'height', 'label': _(u'height'), 'required': False}, ] - }, + }, TRANSFORMATION_ZOOM: { 'label': _(u'Zoom'), 'description': _(u'Zoom by n percent.'), 'arguments': [ {'name': 'percent', 'label': _(u'percent'), 'required': True} ] - }, + }, } diff --git a/apps/converter/utils.py b/apps/converter/utils.py index 26ad9c4b74..1544db04ee 100644 --- a/apps/converter/utils.py +++ b/apps/converter/utils.py @@ -2,8 +2,8 @@ import os from django.core.exceptions import ImproperlyConfigured from django.utils.importlib import import_module - - + + #http://stackoverflow.com/questions/123198/how-do-i-copy-a-file-in-python def copyfile(source, dest, buffer_size=1024 * 1024): """ @@ -36,7 +36,7 @@ def _lazy_load(fn): return _cached[0] return _decorated - + @_lazy_load def load_backend(): from converter.conf.settings import GRAPHICS_BACKEND as backend_name @@ -71,7 +71,8 @@ def load_backend(): (backend_name, ", ".join(map(repr, available_backends)), e_user) raise ImproperlyConfigured(error_msg) else: - raise # If there's some other error, this must be an error in Mayan itself. + # If there's some other error, this must be an error in Mayan itself. + raise def cleanup(filename): diff --git a/apps/converter/views.py b/apps/converter/views.py index 4e74757fae..43842bcbc5 100644 --- a/apps/converter/views.py +++ b/apps/converter/views.py @@ -7,6 +7,7 @@ from common.utils import encapsulate from converter import backend from converter.conf.settings import GRAPHICS_BACKEND + def formats_list(request): #check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) diff --git a/apps/document_indexing/views.py b/apps/document_indexing/views.py index c5729a107c..a344093e6e 100644 --- a/apps/document_indexing/views.py +++ b/apps/document_indexing/views.py @@ -44,7 +44,7 @@ def index_instance_list(request, index_id=None): request, title=title, object_list=index_instance_list, - extra_context = { + extra_context={ 'object': index_instance } ) @@ -105,7 +105,6 @@ def document_index_list(request, document_id): for index_instance in document.indexinstance_set.all(): object_list.append(get_breadcrumbs(index_instance, single_link=True, include_count=True)) - return render_to_response('generic_list.html', { 'title': _(u'indexes containing: %s') % document, 'object_list': object_list, diff --git a/apps/documents/__init__.py b/apps/documents/__init__.py index b4395be419..748e84a3b5 100644 --- a/apps/documents/__init__.py +++ b/apps/documents/__init__.py @@ -25,7 +25,6 @@ from documents.literals import HISTORY_DOCUMENT_CREATED, \ HISTORY_DOCUMENT_EDITED, HISTORY_DOCUMENT_DELETED from documents.conf.settings import ZOOM_MAX_LEVEL from documents.conf.settings import ZOOM_MIN_LEVEL -from documents.conf.settings import CACHE_PATH from documents.conf import settings as document_settings from documents.widgets import document_thumbnail diff --git a/apps/documents/models.py b/apps/documents/models.py index 52d785eede..1d4b67881f 100644 --- a/apps/documents/models.py +++ b/apps/documents/models.py @@ -9,7 +9,6 @@ from django.utils.translation import ugettext from django.contrib.auth.models import User from django.contrib.contenttypes import generic from django.contrib.comments.models import Comment -from django.conf import settings from django.core.exceptions import ValidationError from taggit.managers import TaggableManager @@ -31,8 +30,6 @@ from documents.conf.settings import CACHE_PATH from documents.managers import RecentDocumentManager, \ DocumentPageTransformationManager 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_PAGE_NUMBER @@ -168,7 +165,7 @@ class Document(models.Model): def update_page_count(self, save=True): handle, filepath = tempfile.mkstemp() # Just need the filepath, close the file description - os.close(handle) + os.close(handle) self.save_to_file(filepath) try: @@ -236,7 +233,7 @@ class Document(models.Model): ) page_transformation.save() - + def get_cached_image_name(self, page): document_page = self.documentpage_set.get(page_number=page) transformations, warnings = document_page.get_transformation_list() diff --git a/apps/documents/views.py b/apps/documents/views.py index 0d2fe0350e..acff89e8d5 100644 --- a/apps/documents/views.py +++ b/apps/documents/views.py @@ -8,7 +8,6 @@ from django.template import RequestContext 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.utils.http import urlencode import sendfile @@ -19,7 +18,7 @@ from common.literals import PAGE_SIZE_DIMENSIONS, \ PAGE_ORIENTATION_PORTRAIT, PAGE_ORIENTATION_LANDSCAPE from common.conf.settings import DEFAULT_PAPER_SIZE from converter.literals import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \ - DEFAULT_FILE_FORMAT, DEFAULT_PAGE_NUMBER + DEFAULT_PAGE_NUMBER from filetransfers.api import serve_file from grouping.utils import get_document_group_subtemplate from metadata.forms import MetadataFormSet, MetadataSelectionForm @@ -388,13 +387,13 @@ def document_page_transformation_edit(request, document_page_transformation_id): 'navigation_object_list': [ {'object': 'page'}, {'object': 'transformation', 'name': _(u'transformation')} - ], + ], 'title': _(u'Edit transformation "%(transformation)s" for: %(document_page)s') % { 'transformation': document_page_transformation.get_transformation_display(), 'document_page': document_page_transformation.document_page}, 'web_theme_hide_menus': True, }, context_instance=RequestContext(request)) - + def document_page_transformation_delete(request, document_page_transformation_id): check_permissions(request.user, [PERMISSION_DOCUMENT_TRANSFORM]) @@ -417,7 +416,7 @@ def document_page_transformation_delete(request, document_page_transformation_id 'navigation_object_list': [ {'object': 'page'}, {'object': 'transformation', 'name': _(u'transformation')} - ], + ], 'title': _(u'Are you sure you wish to delete transformation "%(transformation)s" for: %(document_page)s') % { 'transformation': document_page_transformation.get_transformation_display(), 'document_page': document_page_transformation.document_page}, @@ -865,7 +864,7 @@ def document_type_document_list(request, document_type_id): extra_context={ 'object_name': _(u'document type'), 'navigation_object_name': 'document_type', - 'document_type': document_type, + 'document_type': document_type, } ) @@ -926,11 +925,11 @@ def document_type_delete(request, document_type_id): 'delete_view': True, 'previous': previous, 'next': next, - + 'object_name': _(u'document type'), 'navigation_object_name': 'document_type', 'document_type': document_type, - + 'title': _(u'Are you sure you wish to delete the document type: %s?') % document_type, 'message': _(u'The document type of all documents using this document type will be set to none.'), 'form_icon': u'layout_delete.png', @@ -1018,7 +1017,7 @@ def document_type_filename_edit(request, document_type_filename_id): 'navigation_object_list': [ {'object': 'document_type', 'name': _(u'document type')}, {'object': 'filename', 'name': _(u'document type filename')} - ], + ], }, context_instance=RequestContext(request)) @@ -1052,7 +1051,7 @@ def document_type_filename_delete(request, document_type_filename_id): 'navigation_object_list': [ {'object': 'document_type', 'name': _(u'document type')}, {'object': 'filename', 'name': _(u'document type filename')} - ], + ], 'title': _(u'Are you sure you wish to delete the filename: %(filename)s, from document type "%(document_type)s"?') % { 'document_type': document_type_filename.document_type, 'filename': document_type_filename }, diff --git a/apps/exporter/__init__.py b/apps/exporter/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/apps/exporter/models.py b/apps/exporter/models.py new file mode 100644 index 0000000000..71a8362390 --- /dev/null +++ b/apps/exporter/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/apps/exporter/tests.py b/apps/exporter/tests.py new file mode 100644 index 0000000000..501deb776c --- /dev/null +++ b/apps/exporter/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/apps/exporter/urls.py b/apps/exporter/urls.py new file mode 100644 index 0000000000..73fda937a8 --- /dev/null +++ b/apps/exporter/urls.py @@ -0,0 +1,5 @@ +from django.conf.urls.defaults import patterns, url + +urlpatterns = patterns('exporter.views', + url(r'^export_test/$', 'export_test', (), 'export_test'), +) diff --git a/apps/exporter/views.py b/apps/exporter/views.py new file mode 100644 index 0000000000..407f3ffcc8 --- /dev/null +++ b/apps/exporter/views.py @@ -0,0 +1,150 @@ +import os +import hashlib + +from django.utils import simplejson +from django.http import HttpResponse +from django.template.defaultfilters import slugify + +from documents.models import Document, DocumentType +from metadata.models import MetadataType, MetadataSet + +FORMAT_VERSION = 1.0 +HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest() + + +def get_hash(obj): + if obj: + return u'%s_%s' % (HASH_FUNCTION(unicode(obj)), slugify(unicode(obj))) + else: + return None + + +''' + + +comments +tags +folders + +pages +pages transformation +metadata +doc_type metadata + +sources +sources transform + +users + +class DocumentTypeDefaults(models.Model): + """ + Default preselected metadata types and metadata set per document + type + """ + document_type = models.ForeignKey(DocumentType, verbose_name=_(u'document type')) + default_metadata_sets = models.ManyToManyField(MetadataSet, blank=True, verbose_name=_(u'default metadata sets')) + default_metadata = models.ManyToManyField(MetadataType, blank=True, verbose_name=_(u'default metadata')) + + +''' + +def export_test(request): + big_list = [] + big_list.append({'version': FORMAT_VERSION}) + + for metadata_type in MetadataType.objects.all(): + big_list.append( + { + 'metadata_types': [ + { + 'id': get_hash(metadata_type.name), + 'name': metadata_type.name, + 'title': metadata_type.title, + 'default': metadata_type.default, + 'lookup': metadata_type.lookup, + } + ] + } + ) + + for metadata_set in MetadataSet.objects.all(): + big_list.append( + { + 'metadata_sets': [ + { + 'id': get_hash(metadata_set.title), + 'name': metadata_set.title, + 'metadata_types': [ + { + 'id': get_hash(metadata_type), + } + for metadata_type in metadata_set.metadatasetitem_set.all() + ] + } + ] + } + ) + + + for document_type in DocumentType.objects.all(): + big_list.append( + { + 'document_types': [ + { + 'id': get_hash(document_type.name), + 'name': document_type.name, + 'filenames': [ + { + 'filename': doc_type_filename.filename, + 'enabled': doc_type_filename.enabled, + } + for doc_type_filename in document_type.documenttypefilename_set.all() + ], + 'metadata_defaults': [ + { + 'default_metadata': [get_hash(metadata_type.name) for metadata_type in doc_type_defaults.default_metadata.all()], + 'default_metadata_sets': [get_hash(metadata_set.title) for metadata_set in doc_type_defaults.default_metadata_sets.all()], + } + for doc_type_defaults in document_type.documenttypedefaults_set.all() + ] + } + ] + } + ) + + for document in Document.objects.all()[:10]: + big_list.append( + { + 'documents': [ + { + 'document_type': get_hash(document.document_type), + 'filename': os.extsep.join([document.file_filename, document.file_extension]), + #'date_added' + 'uuid': document.uuid, + 'description': unicode(document.description) if document.description else None, + 'tags': [get_hash(tag) for tag in document.tags.all()], + 'folders': [get_hash(folder_document.folder) for folder_document in document.folderdocument_set.all()], + 'comments': [ + { + 'comment': comment.comment, + 'user': unicode(comment.user), + 'submit_date': unicode(comment.submit_date), + } + for comment in document.comments.all() + ], + 'versions': [ + { + 1.0: { + 'mimetype': document.file_mimetype, + 'encoding': document.file_mime_encoding, + #'date_updated' + 'checksum': document.checksum, + } + } + ] + } + ] + } + ) + + return HttpResponse(simplejson.dumps(big_list, indent=4, ensure_ascii=True), mimetype='application/json') diff --git a/apps/folders/__init__.py b/apps/folders/__init__.py index c3f7408d06..e8aa591476 100644 --- a/apps/folders/__init__.py +++ b/apps/folders/__init__.py @@ -2,7 +2,6 @@ from django.utils.translation import ugettext_lazy as _ from navigation.api import register_links, register_top_menu, \ register_multi_item_links, register_sidebar_template -from navigation.api import register_sidebar_template from documents.models import Document from documents.literals import PERMISSION_DOCUMENT_VIEW diff --git a/apps/folders/views.py b/apps/folders/views.py index f846b7d2a9..b6495ffb05 100644 --- a/apps/folders/views.py +++ b/apps/folders/views.py @@ -9,7 +9,6 @@ from django.core.exceptions import PermissionDenied from documents.literals import PERMISSION_DOCUMENT_VIEW from documents.models import Document -from documents.widgets import document_thumbnail, document_link from permissions.api import check_permissions from common.utils import encapsulate @@ -36,6 +35,7 @@ def folder_list(request, queryset=None, extra_context=None): extra_context=context, ) + def folder_create(request): if request.method == 'POST': form = FolderForm(request.POST) @@ -202,7 +202,7 @@ def folder_add_document(request, document_id): return HttpResponseRedirect(next) else: form = AddDocumentForm(user=request.user) - + return render_to_response('generic_form.html', { 'title': _(u'add document "%s" to a folder') % document, 'form': form, @@ -210,12 +210,12 @@ def folder_add_document(request, document_id): 'next': next, }, context_instance=RequestContext(request)) - + def document_folder_list(request, document_id): check_permissions(request.user, [PERMISSION_DOCUMENT_VIEW]) document = get_object_or_404(Document, pk=document_id) - + return folder_list( request, queryset=Folder.objects.filter(user=request.user).filter(folderdocument__document=document), @@ -224,7 +224,7 @@ def document_folder_list(request, document_id): 'object': document, } ) - + def folder_document_remove(request, folder_id, document_id=None, document_id_list=None): post_action_redirect = None diff --git a/apps/history/api.py b/apps/history/api.py index 1e4dbf48b2..467f4c8035 100644 --- a/apps/history/api.py +++ b/apps/history/api.py @@ -10,7 +10,6 @@ except ImportError: from django.core.exceptions import ImproperlyConfigured from django.db import transaction from django.db.utils import DatabaseError -#from django.utils import simplejson from django.core import serializers from django.shortcuts import get_object_or_404 from django.db import models @@ -18,6 +17,7 @@ from django.db import models from history.models import HistoryType, History from history.runtime_data import history_types_dict + @transaction.commit_manually def register_history_type(history_type_dict): namespace = history_type_dict['namespace'] diff --git a/apps/metadata/__init__.py b/apps/metadata/__init__.py index 96d583a515..55e1ccfe96 100644 --- a/apps/metadata/__init__.py +++ b/apps/metadata/__init__.py @@ -61,7 +61,7 @@ setup_document_type_metadata = {'text': _(u'default metadata'), 'view': 'setup_d #register_links(Document, [metadata_add, metadata_edit, metadata_remove]) register_links(['metadata_add', 'metadata_edit', 'metadata_remove', 'metadata_view'], [metadata_add, metadata_edit, metadata_remove], menu_name='sidebar') -register_links(Document, [metadata_view], menu_name='form_header')#, metadata_edit, metadata_remove]) +register_links(Document, [metadata_view], menu_name='form_header') #, metadata_edit, metadata_remove]) register_multi_item_links(['document_find_duplicates', 'folder_view', 'index_instance_list', 'document_type_document_list', 'search', 'results', 'document_group_view', 'document_list', 'document_list_recent'], [metadata_multiple_add, metadata_multiple_edit, metadata_multiple_remove]) register_links(MetadataType, [setup_metadata_type_edit, setup_metadata_type_delete]) diff --git a/apps/mimetype/api.py b/apps/mimetype/api.py index 89b9dbd3fc..b4d0d86749 100644 --- a/apps/mimetype/api.py +++ b/apps/mimetype/api.py @@ -17,29 +17,29 @@ UNKNWON_TYPE_FILE_NAME = 'unknown.png' ERROR_FILE_NAME = 'error.png' mimetype_icons = { - 'application/pdf' : 'file_extension_pdf.png', - 'application/zip' : 'file_extension_zip.png', - 'application/ogg' : 'file_extension_ogg.png', - 'application/postscript' : 'file_extension_ps.png', - 'application/x-gzip' : 'file_extension_gz.png', - 'application/x-rar-compressed' : 'file_extension_rar.png', - 'application/x-troff-msvideo' : 'file_extension_avi.png', - 'application/acad' : 'file_extension_dwg.png', - 'application/octet-stream' : 'file_extension_exe.png', + 'application/pdf': 'file_extension_pdf.png', + 'application/zip': 'file_extension_zip.png', + 'application/ogg': 'file_extension_ogg.png', + 'application/postscript': 'file_extension_ps.png', + 'application/x-gzip': 'file_extension_gz.png', + 'application/x-rar-compressed': 'file_extension_rar.png', + 'application/x-troff-msvideo': 'file_extension_avi.png', + 'application/acad': 'file_extension_dwg.png', + 'application/octet-stream': 'file_extension_exe.png', 'application/vnd.oasis.opendocument.text': 'ODF_textdocument_32x32.png', 'application/vnd.oasis.opendocument.spreadsheet': 'ODF_spreadsheet_32x32.png', 'application/vnd.oasis.opendocument.presentation': 'ODF_presentation_32x32.png', 'application/vnd.oasis.opendocument.graphics': 'ODF_drawing_32x32.png', - 'application/vnd.ms-excel': 'file_extension_xls.png', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'file_extension_xls.png', + 'application/vnd.ms-excel': 'file_extension_xls.png', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'file_extension_xls.png', 'application/msword': 'file_extension_doc.png', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'file_extension_doc.png', 'application/mspowerpoint': 'file_extension_pps.png', 'application/vnd.ms-powerpoint': 'file_extension_pps.png', - 'application/wav' : 'file_extension_wav.png', - 'application/x-wav' : 'file_extension_wav.png', - 'application/vnd.oasis.opendocument.text' : 'ODF_textdocument_32x32.png', - + 'application/wav': 'file_extension_wav.png', + 'application/x-wav': 'file_extension_wav.png', + 'application/vnd.oasis.opendocument.text': 'ODF_textdocument_32x32.png', + 'image/jpeg' : 'file_extension_jpeg.png', 'image/png' : 'file_extension_png.png', 'image/x-png' : 'file_extension_png.png', @@ -49,7 +49,7 @@ mimetype_icons = { 'image/gif' : 'file_extension_gif.png', 'image/vnd.dwg' : 'file_extension_dwg.png', 'image/x-dwg' : 'file_extension_dwg.png', - + 'audio/mpeg' : 'file_extension_mp3.png', 'audio/mid' : 'file_extension_mid.png', 'audio/x-wav' : 'file_extension_wav.png', @@ -63,7 +63,7 @@ mimetype_icons = { 'video/quicktime' : 'file_extension_mov.png', 'video/x-ms-asf' : 'file_extension_asf.png', 'video/x-ms-wmv' : 'file_extension_wmv.png', - + 'text/html' : 'file_extension_html.png', 'text/plain' : 'file_extension_txt.png', } diff --git a/apps/ocr/__init__.py b/apps/ocr/__init__.py index 209b23145a..0c558617dc 100644 --- a/apps/ocr/__init__.py +++ b/apps/ocr/__init__.py @@ -73,6 +73,7 @@ register_tool(all_document_ocr_cleanup, namespace='ocr', title=_(u'OCR')) #Menus register_top_menu('ocr', link={'text': _('OCR'), 'famfam': 'hourglass', 'view': 'queue_document_list'}, children_path_regex=[r'^ocr/']) + @transaction.commit_manually def create_default_queue(): try: diff --git a/apps/ocr/managers.py b/apps/ocr/managers.py index a28ca8b195..a1fdb80b8c 100644 --- a/apps/ocr/managers.py +++ b/apps/ocr/managers.py @@ -1,5 +1,4 @@ from django.db import models -from django.contrib.contenttypes.models import ContentType from ocr.exceptions import AlreadyQueued diff --git a/apps/ocr/tasks.py b/apps/ocr/tasks.py index cceb77f034..dee3d64da9 100644 --- a/apps/ocr/tasks.py +++ b/apps/ocr/tasks.py @@ -4,7 +4,6 @@ from time import sleep from random import random from django.db.models import Q -from django.utils.translation import ugettext as _ from django.core.cache import get_cache from job_processor.api import process_job diff --git a/apps/sources/__init__.py b/apps/sources/__init__.py index 7f240fb4ca..9054815714 100644 --- a/apps/sources/__init__.py +++ b/apps/sources/__init__.py @@ -1,8 +1,7 @@ from django.utils.translation import ugettext_lazy as _ from navigation.api import register_links, \ - register_model_list_columns, register_multi_item_links, \ - register_sidebar_template + register_model_list_columns from permissions.api import register_permission, set_namespace_title from sources.staging import StagingFile diff --git a/apps/sources/compressed_file.py b/apps/sources/compressed_file.py index 1adc360fb6..be6b4decf3 100644 --- a/apps/sources/compressed_file.py +++ b/apps/sources/compressed_file.py @@ -11,7 +11,7 @@ class CompressedFile(object): def __init__(self, file_object): self.file_object = file_object - def children(self): + def children(self): try: # Try for a ZIP file zfobj = zipfile.ZipFile(self.file_object) @@ -19,6 +19,6 @@ class CompressedFile(object): return (SimpleUploadedFile(name=filename, content=zfobj.read(filename)) for filename in filenames) except zipfile.BadZipfile: raise NotACompressedFile - + #def close(self): # self.file_object.close() diff --git a/apps/sources/forms.py b/apps/sources/forms.py index 3f0b625887..fd4667bf38 100644 --- a/apps/sources/forms.py +++ b/apps/sources/forms.py @@ -56,34 +56,34 @@ class WebFormForm(DocumentForm): label=_(u'Expand compressed files'), required=False, help_text=ugettext(u'Upload a compressed file\'s contained files as individual documents') ) - + def clean_file(self): data = self.cleaned_data['file'] validate_whitelist_blacklist(data.name, self.source.whitelist.split(','), self.source.blacklist.split(',')) - return data + return data class WebFormSetupForm(forms.ModelForm): def __init__(self, *args, **kwargs): - super(WebFormSetupForm, self).__init__(*args, **kwargs) + super(WebFormSetupForm, self).__init__(*args, **kwargs) self.fields['icon'].widget = FamFamRadioSelect( attrs=self.fields['icon'].widget.attrs, choices=self.fields['icon'].widget.choices, ) - + class Meta: model = WebForm - - + + class StagingFolderSetupForm(forms.ModelForm): def __init__(self, *args, **kwargs): - super(StagingFolderSetupForm, self).__init__(*args, **kwargs) + super(StagingFolderSetupForm, self).__init__(*args, **kwargs) self.fields['icon'].widget = FamFamRadioSelect( attrs=self.fields['icon'].widget.attrs, choices=self.fields['icon'].widget.choices, ) - + class Meta: model = StagingFolder @@ -91,7 +91,7 @@ class StagingFolderSetupForm(forms.ModelForm): class WatchFolderSetupForm(forms.ModelForm): class Meta: model = WatchFolder - + class SourceTransformationForm(forms.ModelForm): class Meta: diff --git a/apps/sources/models.py b/apps/sources/models.py index a383286343..c97f2f4ca4 100644 --- a/apps/sources/models.py +++ b/apps/sources/models.py @@ -8,7 +8,7 @@ from django.core.exceptions import ValidationError from converter.api import get_available_transformations_choices from converter.literals import DIMENSION_SEPARATOR -from documents.models import DocumentType, Document#, RecentDocument +from documents.models import DocumentType, Document from documents.literals import HISTORY_DOCUMENT_CREATED from document_indexing.api import update_indexes from history.api import create_history @@ -145,6 +145,7 @@ class SourceMetadata(models.Model): verbose_name_plural = _(u'sources metadata') ''' + class WebForm(InteractiveBaseModel): is_interactive = True source_type = SOURCE_CHOICE_WEB_FORM diff --git a/apps/sources/staging.py b/apps/sources/staging.py index 3c8935630c..8a0a200859 100644 --- a/apps/sources/staging.py +++ b/apps/sources/staging.py @@ -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.utils.translation import ugettext_lazy as _ from mimetype.api import get_icon_file_path, get_error_icon_file_path, \ get_mimetype diff --git a/apps/sources/utils.py b/apps/sources/utils.py index e1900db5a9..6d61ad9ebb 100644 --- a/apps/sources/utils.py +++ b/apps/sources/utils.py @@ -5,9 +5,11 @@ from django.utils.translation import ugettext # From http://www.peterbe.com/plog/whitelist-blacklist-logic -def accept_item(value, whitelist, blacklist, default_accept=True): - """ return true if this item is either whitelisted or - not blacklisted """ +def accept_item(value, whitelist, blacklist, default_accept=True): + """ + return true if this item is either whitelisted or + not blacklisted + """ if not whitelist: whitelist = [] @@ -18,9 +20,9 @@ def accept_item(value, whitelist, blacklist, default_accept=True): for reject, item_list in ([False, whitelist], [True, blacklist]): #print 'item_list: %s' % item_list #print 'reject: %s' % reject - for okpattern in item_list: + for okpattern in item_list: #print 'okpattern: %s' % okpattern - if re.findall(okpattern.replace('*','\S+'), value, re.I): + if re.findall(okpattern.replace('*', '\S+'), value, re.I): # match! #print 'MATCH' if reject: diff --git a/apps/sources/views.py b/apps/sources/views.py index 3f1d376585..c2cde5e7d8 100644 --- a/apps/sources/views.py +++ b/apps/sources/views.py @@ -29,7 +29,7 @@ from sources.forms import SourceTransformationForm, SourceTransformationForm_cre from sources import PERMISSION_SOURCES_SETUP_VIEW, \ PERMISSION_SOURCES_SETUP_EDIT, PERMISSION_SOURCES_SETUP_DELETE, \ PERMISSION_SOURCES_SETUP_CREATE - + def return_function(obj): return lambda context: context['source'].source_type == obj.source_type and context['source'].pk == obj.pk @@ -59,13 +59,13 @@ def get_active_tab_links(): 'keep_query': True, 'conditional_highlight': return_function(staging_folder), }) - + return { 'tab_links': tab_links, SOURCE_CHOICE_WEB_FORM: web_forms, SOURCE_CHOICE_STAGING: staging_folders } - + def upload_interactive(request, source_type=None, source_id=None): check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE]) @@ -140,7 +140,7 @@ def upload_interactive(request, source_type=None, source_id=None): return HttpResponseRedirect(request.get_full_path()) else: form = WebFormForm( - show_expand=(web_form.uncompress==SOURCE_UNCOMPRESS_CHOICE_ASK), + show_expand=(web_form.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK), document_type=document_type, source=web_form ) @@ -159,7 +159,7 @@ def upload_interactive(request, source_type=None, source_id=None): if request.method == 'POST': form = StagingDocumentForm(request.POST, request.FILES, cls=StagingFile, document_type=document_type, - show_expand=(staging_folder.uncompress==SOURCE_UNCOMPRESS_CHOICE_ASK), + show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK), source=staging_folder ) if form.is_valid(): @@ -171,14 +171,14 @@ def upload_interactive(request, source_type=None, source_id=None): if staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_Y: expand = True else: - expand = False + expand = False new_filename = get_form_filename(form) staging_folder.upload_file(staging_file.upload(), new_filename, document_type=document_type, expand=expand, metadata_dict_list=decode_metadata_from_url(request.GET), user=request.user - ) + ) messages.success(request, _(u'Staging file: %s, uploaded successfully.') % staging_file.filename) if staging_folder.delete_after_upload: @@ -191,8 +191,8 @@ def upload_interactive(request, source_type=None, source_id=None): return HttpResponseRedirect(request.get_full_path()) else: form = StagingDocumentForm(cls=StagingFile, - document_type=document_type, - show_expand=(staging_folder.uncompress==SOURCE_UNCOMPRESS_CHOICE_ASK), + document_type=document_type, + show_expand=(staging_folder.uncompress == SOURCE_UNCOMPRESS_CHOICE_ASK), source=staging_folder ) try: @@ -217,7 +217,7 @@ def upload_interactive(request, source_type=None, source_id=None): 'hide_link': True, } }, - ] + ] context.update({ 'document_type_id': document_type_id, @@ -234,7 +234,7 @@ def upload_interactive(request, source_type=None, source_id=None): 'temporary_navigation_links': {'form_header': {'upload_interactive': {'links': results['tab_links']}}}, }) return render_to_response('generic_form.html', context, - context_instance=RequestContext(request)) + context_instance=RequestContext(request)) def get_form_filename(form): @@ -246,16 +246,16 @@ def get_form_filename(form): if form and 'document_type_available_filenames' in form.cleaned_data: if form.cleaned_data['document_type_available_filenames']: return form.cleaned_data['document_type_available_filenames'].filename - + return filename - - + + def staging_file_preview(request, source_type, source_id, staging_file_id): check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE]) staging_folder = get_object_or_404(StagingFolder, pk=source_id) StagingFile = create_staging_file_class(request, staging_folder.folder_path) transformations, errors = SourceTransformation.transformations.get_for_object_as_list(staging_folder) - + output_file = StagingFile.get(staging_file_id).get_image( size=staging_folder.get_preview_size(), transformations=transformations @@ -274,7 +274,7 @@ def staging_file_thumbnail(request, source_id, staging_file_id): staging_folder = get_object_or_404(StagingFolder, pk=source_id) StagingFile = create_staging_file_class(request, staging_folder.folder_path, source=staging_folder) transformations, errors = SourceTransformation.transformations.get_for_object_as_list(staging_folder) - + output_file = StagingFile.get(staging_file_id).get_image( size=THUMBNAIL_SIZE, transformations=transformations @@ -291,7 +291,7 @@ def staging_file_thumbnail(request, source_id, staging_file_id): def staging_file_delete(request, source_type, source_id, staging_file_id): check_permissions(request.user, [PERMISSION_DOCUMENT_CREATE]) staging_folder = get_object_or_404(StagingFolder, pk=source_id) - StagingFile = create_staging_file_class(request, staging_folder.folder_path) + StagingFile = create_staging_file_class(request, staging_folder.folder_path) staging_file = StagingFile.get(staging_file_id) next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', '/'))) @@ -299,7 +299,7 @@ def staging_file_delete(request, source_type, source_id, staging_file_id): if request.method == 'POST': try: - transformations, errors=SourceTransformation.transformations.get_for_object_as_list(staging_folder) + transformations, errors = SourceTransformation.transformations.get_for_object_as_list(staging_folder) staging_file.delete( preview_size=staging_folder.get_preview_size(), transformations=transformations @@ -310,7 +310,7 @@ def staging_file_delete(request, source_type, source_id, staging_file_id): return HttpResponseRedirect(next) results = get_active_tab_links() - + return render_to_response('generic_confirm.html', { 'source': staging_folder, 'delete_view': True, @@ -324,14 +324,14 @@ def staging_file_delete(request, source_type, source_id, staging_file_id): def setup_source_list(request, source_type): check_permissions(request.user, [PERMISSION_SOURCES_SETUP_VIEW]) - + if source_type == SOURCE_CHOICE_WEB_FORM: cls = WebForm elif source_type == SOURCE_CHOICE_STAGING: cls = StagingFolder elif source_type == SOURCE_CHOICE_WATCH: cls = WatchFolder - + context = { 'object_list': cls.objects.all(), 'title': cls.class_fullname_plural(), diff --git a/apps/sources/widgets.py b/apps/sources/widgets.py index 472607f19f..59f4de1f5a 100644 --- a/apps/sources/widgets.py +++ b/apps/sources/widgets.py @@ -16,7 +16,7 @@ class FamFamRadioFieldRenderer(forms.widgets.RadioFieldRenderer): else: famfam_template = u'' results.append(u'
  • %s%s
  • ' % (famfam_template, force_unicode(w))) - + results.append(u'\n') return mark_safe(u'\n'.join(results)) diff --git a/apps/web_theme/templatetags/theme_tags.py b/apps/web_theme/templatetags/theme_tags.py index 4414d35a2b..05878bf798 100644 --- a/apps/web_theme/templatetags/theme_tags.py +++ b/apps/web_theme/templatetags/theme_tags.py @@ -59,7 +59,6 @@ class SettingsNode(Node): context[self.var_name] = getattr(web_theme_settings, self.format_string, '') return '' -from django.utils.safestring import mark_safe @register.tag def get_web_theme_setting(parser, token):