Remove use of storage wrappers

Use a dynamic subclass instead that always deconstructs to a fake
subclass with a __eq__ method that always returns True. This should
trick makemigrations into never creating a new migrations for
changes to the storage class or the arguments.

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-29 03:45:56 -04:00
parent 442bf5dc4b
commit 000fe87c37
11 changed files with 59 additions and 35 deletions
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.16 on 2018-12-28 04:22
# Generated by Django 1.11.16 on 2018-12-29 07:45
from __future__ import unicode_literals
from django.db import migrations, models
import mayan.apps.documents.storages
import mayan.apps.common.classes
import mayan.apps.documents.utils
@@ -17,6 +17,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='documentversion',
name='file',
field=models.FileField(storage=mayan.apps.documents.storages.storage_documentversion_wrapper, upload_to=mayan.apps.documents.utils.document_uuid_function, verbose_name='File'),
field=models.FileField(storage=mayan.apps.common.classes.FakeStorageSubclass(), upload_to=mayan.apps.documents.utils.document_uuid_function, verbose_name='File'),
),
]
@@ -21,7 +21,7 @@ from ..literals import DOCUMENT_IMAGES_CACHE_NAME
from ..managers import DocumentVersionManager
from ..settings import setting_fix_orientation
from ..signals import post_document_created, post_version_upload
from ..storages import storage_documentversion_wrapper
from ..storages import storage_documentversion
from ..utils import document_hash_function, document_uuid_function
from .document_models import Document
@@ -67,7 +67,7 @@ class DocumentVersion(models.Model):
# File related fields
file = models.FileField(
storage=storage_documentversion_wrapper, upload_to=document_uuid_function,
storage=storage_documentversion, upload_to=document_uuid_function,
verbose_name=_('File')
)
mimetype = models.CharField(
@@ -137,7 +137,7 @@ class DocumentVersion(models.Model):
be in the document storage. This is a diagnostic flag to help users
detect if the storage has desynchronized (ie: Amazon's S3).
"""
return self.file.storage().exists(self.file.name)
return self.file.storage.exists(self.file.name)
def fix_orientation(self):
for page in self.pages.all():
@@ -329,7 +329,7 @@ class DocumentVersion(models.Model):
@property
def size(self):
if self.exists():
return self.file.storage().size(self.file.name)
return self.file.storage.size(self.file.name)
else:
return None
+3 -5
View File
@@ -2,20 +2,18 @@ from __future__ import unicode_literals
from django.utils.module_loading import import_string
from mayan.apps.common.utils import get_storage_subclass
from .settings import (
setting_documentimagecache_storage,
setting_documentimagecache_storage_arguments, setting_storage_backend,
setting_storage_backend_arguments
)
storage_documentversion = import_string(
storage_documentversion = get_storage_subclass(
dotted_path=setting_storage_backend.value
)(**setting_storage_backend_arguments.value)
storage_documentimagecache = import_string(
dotted_path=setting_documentimagecache_storage.value
)(**setting_documentimagecache_storage_arguments.value)
def storage_documentversion_wrapper():
return storage_documentversion