1
1
# -*- coding: utf-8 -*-
2
+ from pyramid .threadlocal import get_current_request
2
3
from fa .bootstrap import actions
3
4
from webob .exc import HTTPFound
4
5
from repoze .workflow import WorkflowError
@@ -16,7 +17,7 @@ def goto_state(context, request):
16
17
request .add_message (u'Workflow status has been changed. New workflow state is: <strong>%s</strong>.' % state )
17
18
return HTTPFound (location = request .fa_url (request .model_name , request .model_id ))
18
19
except WorkflowError , msg :
19
- print unicode (msg )
20
+ request . add_message (msg , 'error' )
20
21
return HTTPFound (location = request .fa_url (request .model_name , request .model_id ))
21
22
22
23
@@ -30,7 +31,8 @@ def change_workflow(context):
30
31
permission = 'workflow' ,
31
32
content = '%s state' % context .get_instance ().workflow_state )
32
33
33
- states = wf .get_transitions (context .get_instance (), None )
34
+ request = get_current_request ()
35
+ states = wf .get_transitions (context .get_instance (), request )
34
36
if not states :
35
37
return None
36
38
for state in states :
@@ -40,3 +42,9 @@ def change_workflow(context):
40
42
content = state ['name' ],
41
43
attrs = attrs ))
42
44
return wf_actions
45
+
46
+
47
+ def validate_contract_done (content , info ):
48
+ """ raise WorkflowError when contract has active CustomerRequests. """
49
+ if [a for a in content .customer_requests if a .active ]:
50
+ raise WorkflowError (u'Contract cannot be closed - there are customer requests still open.' )
0 commit comments