Catch re-launching a workflow for a document and logging the condition
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.db import models
|
from django.db import IntegrityError, models
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
@@ -10,6 +12,8 @@ from documents.models import Document, DocumentType
|
|||||||
|
|
||||||
from .managers import WorkflowManager
|
from .managers import WorkflowManager
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Workflow(models.Model):
|
class Workflow(models.Model):
|
||||||
@@ -31,7 +35,13 @@ class Workflow(models.Model):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def launch_for(self, document):
|
def launch_for(self, document):
|
||||||
self.instances.create(document=document)
|
try:
|
||||||
|
logger.info('Launching workflow %s for document %s', self, document)
|
||||||
|
self.instances.create(document=document)
|
||||||
|
except IntegrityError:
|
||||||
|
logger.info('Workflow %s already launched for document %s', self, document)
|
||||||
|
else:
|
||||||
|
logger.info('Workflow %s launched for document %s', self, document)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Workflow')
|
verbose_name = _('Workflow')
|
||||||
|
|||||||
Reference in New Issue
Block a user