Changeset 6353 for main/waeup.sirp/trunk/src/waeup/sirp/applicants
- Timestamp:
- 11 Jun 2011, 18:51:17 (14 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/applicants
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py
r6351 r6353 59 59 IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab 60 60 ) 61 from waeup.sirp.applicants.workflow import create_workflow,INITIALIZED, STARTED61 from waeup.sirp.applicants.workflow import INITIALIZED, STARTED 62 62 63 63 results_widget = CustomWidgetFactory( … … 73 73 MultiListDisplayWidget, subwidget=results_display_widget) 74 74 75 TRANSITION_OBJECTS = create_workflow()75 #TRANSITION_OBJECTS = create_workflow() 76 76 77 77 #TRANSITION_DICT = dict([ … … 538 538 datepicker.need() # Enable jQuery datepicker in date fields. 539 539 super(EditApplicantFull, self).update() 540 self.wf_info = IWorkflowInfo(self.context) 540 541 return 541 542 … … 551 552 def getTransitions(self): 552 553 """Return a list of dicts of allowed transition ids and titles. 554 555 Each list entry provides keys ``name`` and ``title`` for 556 internal name and (human readable) title of a single 557 transition. 553 558 """ 554 allowed_transitions_ids = IWorkflowInfo( 555 self.context).getManualTransitionIds() 556 null_transition = [{'name': '', 'title':'No transition'}] 557 transitions = null_transition + [dict( 558 name=transition_object.transition_id, 559 title=transition_object.title) 560 for transition_object in TRANSITION_OBJECTS 561 if transition_object.transition_id in allowed_transitions_ids] 562 return transitions 559 allowed_transitions = self.wf_info.getManualTransitions() 560 return [dict(name=x, title=y) for x, y in allowed_transitions] 563 561 564 562 @grok.action('Save') … … 569 567 if form.has_key('transition') and form['transition']: 570 568 transition_id = form['transition'] 571 IWorkflowInfo(self.context).fireTransition(transition_id)569 self.wf_info.fireTransition(transition_id) 572 570 self.flash('Form has been saved.') 573 571 self.context.getApplicantsRootLogger().info('Saved') -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/workflow.py
r6349 r6353 3 3 import grok 4 4 from datetime import datetime 5 from hurry.workflow.workflow import ( 6 Transition, Workflow, WorkflowVersions, WorkflowInfo, WorkflowState, 7 NullCondition) 8 from hurry.workflow.interfaces import ( 9 IWorkflow, IWorkflowState, IWorkflowInfo, IWorkflowVersions, 10 InvalidTransitionError, IWorkflowTransitionEvent) 5 from hurry.workflow.workflow import Transition, WorkflowState, NullCondition 6 from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent 11 7 from waeup.sirp.applicants.interfaces import IApplicantBaseData 12 from waeup.sirp.interfaces import IObjectHistory 8 from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo 9 from waeup.sirp.workflow import ( 10 WAeUPWorkflow, WAeUPWorkflowInfo, NULL_TRANSITION) 13 11 14 12 INITIALIZED = 'initialized' … … 19 17 CREATED = 'created' 20 18 21 NULL_TRANSITION = Transition( 22 transition_id = '', 23 title = 'No transition', 24 source = None, 25 condition = NullCondition, 26 msg = '', 27 destination = None,) 19 APPLICATION_TRANSISIONS = ( 20 NULL_TRANSITION, 28 21 29 def create_workflow(): 30 init_transition = Transition( 22 Transition( 31 23 transition_id = 'init', 32 24 title = 'Initialize application', … … 34 26 condition = NullCondition, 35 27 msg = 'application process initialized', 36 destination = INITIALIZED) 28 destination = INITIALIZED), 37 29 38 start_transition =Transition(30 Transition( 39 31 transition_id = 'start', 40 32 title = 'Start application', 41 33 msg = 'application process started', 42 34 source = INITIALIZED, 43 destination = STARTED) 35 destination = STARTED), 44 36 45 submit_transition =Transition(37 Transition( 46 38 transition_id = 'submit', 47 39 title = 'Submit application', 48 40 msg = 'application record submitted', 49 41 source = STARTED, 50 destination = SUBMITTED) 42 destination = SUBMITTED), 51 43 52 admit_transition =Transition(44 Transition( 53 45 transition_id = 'admit', 54 46 title = 'Admit applicant', 55 47 msg = 'applicant admitted', 56 48 source = SUBMITTED, 57 destination = ADMITTED) 49 destination = ADMITTED), 58 50 59 refuse1_transition =Transition(51 Transition( 60 52 transition_id = 'refuse1', 61 53 title = 'Refuse application', 62 54 msg = 'application refused', 63 55 source = SUBMITTED, 64 destination = NOT_ADMITTED) 56 destination = NOT_ADMITTED), 65 57 66 refuse2_transition =Transition(58 Transition( 67 59 transition_id = 'refuse2', 68 60 title = 'Refuse application', 69 61 msg = 'application refused', 70 62 source = ADMITTED, 71 destination = NOT_ADMITTED) 63 destination = NOT_ADMITTED), 72 64 73 create_transition =Transition(65 Transition( 74 66 transition_id = 'create', 75 67 title = 'Create student record', 76 68 msg = 'student record created', 77 69 source = ADMITTED, 78 destination = CREATED) 70 destination = CREATED), 79 71 80 reset1_transition =Transition(72 Transition( 81 73 transition_id = 'reset1', 82 74 title = 'Reset application', 83 75 msg = 'application record reset', 84 76 source = SUBMITTED, 85 destination = STARTED) 77 destination = STARTED), 86 78 87 reset2_transition =Transition(79 Transition( 88 80 transition_id = 'reset2', 89 81 title = 'Reset application', 90 82 msg = 'application record reset', 91 83 source = ADMITTED, 92 destination = STARTED) 84 destination = STARTED), 93 85 94 reset3_transition =Transition(86 Transition( 95 87 transition_id = 'reset3', 96 88 title = 'Reset application', 97 89 msg = 'application record reset', 98 90 source = NOT_ADMITTED, 99 destination = STARTED) 91 destination = STARTED), 100 92 101 reset4_transition =Transition(93 Transition( 102 94 transition_id = 'reset4', 103 95 title = 'Reset application', 104 96 msg = 'application record reset', 105 97 source = CREATED, 106 destination = STARTED) 98 destination = STARTED), 99 ) 107 100 108 return [NULL_TRANSITION, init_transition, start_transition, 109 submit_transition, admit_transition, create_transition, 110 refuse1_transition, refuse2_transition, reset1_transition, 111 reset2_transition, reset3_transition, reset4_transition] 112 113 114 class ApplicationWorkflow(Workflow): 115 """A hurry.workflow Workflow with more appropriate error messages. 116 """ 117 grok.provides(IWorkflow) 118 def __init__(self): 119 super(Workflow, self).__init__() 120 self.refresh(create_workflow()) 121 122 def getTransition(self, source, transition_id): 123 transition = self._id_transitions[transition_id] 124 if transition.source != source: 125 raise InvalidTransitionError( 126 "Transition '%s' requires '%s' as source state (is: '%s')" % ( 127 transition_id, transition.source, source)) 128 return transition 129 130 131 class ApplicationWorkflowNullVersions(WorkflowVersions): 132 """A workflow versions manager that does not handle versions. 133 134 Sounds odd, but the default implementation of 135 :class:`hurry.workflow.workflow.WorkflowVersions` is a base 136 implementation that raises :exc:`NotImplemented` exceptions for 137 most of the methods defined below. 138 139 If we want to register a versionless workflow, an utility 140 implementing IWorkflowVersions is looked up nevertheless by 141 WorkflowInfo and WorkflowState components so we **have** to 142 provide workflow versions, even if we do not support versioned 143 workflows. 144 145 This implementation returns empty result sets for any requests, 146 but does not raise :exc:`NotImplemented`. 147 """ 148 def getVersions(self, state, id): 149 return [] 150 151 def getVersionsWithAutomaticTransitions(self): 152 return [] 153 154 def hasVersion(self, id, state): 155 return False 156 157 def hasVersionId(self, id): 158 return False 159 160 # Register global utilities for workflows and workflow versions... 161 #grok.global_utility(ApplicationWorkflow, IWorkflow, name=WORKFLOW_NAME) 162 #grok.global_utility(ApplicationWorkflowNullVersions, IWorkflowVersions, 163 # name=WORKFLOW_NAME) 164 165 application_workflow = ApplicationWorkflow() 101 application_workflow = WAeUPWorkflow(APPLICATION_TRANSISIONS) 166 102 167 103 class ApplicationWorkflowState(WorkflowState, grok.Adapter): … … 174 110 state_id = 'wf.application.id' 175 111 176 class ApplicationWorkflowInfo(W orkflowInfo, grok.Adapter):112 class ApplicationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter): 177 113 """Adapter to adapt Applicant objects to workflow info objects. 178 114 """ 179 115 grok.context(IApplicantBaseData) 180 grok.provides(IW orkflowInfo)116 grok.provides(IWAeUPWorkflowInfo) 181 117 182 118 def __init__(self, context):
Note: See TracChangeset for help on using the changeset viewer.