Catch re-launching a workflow for a document and logging the condition

This commit is contained in:
Roberto Rosario
2015-06-16 04:37:05 -04:00
parent dee9c3fb70
commit bb205e7cf9

View File

@@ -1,8 +1,10 @@
from __future__ import unicode_literals
import logging
from django.contrib.auth.models import User
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.translation import ugettext_lazy as _
@@ -10,6 +12,8 @@ from documents.models import Document, DocumentType
from .managers import WorkflowManager
logger = logging.getLogger(__name__)
@python_2_unicode_compatible
class Workflow(models.Model):
@@ -31,7 +35,13 @@ class Workflow(models.Model):
return None
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:
verbose_name = _('Workflow')