Move signal handlers into their own app module
This commit is contained in:
@@ -89,6 +89,7 @@ Bugs fixed or issues closed
|
||||
* `issue #67 <https://github.com/mayan-edms/mayan-edms/issues/67>`_ Python 3 compatibility: Update models __unicode__ methdo to __str__ methods (using Django's six library)
|
||||
* `issue #121 <https://github.com/mayan-edms/mayan-edms/issues/121>`_ Twitter Bootstrap theme for Mayan EDMS
|
||||
* `issue #155 <https://github.com/mayan-edms/mayan-edms/issues/155>`_ Header does not fit list on documents/list on small screens (laptop)
|
||||
* `issue #182 <https://github.com/mayan-edms/mayan-edms/issues/182>`_ Reorganize signal processors
|
||||
|
||||
|
||||
.. _PyPI: https://pypi.python.org/pypi/mayan-edms/
|
||||
|
||||
@@ -13,6 +13,10 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common import settings as common_settings
|
||||
|
||||
from .handlers import (
|
||||
auto_admin_account_passwd_change, user_locale_profile_session_config,
|
||||
user_locale_profile_create
|
||||
)
|
||||
from .links import (
|
||||
link_about, link_admin_site, link_current_user_details,
|
||||
link_current_user_edit, link_current_user_locale_profile_details,
|
||||
@@ -66,30 +70,6 @@ def create_superuser_and_anonymous_user(sender, **kwargs):
|
||||
logger.info('Super admin user already exists. -- login: %s', AUTO_ADMIN_USERNAME)
|
||||
|
||||
|
||||
def auto_admin_account_passwd_change(sender, instance, **kwargs):
|
||||
auto_admin_properties = AutoAdminSingleton.objects.get()
|
||||
if instance == auto_admin_properties.account and instance.password != auto_admin_properties.password_hash:
|
||||
# Only delete the auto admin properties when the password has been changed
|
||||
auto_admin_properties.account = None
|
||||
auto_admin_properties.password = None
|
||||
auto_admin_properties.password_hash = None
|
||||
auto_admin_properties.save()
|
||||
|
||||
|
||||
def user_locale_profile_session_config(sender, request, user, **kwargs):
|
||||
if hasattr(request, 'session'):
|
||||
user_locale_profile, created = UserLocaleProfile.objects.get_or_create(user=user)
|
||||
request.session['django_language'] = user_locale_profile.language
|
||||
request.session['django_timezone'] = user_locale_profile.timezone
|
||||
else:
|
||||
request.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_locale_profile.language)
|
||||
|
||||
|
||||
def user_locale_profile_create(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
UserLocaleProfile.objects.create(user=instance)
|
||||
|
||||
|
||||
class CommonApp(apps.AppConfig):
|
||||
name = 'common'
|
||||
verbose_name = _('Common')
|
||||
|
||||
31
mayan/apps/common/handlers.py
Normal file
31
mayan/apps/common/handlers.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from .models import (
|
||||
AnonymousUserSingleton, AutoAdminSingleton, UserLocaleProfile
|
||||
)
|
||||
|
||||
|
||||
def auto_admin_account_passwd_change(sender, instance, **kwargs):
|
||||
auto_admin_properties = AutoAdminSingleton.objects.get()
|
||||
if instance == auto_admin_properties.account and instance.password != auto_admin_properties.password_hash:
|
||||
# Only delete the auto admin properties when the password has been changed
|
||||
auto_admin_properties.account = None
|
||||
auto_admin_properties.password = None
|
||||
auto_admin_properties.password_hash = None
|
||||
auto_admin_properties.save()
|
||||
|
||||
|
||||
def user_locale_profile_session_config(sender, request, user, **kwargs):
|
||||
if hasattr(request, 'session'):
|
||||
user_locale_profile, created = UserLocaleProfile.objects.get_or_create(user=user)
|
||||
request.session['django_language'] = user_locale_profile.language
|
||||
request.session['django_timezone'] = user_locale_profile.timezone
|
||||
else:
|
||||
request.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_locale_profile.language)
|
||||
|
||||
|
||||
def user_locale_profile_create(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
UserLocaleProfile.objects.create(user=instance)
|
||||
@@ -12,6 +12,10 @@ from documents.models import Document
|
||||
from metadata.models import DocumentMetadata
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .handlers import (
|
||||
document_index_delete, document_metadata_index_update,
|
||||
document_metadata_index_post_delete
|
||||
)
|
||||
from .links import (
|
||||
link_document_index_list, link_index_main_menu, link_index_parent,
|
||||
link_index_setup, link_index_setup_create, link_index_setup_document_types,
|
||||
@@ -21,19 +25,6 @@ from .links import (
|
||||
link_template_node_edit
|
||||
)
|
||||
from .models import Index, IndexTemplateNode, IndexInstanceNode
|
||||
from .tasks import task_delete_empty_index_nodes, task_index_document
|
||||
|
||||
|
||||
def document_index_delete(sender, **kwargs):
|
||||
task_delete_empty_index_nodes.apply_async(queue='indexing')
|
||||
|
||||
|
||||
def document_metadata_index_update(sender, **kwargs):
|
||||
task_index_document.apply_async(kwargs=dict(document_id=kwargs['instance'].document.pk), queue='indexing')
|
||||
|
||||
|
||||
def document_metadata_index_post_delete(sender, **kwargs):
|
||||
task_index_document.apply_async(kwargs=dict(document_id=kwargs['instance'].document.pk), queue='indexing')
|
||||
|
||||
|
||||
class DocumentIndexingApp(apps.AppConfig):
|
||||
|
||||
15
mayan/apps/document_indexing/handlers.py
Normal file
15
mayan/apps/document_indexing/handlers.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .tasks import task_delete_empty_index_nodes, task_index_document
|
||||
|
||||
|
||||
def document_index_delete(sender, **kwargs):
|
||||
task_delete_empty_index_nodes.apply_async(queue='indexing')
|
||||
|
||||
|
||||
def document_metadata_index_update(sender, **kwargs):
|
||||
task_index_document.apply_async(kwargs=dict(document_id=kwargs['instance'].document.pk), queue='indexing')
|
||||
|
||||
|
||||
def document_metadata_index_post_delete(sender, **kwargs):
|
||||
task_index_document.apply_async(kwargs=dict(document_id=kwargs['instance'].document.pk), queue='indexing')
|
||||
@@ -11,6 +11,7 @@ from common.utils import encapsulate
|
||||
from documents.models import Document
|
||||
from navigation.api import register_model_list_columns
|
||||
|
||||
from .handlers import launch_workflow
|
||||
from .models import (
|
||||
Workflow, WorkflowInstance, WorkflowInstanceLogEntry, WorkflowState,
|
||||
WorkflowTransition
|
||||
@@ -27,11 +28,6 @@ from .links import (
|
||||
)
|
||||
|
||||
|
||||
def launch_workflow(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
Workflow.objects.launch_for(instance)
|
||||
|
||||
|
||||
class DocumentStatesApp(apps.AppConfig):
|
||||
name = 'document_states'
|
||||
verbose_name = _('Document states')
|
||||
|
||||
8
mayan/apps/document_states/handlers.py
Normal file
8
mayan/apps/document_states/handlers.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .models import Workflow
|
||||
|
||||
|
||||
def launch_workflow(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
Workflow.objects.launch_for(instance)
|
||||
@@ -20,6 +20,11 @@ from rest_api.classes import APIEndPoint
|
||||
|
||||
from .api import get_metadata_string
|
||||
from .classes import DocumentMetadataHelper
|
||||
from .handlers import (
|
||||
post_document_type_metadata_type_add,
|
||||
post_document_type_metadata_type_delete,
|
||||
post_post_document_type_change_metadata
|
||||
)
|
||||
from .links import (
|
||||
link_metadata_add, link_metadata_edit, link_metadata_multiple_add,
|
||||
link_metadata_multiple_edit, link_metadata_multiple_remove,
|
||||
@@ -33,35 +38,10 @@ from .permissions import (
|
||||
PERMISSION_METADATA_DOCUMENT_ADD, PERMISSION_METADATA_DOCUMENT_EDIT,
|
||||
PERMISSION_METADATA_DOCUMENT_REMOVE, PERMISSION_METADATA_DOCUMENT_VIEW
|
||||
)
|
||||
from .tasks import task_add_required_metadata_type, task_remove_metadata_type
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_document_type_metadata_type_add(sender, instance, created, **kwargs):
|
||||
logger.debug('instance: %s', instance)
|
||||
|
||||
if created and instance.required:
|
||||
task_add_required_metadata_type.apply_async(kwargs={'document_type_id': instance.document_type.pk, 'metadata_type_id': instance.metadata_type.pk}, queue='metadata')
|
||||
|
||||
|
||||
def post_document_type_metadata_type_delete(sender, instance, **kwargs):
|
||||
logger.debug('instance: %s', instance)
|
||||
task_remove_metadata_type.apply_async(kwargs={'document_type_id': instance.document_type.pk, 'metadata_type_id': instance.metadata_type.pk}, queue='metadata')
|
||||
|
||||
|
||||
def post_post_document_type_change_metadata(sender, instance, **kwargs):
|
||||
logger.debug('received post_document_type_change')
|
||||
logger.debug('instance: %s', instance)
|
||||
# Delete existing document metadata
|
||||
for metadata in instance.metadata.all():
|
||||
metadata.delete(enforce_required=False)
|
||||
|
||||
# Add new document type metadata types to document
|
||||
for document_type_metadata_type in instance.document_type.metadata.filter(required=True):
|
||||
DocumentMetadata.objects.create(document=instance, metadata_type=document_type_metadata_type.metadata_type, value=None)
|
||||
|
||||
|
||||
class MetadataApp(apps.AppConfig):
|
||||
name = 'metadata'
|
||||
verbose_name = _('Metadata')
|
||||
|
||||
32
mayan/apps/metadata/handlers.py
Normal file
32
mayan/apps/metadata/handlers.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from .models import DocumentMetadata
|
||||
from .tasks import task_add_required_metadata_type, task_remove_metadata_type
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_document_type_metadata_type_add(sender, instance, created, **kwargs):
|
||||
logger.debug('instance: %s', instance)
|
||||
|
||||
if created and instance.required:
|
||||
task_add_required_metadata_type.apply_async(kwargs={'document_type_id': instance.document_type.pk, 'metadata_type_id': instance.metadata_type.pk}, queue='metadata')
|
||||
|
||||
|
||||
def post_document_type_metadata_type_delete(sender, instance, **kwargs):
|
||||
logger.debug('instance: %s', instance)
|
||||
task_remove_metadata_type.apply_async(kwargs={'document_type_id': instance.document_type.pk, 'metadata_type_id': instance.metadata_type.pk}, queue='metadata')
|
||||
|
||||
|
||||
def post_post_document_type_change_metadata(sender, instance, **kwargs):
|
||||
logger.debug('received post_document_type_change')
|
||||
logger.debug('instance: %s', instance)
|
||||
# Delete existing document metadata
|
||||
for metadata in instance.metadata.all():
|
||||
metadata.delete(enforce_required=False)
|
||||
|
||||
# Add new document type metadata types to document
|
||||
for document_type_metadata_type in instance.document_type.metadata.filter(required=True):
|
||||
DocumentMetadata.objects.create(document=instance, metadata_type=document_type_metadata_type.metadata_type, value=None)
|
||||
@@ -18,6 +18,7 @@ from installation import PropertyNamespace
|
||||
from navigation.api import register_model_list_columns
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .handlers import post_version_upload_ocr
|
||||
from .links import (
|
||||
link_document_all_ocr_cleanup, link_document_submit,
|
||||
link_document_submit_multiple, link_entry_delete,
|
||||
@@ -40,13 +41,6 @@ def document_version_ocr_submit(self):
|
||||
task_do_ocr.apply_async(args=[self.pk], queue='ocr')
|
||||
|
||||
|
||||
def post_version_upload_ocr(sender, instance, **kwargs):
|
||||
logger.debug('received post_version_upload')
|
||||
logger.debug('instance pk: %s', instance.pk)
|
||||
if instance.document.document_type.ocr:
|
||||
instance.submit_for_ocr()
|
||||
|
||||
|
||||
class OCRApp(apps.AppConfig):
|
||||
name = 'ocr'
|
||||
verbose_name = _('OCR')
|
||||
|
||||
12
mayan/apps/ocr/handlers.py
Normal file
12
mayan/apps/ocr/handlers.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def post_version_upload_ocr(sender, instance, **kwargs):
|
||||
logger.debug('received post_version_upload')
|
||||
logger.debug('instance pk: %s', instance.pk)
|
||||
if instance.document.document_type.ocr:
|
||||
instance.submit_for_ocr()
|
||||
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
|
||||
|
||||
from django import apps
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.db.models.signals import post_save
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@@ -11,28 +10,13 @@ from common.menus import (
|
||||
)
|
||||
from rest_api.classes import APIEndPoint
|
||||
|
||||
from .handlers import apply_default_roles
|
||||
from .models import Role
|
||||
from .links import (
|
||||
link_permission_grant, link_permission_revoke, link_role_create,
|
||||
link_role_delete, link_role_edit, link_role_list, link_role_members,
|
||||
link_role_permissions
|
||||
)
|
||||
from .settings import DEFAULT_ROLES
|
||||
|
||||
|
||||
def user_post_save(sender, instance, **kwargs):
|
||||
if kwargs.get('created', False):
|
||||
for default_role in DEFAULT_ROLES:
|
||||
if isinstance(default_role, Role):
|
||||
# If a model is passed, execute method
|
||||
default_role.add_member(instance)
|
||||
else:
|
||||
# If a role name is passed, lookup the corresponding model
|
||||
try:
|
||||
role = Role.objects.get(name=default_role)
|
||||
role.add_member(instance)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
|
||||
|
||||
class PermissionsApp(apps.AppConfig):
|
||||
@@ -47,4 +31,4 @@ class PermissionsApp(apps.AppConfig):
|
||||
menu_secondary.bind_links(links=[link_role_list, link_role_create], sources=[Role, 'permissions:role_create', 'permissions:role_list'])
|
||||
menu_setup.bind_links(links=[link_role_list])
|
||||
|
||||
post_save.connect(user_post_save, sender=User)
|
||||
post_save.connect(apply_default_roles, dispatch_uid='apply_default_roles', sender=User)
|
||||
|
||||
22
mayan/apps/permissions/handlers.py
Normal file
22
mayan/apps/permissions/handlers.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from .models import Role
|
||||
|
||||
from .settings import DEFAULT_ROLES
|
||||
|
||||
|
||||
def apply_default_roles(sender, instance, **kwargs):
|
||||
if kwargs.get('created', False):
|
||||
for default_role in DEFAULT_ROLES:
|
||||
if isinstance(default_role, Role):
|
||||
# If a model is passed, execute method
|
||||
default_role.add_member(instance)
|
||||
else:
|
||||
# If a role name is passed, lookup the corresponding model
|
||||
try:
|
||||
role = Role.objects.get(name=default_role)
|
||||
role.add_member(instance)
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
Reference in New Issue
Block a user