Make sure the on entry action of the initial state of workflows executes on document creation.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
wiki.mayan-edms.com
|
||||
- Unify template title rendering.
|
||||
- Add support for template subtitles.
|
||||
- Make sure the on entry action of the initial state of workflows
|
||||
executes on document creation.
|
||||
|
||||
3.0.1 (2018-07-08)
|
||||
=================
|
||||
|
||||
@@ -4,4 +4,4 @@ from django.db import models
|
||||
class WorkflowManager(models.Manager):
|
||||
def launch_for(self, document):
|
||||
for workflow in document.document_type.workflows.all():
|
||||
workflow.launch_for(document)
|
||||
workflow.launch_for(document=document)
|
||||
|
||||
@@ -76,7 +76,12 @@ class Workflow(models.Model):
|
||||
logger.info(
|
||||
'Launching workflow %s for document %s', self, document
|
||||
)
|
||||
self.instances.create(document=document)
|
||||
workflow_instance = self.instances.create(document=document)
|
||||
initial_state = self.get_initial_state()
|
||||
|
||||
if initial_state:
|
||||
for action in initial_state.entry_actions.filter(enabled=True):
|
||||
action.execute(context=workflow_instance.get_context())
|
||||
except IntegrityError:
|
||||
logger.info(
|
||||
'Workflow %s already launched for document %s', self, document
|
||||
@@ -352,6 +357,12 @@ class WorkflowInstance(models.Model):
|
||||
'document_states:workflow_instance_detail', args=(str(self.pk),)
|
||||
)
|
||||
|
||||
def get_context(self):
|
||||
return {
|
||||
'document': self.document, 'workflow': self.workflow,
|
||||
'workflow_instance': self,
|
||||
}
|
||||
|
||||
def get_current_state(self):
|
||||
"""
|
||||
Actual State - The current state of the workflow. If there are
|
||||
@@ -455,12 +466,19 @@ class WorkflowInstanceLogEntry(models.Model):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
result = super(WorkflowInstanceLogEntry, self).save(*args, **kwargs)
|
||||
context = self.workflow_instance.get_context()
|
||||
context.update(
|
||||
{
|
||||
'action': action,
|
||||
'entry_log': self
|
||||
}
|
||||
)
|
||||
|
||||
for action in self.transition.origin_state.exit_actions.filter(enabled=True):
|
||||
action.execute(context={'action': action, 'entry_log': self})
|
||||
action.execute(context=context)
|
||||
|
||||
for action in self.transition.destination_state.entry_actions.filter(enabled=True):
|
||||
action.execute(context={'action': action, 'entry_log': self})
|
||||
action.execute(context=context)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -55,9 +55,7 @@ class AttachTagAction(WorkflowAction):
|
||||
|
||||
def execute(self, context):
|
||||
for tag in self.get_tags():
|
||||
tag.attach_to(
|
||||
document=context['entry_log'].workflow_instance.document
|
||||
)
|
||||
tag.attach_to(document=context['document'])
|
||||
|
||||
|
||||
class RemoveTagAction(AttachTagAction):
|
||||
@@ -75,6 +73,4 @@ class RemoveTagAction(AttachTagAction):
|
||||
|
||||
def execute(self, context):
|
||||
for tag in self.get_tags():
|
||||
tag.remove_from(
|
||||
document=context['entry_log'].workflow_instance.document
|
||||
)
|
||||
tag.remove_from(document=context['document'])
|
||||
|
||||
Reference in New Issue
Block a user