I'm using Viewflow/Django and trying to assign tasks created by dynamic nodes.
I'm using the same nodes.py
in customnode.
However, I need to automatically assign each new task based on information in the MOCTask model
(the assignee).
But tasks don't allow an Assign with anything other than a specific user object and I don't have access to the MOCTask
objects (they are related by foreign key to MOC, which is related by foreign key to MOCProcess
, the flow itself).
My code I was trying (flows.py):
...
split_on_task_assignment = (
DynamicSplit(lambda p: MOCTask.objects.filter(MOC=p.MOC).count())
.IfNone(this.end)
.Next(this.task_completion)
)
task_completion = (
flow.View(views.TaskCompletion)
.Permission('MOC.is_MOC_actor')
.Assign(this.assign_actors)
.Next(this.join_on_task_completion)
)
...
def assign_actors(self, activation):
task = MOCTask.objects.filter(MOC=activation.process.MOC, assigned=False).first()
task.assigned = True
task.save()
return User.objects.filter(email=task.assignee).first()
However, I can't put a this
reference in the assign block, so I'm not sure how to proceed.
Any ideas?
Users can be assigned inside DynamicSplitActivation
when subsequent tasks are created
def activate_next(self):
if self._split_count:
token_source = Token.split_token_source(
self.task.token, self.task.pk)
for _ in range(self._split_count):
activation = self.flow_task._next.activate(
prev_activation=self, token=next(token_source))
activation.activate(..a user..)