diff --git a/mayan/apps/documents/settings.py b/mayan/apps/documents/settings.py index 111bdc5d98..a704fd2cc6 100644 --- a/mayan/apps/documents/settings.py +++ b/mayan/apps/documents/settings.py @@ -10,9 +10,19 @@ from smart_settings import Namespace from .literals import ( DEFAULT_DOCUMENTS_CACHE_MAXIMUM_SIZE, DEFAULT_LANGUAGE, DEFAULT_LANGUAGE_CODES ) +from .utils import callback_update_cache_size namespace = Namespace(name='documents', label=_('Documents')) +setting_document_cache_maximum_size = namespace.add_setting( + global_name='DOCUMENTS_CACHE_MAXIMUM_SIZE', + default=DEFAULT_DOCUMENTS_CACHE_MAXIMUM_SIZE, + help_text=_( + 'The threshold at which the DOCUMENT_CACHE_STORAGE_BACKEND will start ' + 'deleting the oldest document image cache files. Specify the size in ' + 'bytes.' + ), post_edit_function=callback_update_cache_size +) setting_documentimagecache_storage = namespace.add_setting( global_name='DOCUMENTS_CACHE_STORAGE_BACKEND', default='django.core.files.storage.FileSystemStorage', help_text=_( @@ -27,15 +37,6 @@ setting_documentimagecache_storage_arguments = namespace.add_setting( 'Arguments to pass to the DOCUMENT_CACHE_STORAGE_BACKEND.' ) ) -setting_document_cache_maximum_size = namespace.add_setting( - global_name='DOCUMENTS_CACHE_MAXIMUM_SIZE', - default=DEFAULT_DOCUMENTS_CACHE_MAXIMUM_SIZE, - help_text=_( - 'The threshold at which the DOCUMENT_CACHE_STORAGE_BACKEND will start ' - 'deleting the oldest document image cache files. Specify the size in ' - 'bytes.' - ) -) setting_disable_base_image_cache = namespace.add_setting( global_name='DOCUMENTS_DISABLE_BASE_IMAGE_CACHE', default=False, help_text=_( diff --git a/mayan/apps/documents/utils.py b/mayan/apps/documents/utils.py index e33b45e9de..16f6e25d7b 100644 --- a/mayan/apps/documents/utils.py +++ b/mayan/apps/documents/utils.py @@ -1,5 +1,16 @@ from __future__ import unicode_literals +from django.apps import apps + +from .literals import DOCUMENT_IMAGES_CACHE_NAME + + +def callback_update_cache_size(setting): + Cache = apps.get_model(app_label='common', model_name='Cache') + cache = Cache.objects.get(name=DOCUMENT_IMAGES_CACHE_NAME) + cache.maximum_size = setting.value + cache.save() + def parse_range(astr): # http://stackoverflow.com/questions/4248399/