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
+10
View File
@@ -72,6 +72,16 @@ class ErrorLogNamespace(object):
return ErrorLogEntry.objects.filter(namespace=self.name)
class FakeStorageSubclass(object):
"""
Placeholder class to allow serializing the real storage subclass to
support migrations.
"""
def __eq__(self, other):
return True
class MissingItem(object):
_registry = []
@@ -1,10 +1,10 @@
# -*- 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:38
from __future__ import unicode_literals
from django.db import migrations, models
import mayan.apps.common.classes
import mayan.apps.common.models
import mayan.apps.common.storages
class Migration(migrations.Migration):
@@ -17,6 +17,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='shareduploadedfile',
name='file',
field=models.FileField(storage=mayan.apps.common.storages.storage_sharedupload_wrapper, upload_to=mayan.apps.common.models.upload_to, verbose_name='File'),
field=models.FileField(storage=mayan.apps.common.classes.FakeStorageSubclass(), upload_to=mayan.apps.common.models.upload_to, verbose_name='File'),
),
]
+2 -2
View File
@@ -13,7 +13,7 @@ from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from .managers import ErrorLogEntryManager, UserLocaleProfileManager
from .storages import storage_sharedupload_wrapper
from .storages import storage_sharedupload
logger = logging.getLogger(__name__)
@@ -58,7 +58,7 @@ class SharedUploadedFile(models.Model):
that runs out of process.
"""
file = models.FileField(
storage=storage_sharedupload_wrapper, upload_to=upload_to,
storage=storage_sharedupload, upload_to=upload_to,
verbose_name=_('File')
)
filename = models.CharField(max_length=255, verbose_name=_('Filename'))
+2 -7
View File
@@ -1,13 +1,8 @@
from __future__ import unicode_literals
from django.utils.module_loading import import_string
from .settings import setting_shared_storage, setting_shared_storage_arguments
from .utils import get_storage_subclass
storage_sharedupload = import_string(
storage_sharedupload = get_storage_subclass(
dotted_path=setting_shared_storage.value
)(**setting_shared_storage_arguments.value)
def storage_sharedupload_wrapper():
return storage_sharedupload
+23
View File
@@ -12,6 +12,7 @@ from django.urls.base import get_script_prefix
from django.utils.datastructures import MultiValueDict
from django.utils.http import urlencode as django_urlencode
from django.utils.http import urlquote as django_urlquote
from django.utils.module_loading import import_string
from django.utils.six.moves import reduce as reduce_function
from django.utils.six.moves import xmlrpc_client
@@ -100,6 +101,28 @@ def get_descriptor(file_input, read=True):
return file_input
def get_storage_subclass(dotted_path):
"""
Import a storage class and return a subclass that will always return eq
True to avoid creating a new migration when for runtime storage class
changes.
"""
imported_storage_class = import_string(dotted_path=dotted_path)
class StorageSubclass(imported_storage_class):
def __init__(self, *args, **kwargs):
return super(StorageSubclass, self).__init__(*args, **kwargs)
def __eq__(self, other):
return True
def deconstruct(self):
return ('mayan.apps.common.classes.FakeStorageSubclass', (), {})
return StorageSubclass
def TemporaryFile(*args, **kwargs):
kwargs.update({'dir': setting_temporary_directory.value})
return tempfile.TemporaryFile(*args, **kwargs)