def get_defined_storage(self): try: return DefinedStorage.get(name=self.defined_storage_name) except KeyError: return DefinedStorage( dotted_path='', label=_('Unknown'), name='unknown' )
def test_setting_documentimagecache_storage_arguments_invalid_value(self): self._set_environment_variable(name='MAYAN_{}'.format( setting_shared_storage_arguments.global_name), value="invalid_value") self.test_case_silenced_logger_new_level = logging.FATAL + 10 self._silence_logger(name='mayan.apps.storage.classes') with self.assertRaises(expected_exception=TypeError) as assertion: importlib.reload(storages) DefinedStorage.get(name=STORAGE_NAME_COMMON_SHARED_UPLOADED_FILE ).get_storage_instance() self.assertTrue('Unable to initialize' in str(assertion.exception)) self.assertTrue('shared uploaded' in str(assertion.exception))
def test_setting_storage_backend_arguments_invalid_value(self): self._set_environment_variable(name='MAYAN_{}'.format( setting_storage_backend_arguments.global_name), value="invalid_value") self.test_case_silenced_logger_new_level = logging.FATAL + 10 self._silence_logger(name='mayan.apps.storage.classes') with self.assertRaises(expected_exception=TypeError) as assertion: importlib.reload(storages) DefinedStorage.get( name=STORAGE_NAME_DOCUMENT_VERSION).get_storage_instance() self.assertTrue('Unable to initialize' in str(assertion.exception)) self.assertTrue('document version' in str(assertion.exception))
def retrieve(self, request, *args, **kwargs): width = request.GET.get('width') height = request.GET.get('height') task = task_generate_staging_file_image.apply_async( kwargs=dict(staging_folder_pk=self.kwargs['staging_folder_pk'], encoded_filename=self.kwargs['encoded_filename'], width=width, height=height)) kwargs = {'timeout': STAGING_FILE_IMAGE_TASK_TIMEOUT} if settings.DEBUG: # In debug more, task are run synchronously, causing this method # to be called inside another task. Disable the check of nested # tasks when using debug mode. kwargs['disable_sync_subtasks'] = False cache_filename = task.get(**kwargs) storage_staging_file_image_cache = DefinedStorage.get( name=STORAGE_NAME_SOURCE_STAGING_FOLDER_FILE).get_storage_instance( ) with storage_staging_file_image_cache.open( name=cache_filename) as file_object: response = HttpResponse(file_object.read(), content_type='image') return response
def purge(self, _user=None): """ Deletes the entire cache. """ try: DefinedStorage.get(name=self.defined_storage_name) except KeyError: """ Unknown or deleted storage. Must not be purged otherwise only the database data will be erased but the actual storage files will remain. """ else: for partition in self.partitions.all(): partition.purge() event_cache_purged.commit(actor=_user, target=self)
def condition_valid_storage(context): try: storage = DefinedStorage.get( name=context['object'].defined_storage_name) except KeyError: return False else: return storage
def setUp(self): super(CacheTestMixin, self).setUp() self.temporary_directory = mkdtemp() DefinedStorage( dotted_path='django.core.files.storage.FileSystemStorage', label='File caching test storage', name=STORAGE_NAME_FILE_CACHING_TEST_STORAGE, kwargs={'location': self.temporary_directory})
def retrieve(self, request, *args, **kwargs): width = request.GET.get('width') height = request.GET.get('height') task = task_generate_staging_file_image.apply_async( kwargs=dict(staging_folder_pk=self.kwargs['staging_folder_pk'], encoded_filename=self.kwargs['encoded_filename'], width=width, height=height)) cache_filename = task.get(timeout=STAGING_FILE_IMAGE_TASK_TIMEOUT) storage_staging_file_image_cache = DefinedStorage.get( name=STORAGE_NAME_SOURCE_STAGING_FOLDER_FILE).get_storage_instance( ) with storage_staging_file_image_cache.open( cache_filename) as file_object: response = HttpResponse(file_object.read(), content_type='image') return response
def storage(self): return DefinedStorage.get(name=STORAGE_NAME_SOURCE_STAGING_FOLDER_FILE ).get_storage_instance()
from django.utils.translation import ugettext_lazy as _ from mayan.apps.storage.classes import DefinedStorage from .literals import STORAGE_NAME_SOURCE_STAGING_FOLDER_FILE from .settings import ( setting_staging_file_image_cache_storage, setting_staging_file_image_cache_storage_arguments, ) storage_staging_folder_files = DefinedStorage( dotted_path=setting_staging_file_image_cache_storage.value, error_message=_( 'Unable to initialize the staging folder file image ' 'storage. Check the settings {} and {} for formatting ' 'errors.'.format( setting_staging_file_image_cache_storage.global_name, setting_staging_file_image_cache_storage_arguments.global_name ) ), label=_('Staging folder files'), name=STORAGE_NAME_SOURCE_STAGING_FOLDER_FILE, kwargs=setting_staging_file_image_cache_storage_arguments.value )
def get_defined_storage(self): return DefinedStorage.get(name=self.defined_storage_name)
from django.utils.translation import ugettext_lazy as _ from mayan.apps.storage.classes import DefinedStorage from .literals import STORAGE_NAME_DOCUMENT_SIGNATURES_DETACHED_SIGNATURE from .settings import (setting_storage_backend, setting_storage_backend_arguments) storage_document_signatures_detached = DefinedStorage( dotted_path=setting_storage_backend.value, error_message=_('Unable to initialize the detached signatures ' 'storage. Check the settings {} and {} for formatting ' 'errors.'.format( setting_storage_backend.global_name, setting_storage_backend_arguments.global_name)), label=_('Detached signatures'), name=STORAGE_NAME_DOCUMENT_SIGNATURES_DETACHED_SIGNATURE, kwargs=setting_storage_backend_arguments.value)
from django.utils.translation import ugettext_lazy as _ from mayan.apps.storage.classes import DefinedStorage from .literals import (STORAGE_NAME_DOCUMENT_IMAGE, STORAGE_NAME_DOCUMENT_VERSION) from .settings import (setting_documentimagecache_storage, setting_documentimagecache_storage_arguments, setting_storage_backend, setting_storage_backend_arguments) storage_document_image_cache = DefinedStorage( dotted_path=setting_documentimagecache_storage.value, error_message=_( 'Unable to initialize the document image storage. Check ' 'the settings {} and {} for formatting errors.'.format( setting_documentimagecache_storage.global_name, setting_documentimagecache_storage_arguments.global_name)), label=_('Document images'), name=STORAGE_NAME_DOCUMENT_IMAGE, kwargs=setting_documentimagecache_storage_arguments.value) storage_document_versions = DefinedStorage( dotted_path=setting_storage_backend.value, error_message=_('Unable to initialize the document version storage. Check ' 'the settings {} and {} for formatting errors.'.format( setting_storage_backend.global_name, setting_storage_backend_arguments.global_name)), label=_('Document version files'), name=STORAGE_NAME_DOCUMENT_VERSION, kwargs=setting_storage_backend_arguments.value)
from django.utils.translation import ugettext_lazy as _ from mayan.apps.storage.classes import DefinedStorage from .literals import STORAGE_NAME_ASSETS from .settings import (setting_storage_backend, setting_storage_backend_arguments) storage_assets = DefinedStorage( dotted_path=setting_storage_backend.value, error_message=_('Unable to initialize the converter asset ' 'storage. Check the settings {} and {} for formatting ' 'errors.'.format( setting_storage_backend.global_name, setting_storage_backend_arguments.global_name)), label=_('Assets'), name=STORAGE_NAME_ASSETS, kwargs=setting_storage_backend_arguments.value)
from django.utils.translation import ugettext_lazy as _ from mayan.apps.storage.classes import DefinedStorage from .literals import STORAGE_NAME_WORKFLOW_CACHE from .settings import ( setting_workflowimagecache_storage, setting_workflowimagecache_storage_arguments, ) storage_workflow_image = DefinedStorage( dotted_path=setting_workflowimagecache_storage.value, error_message=_( 'Unable to initialize the workflow preview ' 'storage. Check the settings {} and {} for formatting ' 'errors.'.format( setting_workflowimagecache_storage.global_name, setting_workflowimagecache_storage_arguments.global_name)), label=_('Workflow preview images'), name=STORAGE_NAME_WORKFLOW_CACHE, kwargs=setting_workflowimagecache_storage_arguments.value)