Add dependencies and cache handling

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-09-01 15:34:59 -04:00
parent af71ba927f
commit c48fc203e3
6 changed files with 122 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
from __future__ import unicode_literals
from django.apps import apps
from django.db.models.signals import post_save
from django.db.models.signals import post_migrate, post_save
from django.utils.translation import ugettext_lazy as _
from mayan.apps.acls.classes import ModelPermission
@@ -20,7 +20,11 @@ from mayan.apps.events.links import (
from mayan.apps.navigation.classes import SourceColumn
from .control_codes import *
from .handlers import handler_process_document_version
from .dependencies import * # NOQA
from .handlers import (
handler_create_control_sheet_codes_image_cache,
handler_process_document_version
)
from .methods import method_document_submit, method_document_version_submit
@@ -55,6 +59,10 @@ class ControlCodesApp(MayanAppConfig):
value=method_document_version_submit
)
post_migrate.connect(
dispatch_uid='control_codes_handler_create_control_sheet_codes_image_cache',
receiver=handler_create_control_sheet_codes_image_cache,
)
post_version_upload.connect(
dispatch_uid='control_codes_handler_process_document_version',
receiver=handler_process_document_version, sender=DocumentVersion

View File

@@ -0,0 +1,92 @@
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _
from mayan.apps.dependencies.classes import BinaryDependency, PythonDependency
PythonDependency(
copyright_text='''
Copyright (c) 2014, Polyconseil
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
''', help_text=_(
'Read one-dimensional barcodes and QR codes from Python 2 and 3.'
), module=__name__, name='pyzbar', version_string='==0.1.8')
PythonDependency(
copyright_text='''
Copyright (c) 2011, Lincoln Loop
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the package name nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
Original text and license from the pyqrnative package where this was forked
from (http://code.google.com/p/pyqrnative):
#Ported from the Javascript library by Sam Curren
#
#QRCode for Javascript
#http://d-project.googlecode.com/svn/trunk/misc/qrcode/js/qrcode.js
#
#Copyright (c) 2009 Kazuhiko Arase
#
#URL: http://www.d-project.com/
#
#Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license.php
#
# The word "QR Code" is registered trademark of
# DENSO WAVE INCORPORATED
# http://www.denso-wave.com/qrcode/faqpatent-e.html
''', help_text=_('Python QR Code image generator.'), module=__name__,
name='qrcode', version_string='==6.1'
)

View File

@@ -1,21 +1,25 @@
from __future__ import unicode_literals
from django.apps import apps
from django.utils.translation import ugettext_lazy as _
#from .settings import setting_auto_process
from .literals import (
CONTROL_SHEET_CODE_IMAGE_CACHE_NAME,
CONTROL_SHEET_CODE_IMAGE_CACHE_STORAGE_INSTANCE_PATH
)
from .settings import setting_control_sheet_code_image_cache_maximum_size
def handler_initialize_new_document_type_settings(sender, instance, **kwargs):
DocumentTypeSettings = apps.get_model(
app_label='file_metadata', model_name='DocumentTypeSettings'
def handler_create_control_sheet_codes_image_cache(sender, **kwargs):
Cache = apps.get_model(app_label='file_caching', model_name='Cache')
Cache.objects.update_or_create(
defaults={
'label': _('Control sheet codes'),
'storage_instance_path': CONTROL_SHEET_CODE_IMAGE_CACHE_STORAGE_INSTANCE_PATH,
'maximum_size': setting_control_sheet_code_image_cache_maximum_size.value,
}, name=CONTROL_SHEET_CODE_IMAGE_CACHE_NAME,
)
if kwargs['created']:
DocumentTypeSettings.objects.create(
auto_process=setting_auto_process.value, document_type=instance
)
def handler_process_document_version(sender, instance, **kwargs):
#if instance.document.document_type.control_codes_settings.auto_process:
instance.submit_for_control_codes_processing()

View File

@@ -4,7 +4,7 @@ CONTROL_CODE_MAGIC_NUMBER = 'MCTRL'
CONTROL_CODE_SEPARATOR = ':'
CONTROL_CODE_VERSION = '1'
CONTROL_SHEET_CODE_IMAGE_CACHE_NAME = 'workflow_images'
CONTROL_SHEET_CODE_IMAGE_CACHE_NAME = 'control_sheet_codes'
CONTROL_SHEET_CODE_IMAGE_CACHE_STORAGE_INSTANCE_PATH = 'mayan.apps.control_codes.storages.storage_controlsheetcodeimagecache'
CONTROL_SHEET_CODE_IMAGE_TASK_TIMEOUT = 60

View File

@@ -28,7 +28,7 @@ settings_control_sheet_code_image_cache_time = namespace.add_setting(
'code images. The default of 31559626 seconds corresponde to 1 year.'
)
)
setting_control_sheet_code_image_cache_storage = namespace.add_setting(
setting_control_sheet_code_image_cache_storage_dotted_path = namespace.add_setting(
global_name='CONTROL_SHEETS_CODE_IMAGE_CACHE_STORAGE_BACKEND',
default='django.core.files.storage.FileSystemStorage', help_text=_(
'Path to the Storage subclass to use when storing the cached '

View File

@@ -3,10 +3,10 @@ from __future__ import unicode_literals
from mayan.apps.storage.utils import get_storage_subclass
from .settings import (
setting_control_sheet_code_image_cache_storage,
setting_control_sheet_code_image_storage_arguments
setting_control_sheet_code_image_cache_storage_dotted_path,
setting_control_sheet_code_image_cache_storage_arguments
)
storage_controlsheetcodeimagecache = get_storage_subclass(
dotted_path=setting_control_sheet_code_image_cache_storage.value
)(**setting_control_sheet_code_image_storage_arguments.value)
dotted_path=setting_control_sheet_code_image_cache_storage_dotted_path.value
)(**setting_control_sheet_code_image_cache_storage_arguments.value)