[6295] | 1 | """Workflow for applicants. |
---|
| 2 | """ |
---|
| 3 | import grok |
---|
[6318] | 4 | from datetime import datetime |
---|
[6353] | 5 | from hurry.workflow.workflow import Transition, WorkflowState, NullCondition |
---|
| 6 | from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent |
---|
[6295] | 7 | from waeup.sirp.applicants.interfaces import IApplicantBaseData |
---|
[6353] | 8 | from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo |
---|
[6355] | 9 | from waeup.sirp.workflow import WAeUPWorkflow, WAeUPWorkflowInfo |
---|
[6295] | 10 | |
---|
| 11 | INITIALIZED = 'initialized' |
---|
| 12 | STARTED = 'started' |
---|
| 13 | SUBMITTED = 'submitted' |
---|
| 14 | ADMITTED = 'admitted' |
---|
| 15 | NOT_ADMITTED = 'not admitted' |
---|
| 16 | CREATED = 'created' |
---|
| 17 | |
---|
[6354] | 18 | APPLICATION_TRANSITIONS = ( |
---|
[6353] | 19 | Transition( |
---|
[6295] | 20 | transition_id = 'init', |
---|
[6306] | 21 | title = 'Initialize application', |
---|
[6295] | 22 | source = None, |
---|
| 23 | condition = NullCondition, |
---|
[6471] | 24 | msg = 'Application initialized', |
---|
[6353] | 25 | destination = INITIALIZED), |
---|
[6295] | 26 | |
---|
[6353] | 27 | Transition( |
---|
[6295] | 28 | transition_id = 'start', |
---|
[6300] | 29 | title = 'Start application', |
---|
[6471] | 30 | msg = 'Application started', |
---|
[6295] | 31 | source = INITIALIZED, |
---|
[6353] | 32 | destination = STARTED), |
---|
[6295] | 33 | |
---|
[6353] | 34 | Transition( |
---|
[6295] | 35 | transition_id = 'submit', |
---|
[6307] | 36 | title = 'Submit application', |
---|
[6471] | 37 | msg = 'Application submitted', |
---|
[6295] | 38 | source = STARTED, |
---|
[6353] | 39 | destination = SUBMITTED), |
---|
[6295] | 40 | |
---|
[6353] | 41 | Transition( |
---|
[6295] | 42 | transition_id = 'admit', |
---|
[6300] | 43 | title = 'Admit applicant', |
---|
[6471] | 44 | msg = 'Applicant admitted', |
---|
[6295] | 45 | source = SUBMITTED, |
---|
[6353] | 46 | destination = ADMITTED), |
---|
[6295] | 47 | |
---|
[6353] | 48 | Transition( |
---|
[6300] | 49 | transition_id = 'refuse1', |
---|
| 50 | title = 'Refuse application', |
---|
[6471] | 51 | msg = 'Application refused', |
---|
[6295] | 52 | source = SUBMITTED, |
---|
[6353] | 53 | destination = NOT_ADMITTED), |
---|
[6295] | 54 | |
---|
[6353] | 55 | Transition( |
---|
[6300] | 56 | transition_id = 'refuse2', |
---|
| 57 | title = 'Refuse application', |
---|
[6471] | 58 | msg = 'Application refused', |
---|
[6300] | 59 | source = ADMITTED, |
---|
[6353] | 60 | destination = NOT_ADMITTED), |
---|
[6300] | 61 | |
---|
[6353] | 62 | Transition( |
---|
[6295] | 63 | transition_id = 'create', |
---|
[6307] | 64 | title = 'Create student record', |
---|
[6471] | 65 | msg = 'Student record created', |
---|
[6295] | 66 | source = ADMITTED, |
---|
[6353] | 67 | destination = CREATED), |
---|
[6295] | 68 | |
---|
[6353] | 69 | Transition( |
---|
[6300] | 70 | transition_id = 'reset1', |
---|
| 71 | title = 'Reset application', |
---|
[6471] | 72 | msg = 'Application reset', |
---|
[6300] | 73 | source = SUBMITTED, |
---|
[6353] | 74 | destination = STARTED), |
---|
[6295] | 75 | |
---|
[6353] | 76 | Transition( |
---|
[6300] | 77 | transition_id = 'reset2', |
---|
| 78 | title = 'Reset application', |
---|
[6471] | 79 | msg = 'Application reset', |
---|
[6300] | 80 | source = ADMITTED, |
---|
[6353] | 81 | destination = STARTED), |
---|
[6300] | 82 | |
---|
[6353] | 83 | Transition( |
---|
[6300] | 84 | transition_id = 'reset3', |
---|
| 85 | title = 'Reset application', |
---|
[6471] | 86 | msg = 'Application reset', |
---|
[6300] | 87 | source = NOT_ADMITTED, |
---|
[6353] | 88 | destination = STARTED), |
---|
[6300] | 89 | |
---|
[6353] | 90 | Transition( |
---|
[6300] | 91 | transition_id = 'reset4', |
---|
| 92 | title = 'Reset application', |
---|
[6471] | 93 | msg = 'Application reset', |
---|
[6300] | 94 | source = CREATED, |
---|
[6353] | 95 | destination = STARTED), |
---|
| 96 | ) |
---|
[6300] | 97 | |
---|
[6354] | 98 | application_workflow = WAeUPWorkflow(APPLICATION_TRANSITIONS) |
---|
[6295] | 99 | |
---|
[6349] | 100 | class ApplicationWorkflowState(WorkflowState, grok.Adapter): |
---|
[6295] | 101 | """An adapter to adapt Applicant objects to workflow states. |
---|
| 102 | """ |
---|
| 103 | grok.context(IApplicantBaseData) |
---|
| 104 | grok.provides(IWorkflowState) |
---|
[6316] | 105 | |
---|
[6349] | 106 | state_key = 'wf.application.state' |
---|
| 107 | state_id = 'wf.application.id' |
---|
| 108 | |
---|
[6353] | 109 | class ApplicationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter): |
---|
[6295] | 110 | """Adapter to adapt Applicant objects to workflow info objects. |
---|
| 111 | """ |
---|
| 112 | grok.context(IApplicantBaseData) |
---|
[6353] | 113 | grok.provides(IWAeUPWorkflowInfo) |
---|
[6318] | 114 | |
---|
[6349] | 115 | def __init__(self, context): |
---|
| 116 | self.context = context |
---|
| 117 | self.wf = application_workflow |
---|
[6318] | 118 | |
---|
| 119 | @grok.subscribe(IApplicantBaseData, IWorkflowTransitionEvent) |
---|
| 120 | def handle_applicant_transition_event(obj, event): |
---|
[6471] | 121 | """Append message to applicant history when transition happened. |
---|
[6318] | 122 | """ |
---|
[6471] | 123 | msg = '%s' % event.transition.user_data['msg'] |
---|
[6339] | 124 | history = IObjectHistory(obj) |
---|
| 125 | history.addMessage(msg) |
---|
[6318] | 126 | return |
---|