Fix futher Django Warnings.
This commit is contained in:
@@ -4,7 +4,6 @@ from django.core.exceptions import PermissionDenied
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
|
|
||||||
from acls.models import AccessControlList
|
|
||||||
from permissions import Permission
|
from permissions import Permission
|
||||||
|
|
||||||
|
|
||||||
@@ -126,6 +125,8 @@ class Filter(object):
|
|||||||
return unicode(self.label)
|
return unicode(self.label)
|
||||||
|
|
||||||
def get_queryset(self, user):
|
def get_queryset(self, user):
|
||||||
|
from acls.models import AccessControlList
|
||||||
|
|
||||||
queryset = self.model.objects.all()
|
queryset = self.model.objects.all()
|
||||||
for kwargs in self.filter_kwargs:
|
for kwargs in self.filter_kwargs:
|
||||||
queryset = queryset.filter(**kwargs)
|
queryset = queryset.filter(**kwargs)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms.util import flatatt
|
from django.forms.utils import flatatt
|
||||||
from django.utils.encoding import force_unicode, force_text
|
from django.utils.encoding import force_unicode, force_text
|
||||||
from django.utils.html import conditional_escape, format_html
|
from django.utils.html import conditional_escape, format_html
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import io
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from acls import ModelPermission
|
from acls import ModelPermission
|
||||||
from common import MayanAppConfig, menu_facet, menu_sidebar
|
from common import MayanAppConfig, menu_facet, menu_sidebar
|
||||||
from django_gpg.exceptions import GPGDecryptionError
|
|
||||||
from django_gpg.runtime import gpg
|
|
||||||
from documents.models import Document, DocumentVersion
|
from documents.models import Document, DocumentVersion
|
||||||
|
|
||||||
from .hooks import document_pre_open_hook, document_version_post_save_hook
|
from .hooks import document_pre_open_hook, document_version_post_save_hook
|
||||||
@@ -34,8 +31,6 @@ class DocumentSignaturesApp(MayanAppConfig):
|
|||||||
def ready(self):
|
def ready(self):
|
||||||
super(DocumentSignaturesApp, self).ready()
|
super(DocumentSignaturesApp, self).ready()
|
||||||
|
|
||||||
DocumentVersionSignature = self.get_model('DocumentVersionSignature')
|
|
||||||
|
|
||||||
DocumentVersion.register_post_save_hook(
|
DocumentVersion.register_post_save_hook(
|
||||||
1, document_version_post_save_hook
|
1, document_version_post_save_hook
|
||||||
)
|
)
|
||||||
|
|||||||
43
mayan/apps/document_signatures/hooks.py
Normal file
43
mayan/apps/document_signatures/hooks.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import io
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from django_gpg.exceptions import GPGDecryptionError
|
||||||
|
from django_gpg.runtime import gpg
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def document_pre_open_hook(descriptor, instance):
|
||||||
|
from .models import DocumentVersionSignature
|
||||||
|
|
||||||
|
if DocumentVersionSignature.objects.has_embedded_signature(document_version=instance):
|
||||||
|
# If it has an embedded signature, decrypt
|
||||||
|
try:
|
||||||
|
result = gpg.decrypt_file(descriptor, close_descriptor=False)
|
||||||
|
# gpg return a string, turn it into a file like object
|
||||||
|
except GPGDecryptionError:
|
||||||
|
# At least return the original raw content
|
||||||
|
descriptor.seek(0)
|
||||||
|
return descriptor
|
||||||
|
else:
|
||||||
|
descriptor.close()
|
||||||
|
return io.BytesIO(result.data)
|
||||||
|
else:
|
||||||
|
return descriptor
|
||||||
|
|
||||||
|
|
||||||
|
def document_version_post_save_hook(instance):
|
||||||
|
logger.debug('instance: %s', instance)
|
||||||
|
from .models import DocumentVersionSignature
|
||||||
|
|
||||||
|
try:
|
||||||
|
document_signature = DocumentVersionSignature.objects.get(
|
||||||
|
document_version=instance
|
||||||
|
)
|
||||||
|
except DocumentVersionSignature.DoesNotExist:
|
||||||
|
document_signature = DocumentVersionSignature.objects.create(
|
||||||
|
document_version=instance
|
||||||
|
)
|
||||||
|
document_signature.check_for_embedded_signature()
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .models import Workflow
|
|
||||||
|
|
||||||
|
|
||||||
def launch_workflow(sender, instance, created, **kwargs):
|
def launch_workflow(sender, instance, created, **kwargs):
|
||||||
|
Workflow = sender.get_model('Workflow')
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
Workflow.objects.launch_for(instance)
|
Workflow.objects.launch_for(instance)
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from .models import DocumentType
|
|
||||||
|
|
||||||
|
|
||||||
def create_default_document_type(sender, **kwargs):
|
def create_default_document_type(sender, **kwargs):
|
||||||
if not DocumentType.objects.count():
|
DocumentType = sender.get_model('DocumentType')
|
||||||
|
|
||||||
|
if not DocumentType.objects.count():
|
||||||
DocumentType.objects.create(label=_('Default'))
|
DocumentType.objects.create(label=_('Default'))
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import datetime
|
|||||||
|
|
||||||
import qsstats
|
import qsstats
|
||||||
|
|
||||||
from .models import Document, DocumentPage, DocumentVersion
|
|
||||||
|
|
||||||
|
|
||||||
def new_documents_per_month():
|
def new_documents_per_month():
|
||||||
|
from .models import Document
|
||||||
|
|
||||||
qss = qsstats.QuerySetStats(Document.passthrough.all(), 'date_added')
|
qss = qsstats.QuerySetStats(Document.passthrough.all(), 'date_added')
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@@ -21,6 +21,8 @@ def new_documents_per_month():
|
|||||||
|
|
||||||
|
|
||||||
def new_document_versions_per_month():
|
def new_document_versions_per_month():
|
||||||
|
from .models import DocumentVersion
|
||||||
|
|
||||||
qss = qsstats.QuerySetStats(DocumentVersion.objects.all(), 'document__date_added')
|
qss = qsstats.QuerySetStats(DocumentVersion.objects.all(), 'document__date_added')
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@@ -34,6 +36,8 @@ def new_document_versions_per_month():
|
|||||||
|
|
||||||
|
|
||||||
def new_document_pages_per_month():
|
def new_document_pages_per_month():
|
||||||
|
from .models import DocumentPage
|
||||||
|
|
||||||
qss = qsstats.QuerySetStats(DocumentPage.objects.all(), 'document_version__document__date_added')
|
qss = qsstats.QuerySetStats(DocumentPage.objects.all(), 'document_version__document__date_added')
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@@ -47,6 +51,8 @@ def new_document_pages_per_month():
|
|||||||
|
|
||||||
|
|
||||||
def total_document_per_month():
|
def total_document_per_month():
|
||||||
|
from .models import Document
|
||||||
|
|
||||||
qss = qsstats.QuerySetStats(Document.objects.all(), 'date_added')
|
qss = qsstats.QuerySetStats(Document.objects.all(), 'date_added')
|
||||||
this_year = datetime.date.today().year
|
this_year = datetime.date.today().year
|
||||||
|
|
||||||
@@ -72,6 +78,8 @@ def total_document_per_month():
|
|||||||
|
|
||||||
|
|
||||||
def total_document_version_per_month():
|
def total_document_version_per_month():
|
||||||
|
from .models import DocumentVersion
|
||||||
|
|
||||||
qss = qsstats.QuerySetStats(DocumentVersion.objects.all(), 'document__date_added')
|
qss = qsstats.QuerySetStats(DocumentVersion.objects.all(), 'document__date_added')
|
||||||
this_year = datetime.date.today().year
|
this_year = datetime.date.today().year
|
||||||
|
|
||||||
@@ -97,6 +105,8 @@ def total_document_version_per_month():
|
|||||||
|
|
||||||
|
|
||||||
def total_document_page_per_month():
|
def total_document_page_per_month():
|
||||||
|
from .models import DocumentPage
|
||||||
|
|
||||||
qss = qsstats.QuerySetStats(DocumentPage.objects.all(), 'document_version__document__date_added')
|
qss = qsstats.QuerySetStats(DocumentPage.objects.all(), 'document_version__document__date_added')
|
||||||
this_year = datetime.date.today().year
|
this_year = datetime.date.today().year
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from .models import DocumentMetadata
|
|
||||||
from .tasks import task_add_required_metadata_type, task_remove_metadata_type
|
from .tasks import task_add_required_metadata_type, task_remove_metadata_type
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -37,6 +36,8 @@ def post_post_document_type_change_metadata(sender, instance, **kwargs):
|
|||||||
for metadata in instance.metadata.all():
|
for metadata in instance.metadata.all():
|
||||||
metadata.delete(enforce_required=False)
|
metadata.delete(enforce_required=False)
|
||||||
|
|
||||||
|
DocumentMetadata = sender.get_model('DocumentMetadata')
|
||||||
|
|
||||||
# Add new document type metadata types to document
|
# Add new document type metadata types to document
|
||||||
for document_type_metadata_type in instance.document_type.metadata.filter(required=True):
|
for document_type_metadata_type in instance.document_type.metadata.filter(required=True):
|
||||||
DocumentMetadata.objects.create(
|
DocumentMetadata.objects.create(
|
||||||
|
|||||||
@@ -33,16 +33,19 @@ from .permissions import permission_ocr_document, permission_ocr_content_view
|
|||||||
from .settings import (
|
from .settings import (
|
||||||
setting_pdftotext_path, setting_tesseract_path
|
setting_pdftotext_path, setting_tesseract_path
|
||||||
)
|
)
|
||||||
from .tasks import task_do_ocr
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def document_ocr_submit(self):
|
def document_ocr_submit(self):
|
||||||
|
from .tasks import task_do_ocr
|
||||||
|
|
||||||
task_do_ocr.apply_async(args=(self.latest_version.pk,))
|
task_do_ocr.apply_async(args=(self.latest_version.pk,))
|
||||||
|
|
||||||
|
|
||||||
def document_version_ocr_submit(self):
|
def document_version_ocr_submit(self):
|
||||||
|
from .tasks import task_do_ocr
|
||||||
|
|
||||||
task_do_ocr.apply_async(
|
task_do_ocr.apply_async(
|
||||||
kwargs={'document_version_pk': self.pk},
|
kwargs={'document_version_pk': self.pk},
|
||||||
countdown=settings_db_sync_task_delay.value
|
countdown=settings_db_sync_task_delay.value
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import logging
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
from .models import DocumentTypeSettings
|
|
||||||
from .settings import setting_auto_ocr
|
from .settings import setting_auto_ocr
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +15,8 @@ def post_version_upload_ocr(sender, instance, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def initialize_new_ocr_settings(sender, instance, **kwargs):
|
def initialize_new_ocr_settings(sender, instance, **kwargs):
|
||||||
|
DocumentTypeSettings = sender.get_model('DocumentTypeSettings')
|
||||||
|
|
||||||
if kwargs['created']:
|
if kwargs['created']:
|
||||||
DocumentTypeSettings.objects.create(
|
DocumentTypeSettings.objects.create(
|
||||||
document_type=instance, auto_ocr=setting_auto_ocr.value
|
document_type=instance, auto_ocr=setting_auto_ocr.value
|
||||||
|
|||||||
@@ -5,10 +5,11 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from converter.models import Transformation
|
from converter.models import Transformation
|
||||||
|
|
||||||
from .literals import SOURCE_UNCOMPRESS_CHOICE_ASK
|
from .literals import SOURCE_UNCOMPRESS_CHOICE_ASK
|
||||||
from .models import POP3Email, IMAPEmail, WatchFolderSource, WebFormSource
|
|
||||||
|
|
||||||
|
|
||||||
def create_default_document_source(sender, **kwargs):
|
def create_default_document_source(sender, **kwargs):
|
||||||
|
WebFormSource = sender.get_model('WebFormSource')
|
||||||
|
|
||||||
if not WebFormSource.objects.count():
|
if not WebFormSource.objects.count():
|
||||||
WebFormSource.objects.create(
|
WebFormSource.objects.create(
|
||||||
label=_('Default'), uncompress=SOURCE_UNCOMPRESS_CHOICE_ASK
|
label=_('Default'), uncompress=SOURCE_UNCOMPRESS_CHOICE_ASK
|
||||||
@@ -16,6 +17,8 @@ def create_default_document_source(sender, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
def copy_transformations_to_version(sender, **kwargs):
|
def copy_transformations_to_version(sender, **kwargs):
|
||||||
|
Transformation = sender.get_model('Transformation')
|
||||||
|
|
||||||
instance = kwargs['instance']
|
instance = kwargs['instance']
|
||||||
|
|
||||||
# TODO: Fix this, source should be previous version
|
# TODO: Fix this, source should be previous version
|
||||||
@@ -25,7 +28,11 @@ def copy_transformations_to_version(sender, **kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def initialize_periodic_tasks(**kwargs):
|
def initialize_periodic_tasks(sender, **kwargs):
|
||||||
|
POP3Email = sender.get_model('POP3Email')
|
||||||
|
IMAPEmail = sender.get_model('IMAPEmail')
|
||||||
|
WatchFolderSource = sender.get_model('WatchFolderSource')
|
||||||
|
|
||||||
for source in POP3Email.objects.filter(enabled=True):
|
for source in POP3Email.objects.filter(enabled=True):
|
||||||
source.save()
|
source.save()
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ from djcelery.models import PeriodicTask
|
|||||||
|
|
||||||
from mayan.celery import app
|
from mayan.celery import app
|
||||||
|
|
||||||
from .models import StatisticResult
|
|
||||||
|
|
||||||
|
|
||||||
class StatisticNamespace(object):
|
class StatisticNamespace(object):
|
||||||
_registry = {}
|
_registry = {}
|
||||||
@@ -45,6 +43,8 @@ class Statistic(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def purge_schedules():
|
def purge_schedules():
|
||||||
|
from .models import StatisticResult
|
||||||
|
|
||||||
queryset = PeriodicTask.objects.filter(name__startswith='statistics.').exclude(name__in=Statistic.get_task_names())
|
queryset = PeriodicTask.objects.filter(name__startswith='statistics.').exclude(name__in=Statistic.get_task_names())
|
||||||
|
|
||||||
for periodic_task in queryset:
|
for periodic_task in queryset:
|
||||||
@@ -112,12 +112,16 @@ class Statistic(object):
|
|||||||
return 'statistics.task_execute_statistic_{}'.format(self.slug)
|
return 'statistics.task_execute_statistic_{}'.format(self.slug)
|
||||||
|
|
||||||
def store_results(self, results):
|
def store_results(self, results):
|
||||||
|
from .models import StatisticResult
|
||||||
|
|
||||||
StatisticResult.objects.filter(slug=self.slug).delete()
|
StatisticResult.objects.filter(slug=self.slug).delete()
|
||||||
|
|
||||||
statistic_result, created = StatisticResult.objects.get_or_create(slug=self.slug)
|
statistic_result, created = StatisticResult.objects.get_or_create(slug=self.slug)
|
||||||
statistic_result.store_data(data=results)
|
statistic_result.store_data(data=results)
|
||||||
|
|
||||||
def get_results(self):
|
def get_results(self):
|
||||||
|
from .models import StatisticResult
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return StatisticResult.objects.get(slug=self.slug).get_data()
|
return StatisticResult.objects.get(slug=self.slug).get_data()
|
||||||
except StatisticResult.DoesNotExist:
|
except StatisticResult.DoesNotExist:
|
||||||
|
|||||||
Reference in New Issue
Block a user