diff --git a/mayan/apps/document_states/models.py b/mayan/apps/document_states/models.py index 01b97669e3..4df0701340 100644 --- a/mayan/apps/document_states/models.py +++ b/mayan/apps/document_states/models.py @@ -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')