From 75266c7c310c7d705dddf802f31423584587a387 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 3 Jul 2014 17:32:32 -0400 Subject: [PATCH] Update the documents app and the document_signatures app to use the new method of loading backends --- mayan/apps/converter/runtime.py | 2 +- mayan/apps/document_signatures/models.py | 6 +++--- mayan/apps/documents/conf/settings.py | 8 ++++---- mayan/apps/documents/models.py | 6 +++--- mayan/apps/documents/runtime.py | 7 +++++++ mayan/apps/ocr/runtime.py | 4 ++-- 6 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 mayan/apps/documents/runtime.py diff --git a/mayan/apps/converter/runtime.py b/mayan/apps/converter/runtime.py index 7236facaac..5c301913d0 100644 --- a/mayan/apps/converter/runtime.py +++ b/mayan/apps/converter/runtime.py @@ -11,4 +11,4 @@ try: except OfficeBackendError: office_converter = None -backend = load_backend(GRAPHICS_BACKEND) +backend = load_backend(GRAPHICS_BACKEND)() diff --git a/mayan/apps/document_signatures/models.py b/mayan/apps/document_signatures/models.py index 970826e709..40bf886913 100644 --- a/mayan/apps/document_signatures/models.py +++ b/mayan/apps/document_signatures/models.py @@ -4,9 +4,9 @@ import logging from django.db import models from django.utils.translation import ugettext_lazy as _ -from documents.models import DocumentVersion, get_filename_from_uuid -from documents.conf.settings import STORAGE_BACKEND from django_gpg.runtime import gpg +from documents.models import DocumentVersion, get_filename_from_uuid +from documents.runtime import storage_backend from .managers import DocumentVersionSignatureManager @@ -18,7 +18,7 @@ class DocumentVersionSignature(models.Model): Model that describes a document version signature properties """ document_version = models.ForeignKey(DocumentVersion, verbose_name=_(u'document version'), editable=False) - signature_file = models.FileField(blank=True, null=True, upload_to=get_filename_from_uuid, storage=STORAGE_BACKEND(), verbose_name=_(u'signature file'), editable=False) + signature_file = models.FileField(blank=True, null=True, upload_to=get_filename_from_uuid, storage=storage_backend, verbose_name=_(u'signature file'), editable=False) has_embedded_signature = models.BooleanField(default=False, verbose_name=_(u'has embedded signature'), editable=False) objects = DocumentVersionSignatureManager() diff --git a/mayan/apps/documents/conf/settings.py b/mayan/apps/documents/conf/settings.py index f077d93c08..30f2d94c03 100644 --- a/mayan/apps/documents/conf/settings.py +++ b/mayan/apps/documents/conf/settings.py @@ -1,13 +1,12 @@ """Configuration options for the documents app""" import hashlib -import uuid import os +import uuid -from django.utils.translation import ugettext_lazy as _ from django.conf import settings +from django.utils.translation import ugettext_lazy as _ -from storage.backends.filebasedstorage import FileBasedStorage from smart_settings.api import register_settings @@ -20,6 +19,7 @@ def default_uuid(): """unicode(uuid.uuid4())""" return unicode(uuid.uuid4()) + register_settings( namespace=u'documents', module=u'documents.conf.settings', @@ -28,7 +28,7 @@ register_settings( {'name': u'CHECKSUM_FUNCTION', 'global_name': u'DOCUMENTS_CHECKSUM_FUNCTION', 'default': default_checksum}, {'name': u'UUID_FUNCTION', 'global_name': u'DOCUMENTS_UUID_FUNCTION', 'default': default_uuid}, # Storage - {'name': u'STORAGE_BACKEND', 'global_name': u'DOCUMENTS_STORAGE_BACKEND', 'default': FileBasedStorage}, + {'name': u'STORAGE_BACKEND', 'global_name': u'DOCUMENTS_STORAGE_BACKEND', 'default': 'storage.backends.filebasedstorage.FileBasedStorage'}, # Usage {'name': u'PREVIEW_SIZE', 'global_name': u'DOCUMENTS_PREVIEW_SIZE', 'default': u'640x480'}, {'name': u'PRINT_SIZE', 'global_name': u'DOCUMENTS_PRINT_SIZE', 'default': u'1400'}, diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index c0ea043b87..b4cbc5e3ba 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -26,13 +26,13 @@ from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, from mimetype.api import get_mimetype from .conf.settings import (CHECKSUM_FUNCTION, UUID_FUNCTION, - STORAGE_BACKEND, DISPLAY_SIZE, CACHE_PATH, - ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL) + DISPLAY_SIZE, CACHE_PATH, ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL) from .exceptions import NewDocumentVersionNotAllowed from .literals import (RELEASE_LEVEL_FINAL, RELEASE_LEVEL_CHOICES, VERSION_UPDATE_MAJOR, VERSION_UPDATE_MINOR, VERSION_UPDATE_MICRO) from .managers import (DocumentPageTransformationManager, RecentDocumentManager, DocumentTypeManager) +from .runtime import storage_backend from .utils import document_save_to_temp_dir # document image cache name hash function @@ -307,7 +307,7 @@ class DocumentVersion(models.Model): comment = models.TextField(blank=True, verbose_name=_(u'comment')) # File related fields - file = models.FileField(upload_to=get_filename_from_uuid, storage=STORAGE_BACKEND(), verbose_name=_(u'file')) + file = models.FileField(upload_to=get_filename_from_uuid, storage=storage_backend, verbose_name=_(u'file')) mimetype = models.CharField(max_length=255, null=True, blank=True, editable=False) encoding = models.CharField(max_length=64, null=True, blank=True, editable=False) filename = models.CharField(max_length=255, default=u'', editable=False, db_index=True) diff --git a/mayan/apps/documents/runtime.py b/mayan/apps/documents/runtime.py new file mode 100644 index 0000000000..44276cb533 --- /dev/null +++ b/mayan/apps/documents/runtime.py @@ -0,0 +1,7 @@ +from __future__ import absolute_import + +from common.utils import load_backend + +from .conf.settings import STORAGE_BACKEND + +storage_backend = load_backend(STORAGE_BACKEND)() diff --git a/mayan/apps/ocr/runtime.py b/mayan/apps/ocr/runtime.py index 0a52ad8fe1..e79252fc33 100644 --- a/mayan/apps/ocr/runtime.py +++ b/mayan/apps/ocr/runtime.py @@ -5,8 +5,8 @@ from common.utils import load_backend from .conf.settings import BACKEND, LANGUAGE try: - language_backend = load_backend(u'.'.join([u'ocr', u'lang', LANGUAGE, u'LanguageBackend'])) + language_backend = load_backend(u'.'.join([u'ocr', u'lang', LANGUAGE, u'LanguageBackend']))() except ImportError: language_backend = None -ocr_backend = load_backend(BACKEND) +ocr_backend = load_backend(BACKEND)()