Ignore:
Timestamp:
11 Jun 2011, 18:51:17 (14 years ago)
Author:
uli
Message:

Split workflow components (general use stuff goes to w.s.workflow), add some convenience stuff, ...)

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r6351 r6353  
    5959    IApplicantsContainer, IApplicantsContainerAdd, application_types_vocab
    6060    )
    61 from waeup.sirp.applicants.workflow import create_workflow, INITIALIZED, STARTED
     61from waeup.sirp.applicants.workflow import INITIALIZED, STARTED
    6262
    6363results_widget = CustomWidgetFactory(
     
    7373    MultiListDisplayWidget, subwidget=results_display_widget)
    7474
    75 TRANSITION_OBJECTS = create_workflow()
     75#TRANSITION_OBJECTS = create_workflow()
    7676
    7777#TRANSITION_DICT = dict([
     
    538538        datepicker.need() # Enable jQuery datepicker in date fields.
    539539        super(EditApplicantFull, self).update()
     540        self.wf_info = IWorkflowInfo(self.context)
    540541        return
    541542
     
    551552    def getTransitions(self):
    552553        """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.
    553558        """
    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]
    563561
    564562    @grok.action('Save')
     
    569567        if form.has_key('transition') and form['transition']:
    570568            transition_id = form['transition']
    571             IWorkflowInfo(self.context).fireTransition(transition_id)
     569            self.wf_info.fireTransition(transition_id)
    572570        self.flash('Form has been saved.')
    573571        self.context.getApplicantsRootLogger().info('Saved')
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/workflow.py

    r6349 r6353  
    33import grok
    44from 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)
     5from hurry.workflow.workflow import Transition, WorkflowState, NullCondition
     6from hurry.workflow.interfaces import IWorkflowState, IWorkflowTransitionEvent
    117from waeup.sirp.applicants.interfaces import IApplicantBaseData
    12 from waeup.sirp.interfaces import IObjectHistory
     8from waeup.sirp.interfaces import IObjectHistory, IWAeUPWorkflowInfo
     9from waeup.sirp.workflow import (
     10    WAeUPWorkflow, WAeUPWorkflowInfo, NULL_TRANSITION)
    1311
    1412INITIALIZED = 'initialized'
     
    1917CREATED = 'created'
    2018
    21 NULL_TRANSITION = Transition(
    22     transition_id = '',
    23     title = 'No transition',
    24     source = None,
    25     condition = NullCondition,
    26     msg = '',
    27     destination = None,)
     19APPLICATION_TRANSISIONS = (
     20    NULL_TRANSITION,
    2821
    29 def create_workflow():
    30     init_transition = Transition(
     22    Transition(
    3123        transition_id = 'init',
    3224        title = 'Initialize application',
     
    3426        condition = NullCondition,
    3527        msg = 'application process initialized',
    36         destination = INITIALIZED)
     28        destination = INITIALIZED),
    3729
    38     start_transition = Transition(
     30    Transition(
    3931        transition_id = 'start',
    4032        title = 'Start application',
    4133        msg = 'application process started',
    4234        source = INITIALIZED,
    43         destination = STARTED)
     35        destination = STARTED),
    4436
    45     submit_transition = Transition(
     37    Transition(
    4638        transition_id = 'submit',
    4739        title = 'Submit application',
    4840        msg = 'application record submitted',
    4941        source = STARTED,
    50         destination = SUBMITTED)
     42        destination = SUBMITTED),
    5143
    52     admit_transition = Transition(
     44    Transition(
    5345        transition_id = 'admit',
    5446        title = 'Admit applicant',
    5547        msg = 'applicant admitted',
    5648        source = SUBMITTED,
    57         destination = ADMITTED)
     49        destination = ADMITTED),
    5850
    59     refuse1_transition = Transition(
     51    Transition(
    6052        transition_id = 'refuse1',
    6153        title = 'Refuse application',
    6254        msg = 'application refused',
    6355        source = SUBMITTED,
    64         destination = NOT_ADMITTED)
     56        destination = NOT_ADMITTED),
    6557
    66     refuse2_transition = Transition(
     58    Transition(
    6759        transition_id = 'refuse2',
    6860        title = 'Refuse application',
    6961        msg = 'application refused',
    7062        source = ADMITTED,
    71         destination = NOT_ADMITTED)
     63        destination = NOT_ADMITTED),
    7264
    73     create_transition = Transition(
     65    Transition(
    7466        transition_id = 'create',
    7567        title = 'Create student record',
    7668        msg = 'student record created',
    7769        source = ADMITTED,
    78         destination = CREATED)
     70        destination = CREATED),
    7971
    80     reset1_transition = Transition(
     72    Transition(
    8173        transition_id = 'reset1',
    8274        title = 'Reset application',
    8375        msg = 'application record reset',
    8476        source = SUBMITTED,
    85         destination = STARTED)
     77        destination = STARTED),
    8678
    87     reset2_transition = Transition(
     79    Transition(
    8880        transition_id = 'reset2',
    8981        title = 'Reset application',
    9082        msg = 'application record reset',
    9183        source = ADMITTED,
    92         destination = STARTED)
     84        destination = STARTED),
    9385
    94     reset3_transition = Transition(
     86    Transition(
    9587        transition_id = 'reset3',
    9688        title = 'Reset application',
    9789        msg = 'application record reset',
    9890        source = NOT_ADMITTED,
    99         destination = STARTED)
     91        destination = STARTED),
    10092
    101     reset4_transition = Transition(
     93    Transition(
    10294        transition_id = 'reset4',
    10395        title = 'Reset application',
    10496        msg = 'application record reset',
    10597        source = CREATED,
    106         destination = STARTED)
     98        destination = STARTED),
     99    )
    107100
    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()
     101application_workflow = WAeUPWorkflow(APPLICATION_TRANSISIONS)
    166102
    167103class ApplicationWorkflowState(WorkflowState, grok.Adapter):
     
    174110    state_id = 'wf.application.id'
    175111
    176 class ApplicationWorkflowInfo(WorkflowInfo, grok.Adapter):
     112class ApplicationWorkflowInfo(WAeUPWorkflowInfo, grok.Adapter):
    177113    """Adapter to adapt Applicant objects to workflow info objects.
    178114    """
    179115    grok.context(IApplicantBaseData)
    180     grok.provides(IWorkflowInfo)
     116    grok.provides(IWAeUPWorkflowInfo)
    181117
    182118    def __init__(self, context):
  • main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py

    r6338 r6353  
    11##
    22## interfaces.py
     3from hurry.workflow.interfaces import IWorkflow, IWorkflowInfo
    34from zc.sourcefactory.basic import BasicSourceFactory
    45from zope import schema
     
    430431        """
    431432        pass
     433
     434class IWAeUPWorkflowInfo(IWorkflowInfo):
     435    """A :class:`hurry.workflow.workflow.WorkflowInfo` with additional
     436       methods for convenience.
     437    """
     438    def getManualTransitions():
     439        """Get allowed manual transitions.
     440
     441        Get a sorted list of tuples containing the `transition_id` and
     442        `title` of each allowed transition.
     443        """
     444        pass
Note: See TracChangeset for help on using the changeset viewer.