[6295] | 1 | """Workflow for applicants. |
---|
| 2 | """ |
---|
| 3 | import grok |
---|
| 4 | from hurry.workflow.workflow import Transition, Workflow, WorkflowVersions |
---|
| 5 | from hurry.workflow.workflow import WorkflowInfo, WorkflowState, NullCondition |
---|
| 6 | from hurry.workflow.interfaces import MANUAL, AUTOMATIC, SYSTEM |
---|
| 7 | from hurry.workflow.interfaces import IWorkflow, IWorkflowState, IWorkflowInfo |
---|
| 8 | from hurry.workflow.interfaces import IWorkflowVersions |
---|
| 9 | from waeup.sirp.applicants.interfaces import IApplicantBaseData |
---|
| 10 | |
---|
| 11 | INITIALIZED = 'initialized' |
---|
| 12 | STARTED = 'started' |
---|
| 13 | SUBMITTED = 'submitted' |
---|
| 14 | ADMITTED = 'admitted' |
---|
| 15 | NOT_ADMITTED = 'not admitted' |
---|
| 16 | CREATED = 'created' |
---|
| 17 | |
---|
| 18 | def create_workflow(): |
---|
| 19 | init_transition = Transition( |
---|
| 20 | transition_id = 'init', |
---|
| 21 | title = 'Initialize', |
---|
| 22 | source = None, |
---|
| 23 | condition = NullCondition, |
---|
| 24 | destination = INITIALIZED) |
---|
| 25 | |
---|
| 26 | start_transition = Transition( |
---|
| 27 | transition_id = 'start', |
---|
| 28 | title = 'Start', |
---|
| 29 | source = INITIALIZED, |
---|
| 30 | destination = STARTED) |
---|
| 31 | |
---|
| 32 | submit_transition = Transition( |
---|
| 33 | transition_id = 'submit', |
---|
| 34 | title = 'Submit', |
---|
| 35 | source = STARTED, |
---|
| 36 | destination = SUBMITTED) |
---|
| 37 | |
---|
| 38 | admit_transition = Transition( |
---|
| 39 | transition_id = 'admit', |
---|
| 40 | title = 'Admit', |
---|
| 41 | source = SUBMITTED, |
---|
| 42 | destination = ADMITTED) |
---|
| 43 | |
---|
| 44 | defer_transition = Transition( |
---|
| 45 | transition_id = 'defer', |
---|
| 46 | title = 'Defer', |
---|
| 47 | source = SUBMITTED, |
---|
| 48 | destination = NOT_ADMITTED) |
---|
| 49 | |
---|
| 50 | create_transition = Transition( |
---|
| 51 | transition_id = 'create', |
---|
| 52 | title = 'Create Student', |
---|
| 53 | source = ADMITTED, |
---|
| 54 | destination = CREATED) |
---|
| 55 | |
---|
| 56 | #final_transition = Transition( |
---|
| 57 | # transition_id = 'finalize', |
---|
| 58 | # title = 'Delete', |
---|
| 59 | # source = ADMITTED, |
---|
| 60 | # destination = None) |
---|
| 61 | |
---|
| 62 | return [init_transition, start_transition, submit_transition, admit_transition, |
---|
| 63 | defer_transition, create_transition,] |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | class ApplicationWorkflow(Workflow): |
---|
| 67 | """A hurry.workflow Workflow with more appropriate error messages. |
---|
| 68 | """ |
---|
| 69 | grok.provides(IWorkflow) |
---|
| 70 | def __init__(self): |
---|
| 71 | super(Workflow, self).__init__() |
---|
| 72 | self.refresh(create_workflow()) |
---|
| 73 | |
---|
| 74 | def getTransition(self, source, transition_id): |
---|
| 75 | from hurry.workflow.interfaces import\ |
---|
| 76 | InvalidTransitionError, ConditionFailedError |
---|
| 77 | |
---|
| 78 | transition = self._id_transitions[transition_id] |
---|
| 79 | if transition.source != source: |
---|
| 80 | raise InvalidTransitionError( |
---|
| 81 | "Transition '%s' requires '%s' as source state (is: '%s')" % ( |
---|
| 82 | transition_id, transition.source, source)) |
---|
| 83 | return transition |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | class ApplicationWorkflowNullVersions(WorkflowVersions): |
---|
| 87 | """A workflow versions manager that does not handle versions. |
---|
| 88 | |
---|
| 89 | Sounds odd, but the default implementation of |
---|
| 90 | :class:`hurry.workflow.workflow.WorkflowVersions` is a base |
---|
| 91 | implementation that raises :exc:`NotImplemented` exceptions for |
---|
| 92 | most of the methods defined below. |
---|
| 93 | |
---|
| 94 | If we want to register a versionless workflow, an utility |
---|
| 95 | implementing IWorkflowVersions is looked up nevertheless by |
---|
| 96 | WorkflowInfo and WorkflowState components so we **have** to |
---|
| 97 | provide workflow versions, even if we do not support versioned |
---|
| 98 | workflows. |
---|
| 99 | |
---|
| 100 | This implementation returns empty result sets for any requests, |
---|
| 101 | but does not raise :exc:`NotImplemented`. |
---|
| 102 | """ |
---|
| 103 | def getVersions(self, state, id): |
---|
| 104 | return [] |
---|
| 105 | |
---|
| 106 | def getVersionsWithAutomaticTransitions(self): |
---|
| 107 | return [] |
---|
| 108 | |
---|
| 109 | def hasVersion(self, id, state): |
---|
| 110 | return False |
---|
| 111 | |
---|
| 112 | def hasVersionId(self, id): |
---|
| 113 | return False |
---|
| 114 | |
---|
| 115 | # Register global utilities for workflows and workflow versions... |
---|
| 116 | grok.global_utility(ApplicationWorkflow, IWorkflow) |
---|
| 117 | grok.global_utility(ApplicationWorkflowNullVersions, IWorkflowVersions) |
---|
| 118 | |
---|
| 119 | class WorkflowState(grok.Adapter, WorkflowState): |
---|
| 120 | """An adapter to adapt Applicant objects to workflow states. |
---|
| 121 | """ |
---|
| 122 | grok.context(IApplicantBaseData) |
---|
| 123 | grok.provides(IWorkflowState) |
---|
| 124 | |
---|
| 125 | class WorkflowInfo(grok.Adapter, WorkflowInfo): |
---|
| 126 | """Adapter to adapt Applicant objects to workflow info objects. |
---|
| 127 | """ |
---|
| 128 | grok.context(IApplicantBaseData) |
---|
| 129 | grok.provides(IWorkflowInfo) |
---|