Delete periodic task on document type delete

Closes Gitlab issue #715. Thanks to Rob de Canha-Knight (@rssfed23)
for the report and research.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-12-17 01:27:55 -04:00
parent 8b1c5eb868
commit 4f1ecebcac
3 changed files with 20 additions and 4 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import absolute_import, unicode_literals from __future__ import absolute_import, unicode_literals
from django.apps import apps
from django.db.models.signals import pre_delete
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from mayan.apps.common.apps import MayanAppConfig from mayan.apps.common.apps import MayanAppConfig
@@ -17,7 +19,9 @@ from mayan.apps.navigation.classes import SourceColumn
from .classes import StagingFile from .classes import StagingFile
from .handlers import ( from .handlers import (
handler_copy_transformations_to_version, handler_copy_transformations_to_version,
handler_create_default_document_source, handler_initialize_periodic_tasks handler_create_default_document_source,
handler_delete_interval_source_periodic_task,
handler_initialize_periodic_tasks
) )
from .links import ( from .links import (
link_document_create_multiple, link_setup_sources, link_document_create_multiple, link_setup_sources,
@@ -41,6 +45,9 @@ class SourcesApp(MayanAppConfig):
def ready(self): def ready(self):
super(SourcesApp, self).ready() super(SourcesApp, self).ready()
DocumentType = apps.get_model(
app_label='documents', model_name='DocumentType'
)
POP3Email = self.get_model(model_name='POP3Email') POP3Email = self.get_model(model_name='POP3Email')
IMAPEmail = self.get_model(model_name='IMAPEmail') IMAPEmail = self.get_model(model_name='IMAPEmail')
@@ -162,3 +169,8 @@ class SourcesApp(MayanAppConfig):
receiver=handler_copy_transformations_to_version, receiver=handler_copy_transformations_to_version,
dispatch_uid='sources_handler_copy_transformations_to_version' dispatch_uid='sources_handler_copy_transformations_to_version'
) )
pre_delete.connect(
receiver=handler_delete_interval_source_periodic_task,
sender=DocumentType,
dispatch_uid='sources_handler_delete_interval_source_periodic_task'
)

View File

@@ -28,6 +28,11 @@ def handler_create_default_document_source(sender, **kwargs):
) )
def handler_delete_interval_source_periodic_task(sender, instance, **kwargs):
for interval_source in instance.interval_sources.all():
interval_source._delete_periodic_task()
def handler_initialize_periodic_tasks(sender, **kwargs): def handler_initialize_periodic_tasks(sender, **kwargs):
POP3Email = apps.get_model(app_label='sources', model_name='POP3Email') POP3Email = apps.get_model(app_label='sources', model_name='POP3Email')
IMAPEmail = apps.get_model(app_label='sources', model_name='IMAPEmail') IMAPEmail = apps.get_model(app_label='sources', model_name='IMAPEmail')

View File

@@ -176,11 +176,10 @@ class IntervalBaseModel(OutOfProcessSource):
verbose_name=_('Interval') verbose_name=_('Interval')
) )
document_type = models.ForeignKey( document_type = models.ForeignKey(
DocumentType,
help_text=_( help_text=_(
'Assign a document type to documents uploaded from this source.' 'Assign a document type to documents uploaded from this source.'
), on_delete=models.CASCADE, ), on_delete=models.CASCADE, to=DocumentType,
verbose_name=_('Document type') related_name='interval_sources', verbose_name=_('Document type')
) )
uncompress = models.CharField( uncompress = models.CharField(
choices=SOURCE_UNCOMPRESS_CHOICES, choices=SOURCE_UNCOMPRESS_CHOICES,