Backport FakeStorageSubclass from versions/next

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-07-11 01:56:06 -04:00
parent 3fab5c1427
commit 1ab7b7b9b1
12 changed files with 131 additions and 11 deletions

View File

@@ -28,6 +28,9 @@
doing atabase etup.
- Added support for YAML encoded environment variables to the platform
templates apps.
- Move YAML code to its own module.
- Move Django and Celery settings.
- Backport FakeStorageSubclass from versions/next.
3.2.6 (2019-07-10)
==================

View File

@@ -38,6 +38,14 @@ Changes
is now done using MAYAN_DATABASES to mirror Django way of doing database setup.
- Added support for YAML encoded environment variables to the platform
templates apps.
- Move YAML code to its own module. Code now resides in common.serialization
in the form of two new functions: yaml_load and yaml_dump.
- Move Django and Celery settings. Django settings now reside in the smart
settings app. Celery settings now reside in the task manager app.
- Backport FakeStorageSubclass from versions/next. Placeholder class to allow
serializing the real storage subclass to support migrations.
Used by all configurable storages.
Removals
--------

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +1,11 @@
from __future__ import unicode_literals
from django.utils.module_loading import import_string
from mayan.apps.storage.utils import get_storage_subclass
from .settings import (
setting_shared_storage, setting_shared_storage_arguments
)
storage_sharedupload = import_string(
storage_sharedupload = get_storage_subclass(
dotted_path=setting_shared_storage.value
)(**setting_shared_storage_arguments.value)

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.22 on 2019-07-11 05:44
from __future__ import unicode_literals
from django.db import migrations, models
import mayan.apps.document_signatures.models
import mayan.apps.storage.classes
class Migration(migrations.Migration):
dependencies = [
('document_signatures', '0008_auto_20180429_0759'),
]
operations = [
migrations.AlterField(
model_name='detachedsignature',
name='signature_file',
field=models.FileField(blank=True, null=True, storage=mayan.apps.storage.classes.FakeStorageSubclass(), upload_to=mayan.apps.document_signatures.models.upload_to, verbose_name='Signature file'),
),
]

View File

@@ -1,11 +1,11 @@
from __future__ import unicode_literals
from django.utils.module_loading import import_string
from mayan.apps.storage.utils import get_storage_subclass
from .settings import (
setting_storage_backend, setting_storage_backend_arguments
)
storage_detachedsignature = import_string(
storage_detachedsignature = get_storage_subclass(
dotted_path=setting_storage_backend.value
)(**setting_storage_backend_arguments.value)

View File

@@ -1,12 +1,12 @@
from __future__ import unicode_literals
from django.utils.module_loading import import_string
from mayan.apps.storage.utils import get_storage_subclass
from .settings import (
setting_workflowimagecache_storage,
setting_workflowimagecache_storage_arguments
)
storage_workflowimagecache = import_string(
storage_workflowimagecache = get_storage_subclass(
dotted_path=setting_workflowimagecache_storage.value
)(**setting_workflowimagecache_storage_arguments.value)

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.22 on 2019-07-11 05:44
from __future__ import unicode_literals
from django.db import migrations, models
import mayan.apps.documents.models.document_version_models
import mayan.apps.storage.classes
class Migration(migrations.Migration):
dependencies = [
('documents', '0047_auto_20180917_0737'),
]
operations = [
migrations.AlterField(
model_name='documentversion',
name='file',
field=models.FileField(storage=mayan.apps.storage.classes.FakeStorageSubclass(), upload_to=mayan.apps.documents.models.document_version_models.UUID_FUNCTION, verbose_name='File'),
),
]

View File

@@ -1,6 +1,6 @@
from __future__ import unicode_literals
from django.utils.module_loading import import_string
from mayan.apps.storage.utils import get_storage_subclass
from .settings import (
setting_documentimagecache_storage,
@@ -8,10 +8,10 @@ from .settings import (
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(
storage_documentimagecache = get_storage_subclass(
dotted_path=setting_documentimagecache_storage.value
)(**setting_documentimagecache_storage_arguments.value)

View File

@@ -1,12 +1,12 @@
from __future__ import unicode_literals
from django.utils.module_loading import import_string
from mayan.apps.storage.utils import get_storage_subclass
from .settings import (
setting_staging_file_image_cache_storage,
setting_staging_file_image_cache_storage_arguments,
)
storage_staging_file_image_cache = import_string(
storage_staging_file_image_cache = get_storage_subclass(
dotted_path=setting_staging_file_image_cache_storage.value
)(**setting_staging_file_image_cache_storage_arguments.value)

View File

@@ -0,0 +1,10 @@
from __future__ import unicode_literals
class FakeStorageSubclass(object):
"""
Placeholder class to allow serializing the real storage subclass to
support migrations.
"""
def __eq__(self, other):
return True

View File

@@ -5,6 +5,8 @@ import os
import shutil
import tempfile
from django.utils.module_loading import import_string
from .settings import setting_temporary_directory
logger = logging.getLogger(__name__)
@@ -39,6 +41,27 @@ def fs_cleanup(filename, file_descriptor=None, suppress_exceptions=True):
raise
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.storage.classes.FakeStorageSubclass', (), {})
return StorageSubclass
def mkdtemp(*args, **kwargs):
kwargs.update({'dir': setting_temporary_directory.value})
return tempfile.mkdtemp(*args, **kwargs)