diff --git a/mayan/apps/acls/classes.py b/mayan/apps/acls/classes.py index 1cd9ef2d0f..8750160937 100644 --- a/mayan/apps/acls/classes.py +++ b/mayan/apps/acls/classes.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals, absolute_import import logging -from permissions.models import StoredPermission +from django.apps import apps logger = logging.getLogger(__name__) @@ -20,6 +20,10 @@ class ModelPermission(object): @classmethod def get_for_instance(cls, instance): + StoredPermission = apps.get_model( + app_label='permissions', model_name='StoredPermission' + ) + try: permissions = cls._registry[type(instance)] except KeyError: diff --git a/mayan/apps/checkouts/apps.py b/mayan/apps/checkouts/apps.py index 660dce0b1c..8de707d522 100644 --- a/mayan/apps/checkouts/apps.py +++ b/mayan/apps/checkouts/apps.py @@ -4,11 +4,11 @@ from datetime import timedelta from kombu import Exchange, Queue +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission from common import MayanAppConfig, menu_facet, menu_main, menu_sidebar -from documents.models import Document from mayan.celery import app from rest_api.classes import APIEndPoint @@ -35,6 +35,10 @@ class CheckoutsApp(MayanAppConfig): APIEndPoint(app=self, version_string='1') + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + DocumentCheckout = self.get_model('DocumentCheckout') Document.add_to_class( diff --git a/mayan/apps/checkouts/tasks.py b/mayan/apps/checkouts/tasks.py index 5b4327d0e7..9b5ea5d9a8 100644 --- a/mayan/apps/checkouts/tasks.py +++ b/mayan/apps/checkouts/tasks.py @@ -2,17 +2,22 @@ from __future__ import unicode_literals import logging +from django.apps import apps + from lock_manager import Lock, LockError from mayan.celery import app from .literals import CHECKOUT_EXPIRATION_LOCK_EXPIRE -from .models import DocumentCheckout logger = logging.getLogger(__name__) @app.task(ignore_result=True) def task_check_expired_check_outs(): + DocumentCheckout = apps.get_model( + app_label='checkouts', model_name='DocumentCheckout' + ) + logger.debug('executing...') lock_id = 'task_expired_check_outs' try: diff --git a/mayan/apps/common/classes.py b/mayan/apps/common/classes.py index 8aef2dbd7d..d342ab062e 100644 --- a/mayan/apps/common/classes.py +++ b/mayan/apps/common/classes.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from django.apps import apps from django.core.exceptions import PermissionDenied from django.db import models from django.utils.translation import ugettext @@ -125,7 +126,9 @@ class Filter(object): return unicode(self.label) def get_queryset(self, user): - from acls.models import AccessControlList + AccessControlList = apps.get_model( + app_label='acls', model_name='AccessControlList' + ) queryset = self.model.objects.all() for kwargs in self.filter_kwargs: diff --git a/mayan/apps/common/handlers.py b/mayan/apps/common/handlers.py index e992516818..8fffc54769 100644 --- a/mayan/apps/common/handlers.py +++ b/mayan/apps/common/handlers.py @@ -1,12 +1,15 @@ from __future__ import unicode_literals +from django.apps import apps from django.conf import settings from django.utils import timezone, translation -from .models import UserLocaleProfile - def user_locale_profile_session_config(sender, request, user, **kwargs): + UserLocaleProfile = apps.get_model( + app_label='common', model_name='UserLocaleProfile' + ) + user_locale_profile, created = UserLocaleProfile.objects.get_or_create( user=user ) @@ -34,5 +37,9 @@ def user_locale_profile_session_config(sender, request, user, **kwargs): def user_locale_profile_create(sender, instance, created, **kwargs): + UserLocaleProfile = apps.get_model( + app_label='common', model_name='UserLocaleProfile' + ) + if created: UserLocaleProfile.objects.create(user=instance) diff --git a/mayan/apps/common/mixins.py b/mayan/apps/common/mixins.py index 39e90bdcf2..535a81c660 100644 --- a/mayan/apps/common/mixins.py +++ b/mayan/apps/common/mixins.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from django.apps import apps from django.conf import settings from django.contrib import messages from django.core.exceptions import PermissionDenied @@ -7,7 +8,6 @@ from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.utils.translation import ungettext -from acls.models import AccessControlList from permissions import Permission __all__ = ( @@ -85,6 +85,10 @@ class ObjectListPermissionFilterMixin(object): object_permission = None def get_queryset(self): + AccessControlList = apps.get_model( + app_label='acls', model_name='AccessControlList' + ) + queryset = super(ObjectListPermissionFilterMixin, self).get_queryset() if self.object_permission: @@ -113,6 +117,10 @@ class ObjectPermissionCheckMixin(object): return self.get_object() def dispatch(self, request, *args, **kwargs): + AccessControlList = apps.get_model( + app_label='acls', model_name='AccessControlList' + ) + if self.object_permission: try: Permission.check_permissions( diff --git a/mayan/apps/common/tasks.py b/mayan/apps/common/tasks.py index c45b2ddf36..4a0027a36d 100644 --- a/mayan/apps/common/tasks.py +++ b/mayan/apps/common/tasks.py @@ -3,12 +3,12 @@ from __future__ import unicode_literals from datetime import timedelta import logging +from django.apps import apps from django.utils.timezone import now from mayan.celery import app from .literals import UPLOAD_EXPIRATION_INTERVAL -from .models import SharedUploadedFile logger = logging.getLogger(__name__) @@ -17,6 +17,10 @@ logger = logging.getLogger(__name__) def task_delete_stale_uploads(): logger.info('Executing') + SharedUploadedFile = apps.get_model( + app_label='common', model_name='SharedUploadedFile' + ) + for expired_upload in SharedUploadedFile.objects.filter(datetime__lt=now() - timedelta(seconds=UPLOAD_EXPIRATION_INTERVAL)): expired_upload.delete() diff --git a/mayan/apps/document_comments/apps.py b/mayan/apps/document_comments/apps.py index 5b52b73d98..c4d5f3dfd4 100644 --- a/mayan/apps/document_comments/apps.py +++ b/mayan/apps/document_comments/apps.py @@ -1,10 +1,10 @@ from __future__ import unicode_literals +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission from common import MayanAppConfig, menu_facet, menu_object, menu_sidebar -from documents.models import Document from navigation import SourceColumn from .links import ( @@ -25,6 +25,10 @@ class DocumentCommentsApp(MayanAppConfig): def ready(self): super(DocumentCommentsApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + Comment = self.get_model('Comment') ModelPermission.register( diff --git a/mayan/apps/document_indexing/apps.py b/mayan/apps/document_indexing/apps.py index 6dc211800a..aef05f315d 100644 --- a/mayan/apps/document_indexing/apps.py +++ b/mayan/apps/document_indexing/apps.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals from kombu import Exchange, Queue +from django.apps import apps from django.db.models.signals import post_save, post_delete from django.utils.translation import ugettext_lazy as _ @@ -11,10 +12,8 @@ from common import ( ) from common.classes import Package from common.widgets import two_state_template -from documents.models import Document from documents.signals import post_document_created from mayan.celery import app -from metadata.models import DocumentMetadata from navigation import SourceColumn from rest_api.classes import APIEndPoint @@ -43,6 +42,14 @@ class DocumentIndexingApp(MayanAppConfig): def ready(self): super(DocumentIndexingApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + + DocumentMetadata = apps.get_model( + app_label='metadata', model_name='DocumentMetadata' + ) + DocumentIndexInstanceNode = self.get_model('DocumentIndexInstanceNode') Index = self.get_model('Index') IndexInstance = self.get_model('IndexInstance') diff --git a/mayan/apps/document_indexing/tasks.py b/mayan/apps/document_indexing/tasks.py index 007af049e9..507ba9bdd4 100644 --- a/mayan/apps/document_indexing/tasks.py +++ b/mayan/apps/document_indexing/tasks.py @@ -2,20 +2,23 @@ from __future__ import unicode_literals import logging +from django.apps import apps from django.db import OperationalError from mayan.celery import app -from documents.models import Document from lock_manager import Lock, LockError from .literals import RETRY_DELAY -from .models import IndexInstanceNode logger = logging.getLogger(__name__) @app.task(bind=True, default_retry_delay=RETRY_DELAY, max_retries=None, ignore_result=True) def task_delete_empty_index_nodes(self): + IndexInstanceNode = apps.get_model( + app_label='document_indexing', model_name='IndexInstanceNode' + ) + try: rebuild_lock = Lock.acquire_lock( 'document_indexing_task_do_rebuild_all_indexes' @@ -32,6 +35,14 @@ def task_delete_empty_index_nodes(self): @app.task(bind=True, default_retry_delay=RETRY_DELAY, max_retries=None, ignore_result=True) def task_index_document(self, document_id): + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + + IndexInstanceNode = apps.get_model( + app_label='document_indexing', model_name='IndexInstanceNode' + ) + try: rebuild_lock = Lock.acquire_lock( 'document_indexing_task_do_rebuild_all_indexes' @@ -74,6 +85,10 @@ def task_index_document(self, document_id): @app.task(bind=True, default_retry_delay=RETRY_DELAY, ignore_result=True) def task_do_rebuild_all_indexes(self): + IndexInstanceNode = apps.get_model( + app_label='document_indexing', model_name='IndexInstanceNode' + ) + if Lock.check_existing(name__startswith='document_indexing_task_update_index_document'): # A document index update is happening, wait raise self.retry() diff --git a/mayan/apps/document_indexing/widgets.py b/mayan/apps/document_indexing/widgets.py index c207851bae..f7371e92c0 100644 --- a/mayan/apps/document_indexing/widgets.py +++ b/mayan/apps/document_indexing/widgets.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +from django.apps import apps from django.utils.html import mark_safe from django.utils.translation import ugettext -from .models import IndexInstanceNode - def get_instance_link(index_instance_node, text=None, simple=False): """ @@ -64,6 +63,10 @@ def get_breadcrumbs(index_instance_node, simple=False, single_link=False, includ def index_instance_item_link(index_instance_item): + IndexInstanceNode = apps.get_model( + app_label='document_indexing', model_name='IndexInstanceNode' + ) + if isinstance(index_instance_item, IndexInstanceNode): if index_instance_item.index_template_node.link_documents: icon_template = '' diff --git a/mayan/apps/document_signatures/apps.py b/mayan/apps/document_signatures/apps.py index f9e807da6d..dcf953a593 100644 --- a/mayan/apps/document_signatures/apps.py +++ b/mayan/apps/document_signatures/apps.py @@ -2,11 +2,11 @@ from __future__ import unicode_literals import logging +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission from common import MayanAppConfig, menu_facet, menu_sidebar -from documents.models import Document, DocumentVersion from .hooks import document_pre_open_hook, document_version_post_save_hook from .links import ( @@ -31,6 +31,14 @@ class DocumentSignaturesApp(MayanAppConfig): def ready(self): super(DocumentSignaturesApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + + DocumentVersion = apps.get_model( + app_label='documents', model_name='DocumentVersion' + ) + DocumentVersion.register_post_save_hook( 1, document_version_post_save_hook ) diff --git a/mayan/apps/document_signatures/hooks.py b/mayan/apps/document_signatures/hooks.py index 4dcf94dcd7..0065d2c425 100644 --- a/mayan/apps/document_signatures/hooks.py +++ b/mayan/apps/document_signatures/hooks.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import io import logging +from django.apps import apps from django_gpg.exceptions import GPGDecryptionError from django_gpg.runtime import gpg @@ -10,7 +11,11 @@ logger = logging.getLogger(__name__) def document_pre_open_hook(descriptor, instance): - from .models import DocumentVersionSignature + logger.debug('instance: %s', instance) + + DocumentVersionSignature = apps.get_model( + app_label='document_signatures', model_name='DocumentVersionSignature' + ) if DocumentVersionSignature.objects.has_embedded_signature(document_version=instance): # If it has an embedded signature, decrypt @@ -30,7 +35,10 @@ def document_pre_open_hook(descriptor, instance): def document_version_post_save_hook(instance): logger.debug('instance: %s', instance) - from .models import DocumentVersionSignature + + DocumentVersionSignature = apps.get_model( + app_label='document_signatures', model_name='DocumentVersionSignature' + ) try: document_signature = DocumentVersionSignature.objects.get( diff --git a/mayan/apps/document_signatures/links.py b/mayan/apps/document_signatures/links.py index ffd17b870a..3a2436ca1e 100644 --- a/mayan/apps/document_signatures/links.py +++ b/mayan/apps/document_signatures/links.py @@ -1,10 +1,10 @@ from __future__ import unicode_literals +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from navigation import Link -from .models import DocumentVersionSignature from .permissions import ( permission_document_verify, permission_signature_delete, permission_signature_download, permission_signature_upload, @@ -12,6 +12,10 @@ from .permissions import ( def can_upload_detached_signature(context): + DocumentVersionSignature = apps.get_model( + app_label='document_signatures', model_name='DocumentVersionSignature' + ) + return not DocumentVersionSignature.objects.has_detached_signature( context['object'].latest_version ) and not DocumentVersionSignature.objects.has_embedded_signature( @@ -20,6 +24,10 @@ def can_upload_detached_signature(context): def can_delete_detached_signature(context): + DocumentVersionSignature = apps.get_model( + app_label='document_signatures', model_name='DocumentVersionSignature' + ) + return DocumentVersionSignature.objects.has_detached_signature( context['object'].latest_version ) diff --git a/mayan/apps/document_states/apps.py b/mayan/apps/document_states/apps.py index 0af6eb8132..7e71d5b1a2 100644 --- a/mayan/apps/document_states/apps.py +++ b/mayan/apps/document_states/apps.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from django.apps import apps from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy as _ @@ -8,7 +9,6 @@ from common import ( menu_sidebar ) from common.widgets import two_state_template -from documents.models import Document from navigation import SourceColumn from .handlers import launch_workflow @@ -33,6 +33,10 @@ class DocumentStatesApp(MayanAppConfig): def ready(self): super(DocumentStatesApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + Workflow = self.get_model('Workflow') WorkflowInstance = self.get_model('WorkflowInstance') WorkflowInstanceLogEntry = self.get_model('WorkflowInstanceLogEntry') diff --git a/mayan/apps/documents/handlers.py b/mayan/apps/documents/handlers.py index ec185e87d6..bcde760c69 100644 --- a/mayan/apps/documents/handlers.py +++ b/mayan/apps/documents/handlers.py @@ -1,11 +1,13 @@ from __future__ import unicode_literals -from django.db.models import get_model +from django.apps import apps from django.utils.translation import ugettext_lazy as _ def create_default_document_type(sender, **kwargs): - DocumentType = get_model('documents', 'DocumentType') + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) if not DocumentType.objects.count(): DocumentType.objects.create(label=_('Default')) diff --git a/mayan/apps/documents/tasks.py b/mayan/apps/documents/tasks.py index f35c47b023..4427eb3145 100644 --- a/mayan/apps/documents/tasks.py +++ b/mayan/apps/documents/tasks.py @@ -2,34 +2,44 @@ from __future__ import unicode_literals import logging +from django.apps import apps from django.contrib.auth.models import User from django.db import OperationalError from mayan.celery import app -from common.models import SharedUploadedFile - from .literals import ( UPDATE_PAGE_COUNT_RETRY_DELAY, UPLOAD_NEW_VERSION_RETRY_DELAY, NEW_DOCUMENT_RETRY_DELAY ) -from .models import Document, DocumentPage, DocumentType, DocumentVersion logger = logging.getLogger(__name__) @app.task(ignore_result=True) def task_check_delete_periods(): + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + DocumentType.objects.check_delete_periods() @app.task(ignore_result=True) def task_check_trash_periods(): + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + DocumentType.objects.check_trash_periods() @app.task(ignore_result=True) def task_clear_image_cache(): + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + logger.info('Starting document cache invalidation') Document.objects.invalidate_cache() logger.info('Finished document cache invalidation') @@ -37,6 +47,10 @@ def task_clear_image_cache(): @app.task(ignore_result=True) def task_delete_stubs(): + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + logger.info('Executing') Document.objects.delete_stubs() logger.info('Finshed') @@ -44,12 +58,20 @@ def task_delete_stubs(): @app.task(compression='zlib') def task_get_document_page_image(document_page_id, *args, **kwargs): + DocumentPage = apps.get_model( + app_label='documents', model_name='DocumentPage' + ) + document_page = DocumentPage.objects.get(pk=document_page_id) return document_page.get_image(*args, **kwargs) @app.task(bind=True, default_retry_delay=UPDATE_PAGE_COUNT_RETRY_DELAY, ignore_result=True) def task_update_page_count(self, version_id): + DocumentVersion = apps.get_model( + app_label='documents', model_name='DocumentVersion' + ) + document_version = DocumentVersion.objects.get(pk=version_id) try: document_version.update_page_count() @@ -64,6 +86,14 @@ def task_update_page_count(self, version_id): @app.task(bind=True, default_retry_delay=NEW_DOCUMENT_RETRY_DELAY, ignore_result=True) def task_upload_new_document(self, document_type_id, shared_uploaded_file_id, description=None, label=None, language=None, user_id=None): + SharedUploadedFile = apps.get_model( + app_label='common', model_name='SharedUploadedFile' + ) + + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + try: document_type = DocumentType.objects.get(pk=document_type_id) shared_file = SharedUploadedFile.objects.get( @@ -106,6 +136,14 @@ def task_upload_new_document(self, document_type_id, shared_uploaded_file_id, de @app.task(bind=True, default_retry_delay=UPLOAD_NEW_VERSION_RETRY_DELAY, ignore_result=True) def task_upload_new_version(self, document_id, shared_uploaded_file_id, user_id, comment=None): + SharedUploadedFile = apps.get_model( + app_label='common', model_name='SharedUploadedFile' + ) + + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + try: document = Document.objects.get(pk=document_id) shared_file = SharedUploadedFile.objects.get( diff --git a/mayan/apps/folders/apps.py b/mayan/apps/folders/apps.py index 467949f6d5..dc0c51a4ef 100644 --- a/mayan/apps/folders/apps.py +++ b/mayan/apps/folders/apps.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission @@ -9,7 +10,6 @@ from common import ( MayanAppConfig, menu_facet, menu_main, menu_object, menu_secondary, menu_sidebar, menu_multi_item ) -from documents.models import Document from navigation import SourceColumn from rest_api.classes import APIEndPoint @@ -35,6 +35,10 @@ class FoldersApp(MayanAppConfig): def ready(self): super(FoldersApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + DocumentFolder = self.get_model('DocumentFolder') Folder = self.get_model('Folder') diff --git a/mayan/apps/linking/apps.py b/mayan/apps/linking/apps.py index 8a0ac798ff..9931161a9e 100644 --- a/mayan/apps/linking/apps.py +++ b/mayan/apps/linking/apps.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission @@ -10,7 +11,6 @@ from common import ( menu_sidebar ) from common.widgets import two_state_template -from documents.models import Document from navigation import SourceColumn from .links import ( @@ -34,6 +34,10 @@ class LinkingApp(MayanAppConfig): def ready(self): super(LinkingApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + ResolvedSmartLink = self.get_model('ResolvedSmartLink') SmartLink = self.get_model('SmartLink') SmartLinkCondition = self.get_model('SmartLinkCondition') diff --git a/mayan/apps/mailer/apps.py b/mayan/apps/mailer/apps.py index b7eefbb8f7..1313135125 100644 --- a/mayan/apps/mailer/apps.py +++ b/mayan/apps/mailer/apps.py @@ -2,11 +2,11 @@ from __future__ import unicode_literals from kombu import Exchange, Queue +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission from common import MayanAppConfig, menu_object, menu_tools -from documents.models import Document from mayan.celery import app from navigation import SourceColumn @@ -26,6 +26,10 @@ class MailerApp(MayanAppConfig): def ready(self): super(MailerApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + LogEntry = self.get_model('LogEntry') SourceColumn( diff --git a/mayan/apps/metadata/apps.py b/mayan/apps/metadata/apps.py index 79281600c8..8bb0df6364 100644 --- a/mayan/apps/metadata/apps.py +++ b/mayan/apps/metadata/apps.py @@ -4,6 +4,7 @@ import logging from kombu import Exchange, Queue +from django.apps import apps from django.db.models.signals import post_delete, post_save from django.utils.translation import ugettext_lazy as _ @@ -14,7 +15,6 @@ from common import ( ) from common.classes import ModelAttribute, Filter from common.widgets import two_state_template -from documents.models import Document, DocumentType from documents.search import document_search from documents.signals import post_document_type_change from documents.permissions import permission_document_view @@ -54,6 +54,14 @@ class MetadataApp(MayanAppConfig): def ready(self): super(MetadataApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + DocumentMetadata = self.get_model('DocumentMetadata') DocumentTypeMetadataType = self.get_model('DocumentTypeMetadataType') MetadataType = self.get_model('MetadataType') diff --git a/mayan/apps/metadata/handlers.py b/mayan/apps/metadata/handlers.py index d65e7a8c13..da408481e4 100644 --- a/mayan/apps/metadata/handlers.py +++ b/mayan/apps/metadata/handlers.py @@ -1,8 +1,8 @@ from __future__ import unicode_literals -import logging +from django.apps import apps -from django.db.models import get_model +import logging from .tasks import task_add_required_metadata_type, task_remove_metadata_type @@ -38,7 +38,9 @@ def post_post_document_type_change_metadata(sender, instance, **kwargs): for metadata in instance.metadata.all(): metadata.delete(enforce_required=False) - DocumentMetadata = get_model('metadata', 'DocumentMetadata') + DocumentMetadata = apps.get_model( + app_label='metadata', model_name='DocumentMetadata' + ) # Add new document type metadata types to document for document_type_metadata_type in instance.document_type.metadata.filter(required=True): diff --git a/mayan/apps/metadata/tasks.py b/mayan/apps/metadata/tasks.py index be2540cc0f..ebf0f6d596 100644 --- a/mayan/apps/metadata/tasks.py +++ b/mayan/apps/metadata/tasks.py @@ -1,16 +1,20 @@ +from __future__ import unicode_literals + import logging +from django.apps import apps + from mayan.celery import app -from documents.models import DocumentType - -from .models import DocumentMetadata, MetadataType - logger = logging.getLogger(__name__) @app.task(ignore_result=True) def task_remove_metadata_type(document_type_id, metadata_type_id): + DocumentMetadata = apps.get_model( + app_label='metadata', model_name='DocumentMetadata' + ) + DocumentMetadata.objects.filter( document__document_type__id=document_type_id, metadata_type__id=metadata_type_id @@ -19,6 +23,14 @@ def task_remove_metadata_type(document_type_id, metadata_type_id): @app.task(ignore_result=True) def task_add_required_metadata_type(document_type_id, metadata_type_id): + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + + MetadataType = apps.get_model( + app_label='metadata', model_name='MetadataType' + ) + metadata_type = MetadataType.objects.get(pk=metadata_type_id) for document in DocumentType.objects.get(pk=document_type_id).documents.all(): diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py index 0515991962..6a32c07466 100644 --- a/mayan/apps/navigation/classes.py +++ b/mayan/apps/navigation/classes.py @@ -5,6 +5,7 @@ import logging import urllib import urlparse +from django.apps import apps from django.conf import settings from django.core.exceptions import PermissionDenied from django.core.urlresolvers import resolve, reverse @@ -13,7 +14,6 @@ from django.template.defaulttags import URLNode from django.utils.encoding import smart_str, smart_unicode from django.utils.http import urlencode, urlquote -from acls.models import AccessControlList from common.utils import return_attrib from permissions import Permission @@ -218,6 +218,10 @@ class Link(object): self.view = view def resolve(self, context, resolved_object=None): + AccessControlList = apps.get_model( + app_label='acls', model_name='AccessControlList' + ) + request = Variable('request').resolve(context) current_path = request.META['PATH_INFO'] current_view = resolve(current_path).view_name diff --git a/mayan/apps/ocr/apps.py b/mayan/apps/ocr/apps.py index d213396ac2..a25271b601 100644 --- a/mayan/apps/ocr/apps.py +++ b/mayan/apps/ocr/apps.py @@ -5,6 +5,7 @@ import logging from kombu import Exchange, Queue import sh +from django.apps import apps from django.db.models.signals import post_save from django.utils.translation import ugettext_lazy as _ @@ -14,7 +15,6 @@ from common import ( menu_tools ) from common.settings import settings_db_sync_task_delay -from documents.models import Document, DocumentType, DocumentVersion from documents.search import document_search from documents.signals import post_version_upload from documents.widgets import document_link @@ -60,6 +60,18 @@ class OCRApp(MayanAppConfig): def ready(self): super(OCRApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + + DocumentVersion = apps.get_model( + app_label='documents', model_name='DocumentVersion' + ) + DocumentVersionOCRError = self.get_model('DocumentVersionOCRError') APIEndPoint(app=self, version_string='1') diff --git a/mayan/apps/permissions/classes.py b/mayan/apps/permissions/classes.py index e8659a0708..290f9f9a3b 100644 --- a/mayan/apps/permissions/classes.py +++ b/mayan/apps/permissions/classes.py @@ -2,11 +2,11 @@ from __future__ import unicode_literals import logging +from django.apps import apps from django.core.exceptions import PermissionDenied from django.utils.translation import ugettext_lazy as _ from .exceptions import InvalidNamespace -from .models import StoredPermission logger = logging.getLogger(__name__) @@ -64,6 +64,10 @@ class Permission(object): @classmethod def get_for_holder(cls, holder): + StoredPermission = apps.get_model( + app_label='permissions', model_name='StoredPermission' + ) + return StoredPermission.get_for_holder(holder) @classmethod @@ -100,6 +104,10 @@ class Permission(object): @property def stored_permission(self): + StoredPermission = apps.get_model( + app_label='permissions', model_name='StoredPermission' + ) + try: return self.__class__._stored_permissions_cache[self.uuid] except KeyError: diff --git a/mayan/apps/sources/apps.py b/mayan/apps/sources/apps.py index cc4230d710..ed1167f63e 100644 --- a/mayan/apps/sources/apps.py +++ b/mayan/apps/sources/apps.py @@ -1,5 +1,6 @@ from __future__ import absolute_import, unicode_literals +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from kombu import Exchange, Queue @@ -10,7 +11,6 @@ from common import ( ) from common.signals import post_initial_setup, post_upgrade from converter.links import link_transformation_list -from documents.models import Document from documents.signals import post_version_upload from mayan.celery import app from navigation import SourceColumn @@ -41,6 +41,10 @@ class SourcesApp(MayanAppConfig): def ready(self): super(SourcesApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + POP3Email = self.get_model('POP3Email') IMAPEmail = self.get_model('IMAPEmail') Source = self.get_model('Source') diff --git a/mayan/apps/sources/tasks.py b/mayan/apps/sources/tasks.py index 9d6ee5c1e1..3dc60a1242 100644 --- a/mayan/apps/sources/tasks.py +++ b/mayan/apps/sources/tasks.py @@ -1,5 +1,6 @@ import logging +from django.apps import apps from django.contrib.auth.models import User from django.core.files import File from django.db import OperationalError @@ -8,17 +9,18 @@ from django.utils.translation import ugettext_lazy as _ from mayan.celery import app from common.compressed_files import CompressedFile, NotACompressedFile -from common.models import SharedUploadedFile -from documents.models import DocumentType from .literals import DEFAULT_SOURCE_TASK_RETRY_DELAY -from .models import Source logger = logging.getLogger(__name__) @app.task(ignore_result=True) def task_check_interval_source(source_id): + Source = apps.get_model( + app_label='sources', model_name='Source' + ) + source = Source.objects.get_subclass(pk=source_id) if source.enabled: try: @@ -34,6 +36,18 @@ def task_check_interval_source(source_id): @app.task(bind=True, default_retry_delay=DEFAULT_SOURCE_TASK_RETRY_DELAY, ignore_result=True) def task_upload_document(self, source_id, document_type_id, shared_uploaded_file_id, description=None, label=None, language=None, metadata_dict_list=None, user_id=None): + SharedUploadedFile = apps.get_model( + app_label='common', model_name='SharedUploadedFile' + ) + + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + + Source = apps.get_model( + app_label='sources', model_name='Source' + ) + try: document_type = DocumentType.objects.get(pk=document_type_id) source = Source.objects.get_subclass(pk=source_id) @@ -72,6 +86,14 @@ def task_upload_document(self, source_id, document_type_id, shared_uploaded_file @app.task(bind=True, default_retry_delay=DEFAULT_SOURCE_TASK_RETRY_DELAY, ignore_result=True) def task_source_handle_upload(self, document_type_id, shared_uploaded_file_id, source_id, description=None, expand=False, label=None, language=None, metadata_dict_list=None, skip_list=None, user_id=None): + SharedUploadedFile = apps.get_model( + app_label='common', model_name='SharedUploadedFile' + ) + + DocumentType = apps.get_model( + app_label='documents', model_name='DocumentType' + ) + try: document_type = DocumentType.objects.get(pk=document_type_id) shared_upload = SharedUploadedFile.objects.get( diff --git a/mayan/apps/tags/apps.py b/mayan/apps/tags/apps.py index df13311c11..02061d5639 100644 --- a/mayan/apps/tags/apps.py +++ b/mayan/apps/tags/apps.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +from django.apps import apps from django.utils.translation import ugettext_lazy as _ from acls import ModelPermission @@ -9,7 +10,6 @@ from common import ( MayanAppConfig, menu_facet, menu_secondary, menu_object, menu_main, menu_multi_item, menu_sidebar ) -from documents.models import Document from documents.search import document_search from navigation import SourceColumn from rest_api.classes import APIEndPoint @@ -35,6 +35,10 @@ class TagsApp(MayanAppConfig): def ready(self): super(TagsApp, self).ready() + Document = apps.get_model( + app_label='documents', model_name='Document' + ) + DocumentTag = self.get_model('DocumentTag') Tag = self.get_model('Tag')