From da5445eef9fbf6ca62c6eb8329ff4aba6b6d5e27 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 5 Apr 2018 19:30:59 -0400 Subject: [PATCH] Rename the storages instance names for consistency. Signed-off-by: Roberto Rosario --- mayan/apps/document_signatures/models.py | 6 ++-- mayan/apps/document_signatures/storages.py | 2 +- mayan/apps/documents/api_views.py | 4 +-- mayan/apps/documents/models.py | 36 +++++++++++----------- mayan/apps/documents/storages.py | 4 +-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/mayan/apps/document_signatures/models.py b/mayan/apps/document_signatures/models.py index 6366b23789..f3409d35db 100644 --- a/mayan/apps/document_signatures/models.py +++ b/mayan/apps/document_signatures/models.py @@ -15,7 +15,7 @@ from django_gpg.models import Key from documents.models import DocumentVersion from .managers import EmbeddedSignatureManager -from .storages import storage_backend +from .storages import storage_detachedsignature logger = logging.getLogger(__name__) @@ -127,8 +127,8 @@ class EmbeddedSignature(SignatureBaseModel): @python_2_unicode_compatible class DetachedSignature(SignatureBaseModel): signature_file = models.FileField( - blank=True, null=True, storage=storage_backend, upload_to=upload_to, - verbose_name=_('Signature file') + blank=True, null=True, storage=storage_detachedsignature, + upload_to=upload_to, verbose_name=_('Signature file') ) # Don't inherit the SignatureBaseModel manager diff --git a/mayan/apps/document_signatures/storages.py b/mayan/apps/document_signatures/storages.py index 52000433f0..0393501def 100644 --- a/mayan/apps/document_signatures/storages.py +++ b/mayan/apps/document_signatures/storages.py @@ -8,7 +8,7 @@ from .settings import ( setting_storage_backend, setting_storage_backend_arguments ) -storage_backend = import_string( +storage_detachedsignature = import_string( dotted_path=setting_storage_backend.value )( **yaml.safe_load( diff --git a/mayan/apps/documents/api_views.py b/mayan/apps/documents/api_views.py index 5d79656fb7..f57a2ad741 100644 --- a/mayan/apps/documents/api_views.py +++ b/mayan/apps/documents/api_views.py @@ -34,7 +34,7 @@ from .serializers import ( RecentDocumentSerializer, WritableDocumentSerializer, WritableDocumentTypeSerializer, WritableDocumentVersionSerializer ) -from .storages import documentimagecache_storage +from .storages import storage_documentimagecache from .tasks import task_generate_document_page_image logger = logging.getLogger(__name__) @@ -288,7 +288,7 @@ class APIDocumentPageImageView(generics.RetrieveAPIView): ) cache_filename = task.get(timeout=DOCUMENT_IMAGE_TASK_TIMEOUT) - with documentimagecache_storage.open(cache_filename) as file_object: + with storage_documentimagecache.open(cache_filename) as file_object: return HttpResponse(file_object.read(), content_type='image') diff --git a/mayan/apps/documents/models.py b/mayan/apps/documents/models.py index 4a1486467e..e10f21bd83 100644 --- a/mayan/apps/documents/models.py +++ b/mayan/apps/documents/models.py @@ -45,7 +45,7 @@ from .settings import ( from .signals import ( post_document_created, post_document_type_change, post_version_upload ) -from .storages import documentversion_storage, documentimagecache_storage +from .storages import storage_documentversion, storage_documentimagecache logger = logging.getLogger(__name__) @@ -394,7 +394,7 @@ class DocumentVersion(models.Model): # File related fields file = models.FileField( - storage=documentversion_storage, upload_to=UUID_FUNCTION, + storage=storage_documentversion, upload_to=UUID_FUNCTION, verbose_name=_('File') ) mimetype = models.CharField( @@ -460,10 +460,10 @@ class DocumentVersion(models.Model): cache_filename = self.cache_filename logger.debug('Intermidiate filename: %s', cache_filename) - if documentimagecache_storage.exists(cache_filename): + if storage_documentimagecache.exists(cache_filename): logger.debug('Intermidiate file "%s" found.', cache_filename) - return documentimagecache_storage.open(cache_filename) + return storage_documentimagecache.open(cache_filename) else: logger.debug('Intermidiate file "%s" not found.', cache_filename) @@ -471,11 +471,11 @@ class DocumentVersion(models.Model): converter = converter_class(file_object=self.open()) pdf_file_object = converter.to_pdf() - with documentimagecache_storage.open(cache_filename, 'wb+') as file_object: + with storage_documentimagecache.open(cache_filename, 'wb+') as file_object: for chunk in pdf_file_object: file_object.write(chunk) - return documentimagecache_storage.open(cache_filename) + return storage_documentimagecache.open(cache_filename) except InvalidOfficeFormat: return self.open() except Exception as exception: @@ -484,7 +484,7 @@ class DocumentVersion(models.Model): 'Error creating intermediate file "%s"; %s.', cache_filename, exception ) - documentimagecache_storage.delete(cache_filename) + storage_documentimagecache.delete(cache_filename) raise def get_rendered_string(self, preserve_extension=False): @@ -504,7 +504,7 @@ class DocumentVersion(models.Model): ) def invalidate_cache(self): - documentimagecache_storage.delete(self.cache_filename) + storage_documentimagecache.delete(self.cache_filename) for page in self.pages.all(): page.invalidate_cache() @@ -811,7 +811,7 @@ class DocumentPage(models.Model): # Check is transformed image is available logger.debug('transformations cache filename: %s', cache_filename) - if not setting_disable_transformed_image_cache.value and documentimagecache_storage.exists(cache_filename): + if not setting_disable_transformed_image_cache.value and storage_documentimagecache.exists(cache_filename): logger.debug( 'transformations cache file "%s" found', cache_filename ) @@ -820,7 +820,7 @@ class DocumentPage(models.Model): 'transformations cache file "%s" not found', cache_filename ) image = self.get_image(transformations=transformation_list) - with documentimagecache_storage.open(cache_filename, 'wb+') as file_object: + with storage_documentimagecache.open(cache_filename, 'wb+') as file_object: file_object.write(image.getvalue()) self.cached_images.create(filename=cache_filename) @@ -841,10 +841,10 @@ class DocumentPage(models.Model): cache_filename = self.cache_filename logger.debug('Page cache filename: %s', cache_filename) - if not setting_disable_base_image_cache.value and documentimagecache_storage.exists(cache_filename): + if not setting_disable_base_image_cache.value and storage_documentimagecache.exists(cache_filename): logger.debug('Page cache file "%s" found', cache_filename) converter = converter_class( - file_object=documentimagecache_storage.open(cache_filename) + file_object=storage_documentimagecache.open(cache_filename) ) converter.seek(0) @@ -861,10 +861,10 @@ class DocumentPage(models.Model): # Since open "wb+" doesn't create files, check if the file # exists, if not then create it - if not documentimagecache_storage.exists(cache_filename): - documentimagecache_storage.save(name=cache_filename, content=ContentFile(content='')) + if not storage_documentimagecache.exists(cache_filename): + storage_documentimagecache.save(name=cache_filename, content=ContentFile(content='')) - with documentimagecache_storage.open(cache_filename, 'wb+') as file_object: + with storage_documentimagecache.open(cache_filename, 'wb+') as file_object: file_object.write(page_image.getvalue()) except Exception as exception: # Cleanup in case of error @@ -872,7 +872,7 @@ class DocumentPage(models.Model): 'Error creating page cache file "%s"; %s', cache_filename, exception ) - documentimagecache_storage.delete(cache_filename) + storage_documentimagecache.delete(cache_filename) raise for transformation in transformations: @@ -881,7 +881,7 @@ class DocumentPage(models.Model): return converter.get_page() def invalidate_cache(self): - documentimagecache_storage.delete(self.cache_filename) + storage_documentimagecache.delete(self.cache_filename) for cached_image in self.cached_images.all(): cached_image.delete() @@ -912,7 +912,7 @@ class DocumentPageCachedImage(models.Model): verbose_name_plural = _('Document page cached images') def delete(self, *args, **kwargs): - documentimagecache_storage.delete(self.filename) + storage_documentimagecache.delete(self.filename) return super(DocumentPageCachedImage, self).delete(*args, **kwargs) diff --git a/mayan/apps/documents/storages.py b/mayan/apps/documents/storages.py index f7c9a4aeb8..ae61eed877 100644 --- a/mayan/apps/documents/storages.py +++ b/mayan/apps/documents/storages.py @@ -9,7 +9,7 @@ from .settings import ( setting_storage_backend, setting_storage_backend_arguments ) -documentversion_storage = import_string( +storage_documentversion = import_string( dotted_path=setting_storage_backend.value )( **yaml.safe_load( @@ -17,7 +17,7 @@ documentversion_storage = import_string( ) ) -documentimagecache_storage = import_string( +storage_documentimagecache = import_string( dotted_path=setting_documentimagecache_storage.value )( **yaml.safe_load(