Skip to content

Commit

Permalink
Assign owner to start task
Browse files Browse the repository at this point in the history
  • Loading branch information
kmmbvnr committed Jun 4, 2014
1 parent f0ce084 commit 3e85efa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion tests/examples/shipment/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.test import TestCase
from viewflow.graphviz import diagram
from viewflow.models import Task
from viewflow.test import FlowTest

from examples.shipment.flows import ShipmentFlow
Expand All @@ -20,6 +21,9 @@ def test_diagram_creation_succeed(self):


class ShipmentFlowTests(TestCase):
def task(self, process, flow_task):
return Task.objects.get(process=process, flow_task=flow_task)

def setUp(self):
self.default_carrier = Carrier.objects.get(name=Carrier.DEFAULT)
self.special_carrier = Carrier.objects.exclude(name=Carrier.DEFAULT)[0]
Expand All @@ -29,7 +33,8 @@ def test_normal_post_succeed(self):
# Clerk start process
flow.Task(ShipmentFlow.start).User('shipment/clerk') \
.Execute({'goods_tag': 'TST123'}) \
.Assert(lambda p: p.created is not None)
.Assert(lambda p: p.created is not None) \
.Assert(lambda p: self.task(p, ShipmentFlow.start).owner.username == 'shipment/clerk')

# Clerk decides that is special shipment post
flow.Task(ShipmentFlow.shipment_type).User('shipment/clerk') \
Expand Down
5 changes: 5 additions & 0 deletions viewflow/flow/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def get_management_form_cls(self):
else:
return self.flow_cls.management_form_cls

def assign(self, user):
self.task.assign(user=user)

def prepare(self, data=None):
super(StartViewActivation, self).prepare()

Expand Down Expand Up @@ -130,6 +133,7 @@ def dispatch(self, request, activation, **kwargs):
if not self.activation.flow_task.has_perm(request.user):
raise PermissionDenied

self.activation.assign(user=request.user)
self.activation.prepare(request.POST or None)
return super(StartViewMixin, self).dispatch(request, **kwargs)

Expand Down Expand Up @@ -195,6 +199,7 @@ def dispatch(self, request, *args, **kwargs):
if not self.flow_task.has_perm(request.user):
raise PermissionDenied

self.assign(user=request.user)
self.prepare(request.POST or None)
return super(StartView, self).dispatch(request, *args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion viewflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _in_db(self):
"""
return self.pk

@transition(field=status, source=STATUS.NEW, target=STATUS.ASSIGNED, conditions=[_in_db])
@transition(field=status, source=STATUS.NEW, target=STATUS.ASSIGNED)
def assign(self, user=None, external_task_id=None):
"""
Tasks that perform some activity should be associated with
Expand Down

0 comments on commit 3e85efa

Please sign in to comment.