Ignore:
Timestamp:
9 Jun 2011, 12:27:17 (13 years ago)
Author:
Henrik Bettermann
Message:

Control workflow in views.

File:
1 edited

Legend:

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

    r6254 r6303  
    3131from zope.traversing.browser import absoluteURL
    3232
     33from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
     34
    3335from waeup.sirp.browser import (
    3436    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage,
     
    6163from waeup.sirp.browser.pages import add_local_role, del_local_roles
    6264from waeup.sirp.permissions import get_users_with_local_roles, getRoles
     65from waeup.sirp.applicants.workflow import create_workflow, INITIALIZED, STARTED
    6366
    6467results_widget = CustomWidgetFactory(
     
    393396        if SUBMIT is None:
    394397            return
    395 
    396398        if self.request.principal.id == 'zope.anybody':
    397399            self.flash('Entered credentials are invalid.')
    398400            return
    399 
    400401        if not IApplicantPrincipal.providedBy(self.request.principal):
    401402            # Don't care if user is already authenticated as non-applicant
    402403            return
    403 
    404404        pin = self.request.principal.access_code
    405405        if pin not in self.context.keys():
     
    408408            applicant.access_code = pin
    409409            self.context[pin] = applicant
    410 
    411410        # Assign current principal the owner role on created applicant
    412411        # record
     
    414413        role_manager.assignRoleToPrincipal(
    415414            'waeup.local.ApplicationOwner', self.request.principal.id)
     415        state = IWorkflowState(self.context[pin]).getState()
     416        if state == INITIALIZED:
     417            IWorkflowInfo(self.context[pin]).fireTransition('start')
    416418        self.redirect(self.url(self.context[pin], 'edit'))
    417419        return
     
    464466        return 'not yet admitted'
    465467
     468    @property
     469    def getApplicationState(self):
     470        state = IWorkflowState(self.context).getState()
     471        return state
     472
    466473class ApplicantsManageActionButton(ManageActionButton):
    467474    grok.context(IApplicant)
     
    497504        return '%s Application Form' % container_title
    498505
     506    @property
     507    def getTransitions(self):
     508        allowed_transitions_ids = IWorkflowInfo(self.context).getManualTransitionIds()
     509        transition_objects = create_workflow()
     510        null_transition = [{'name': '', 'title':'No transition'}]
     511        transitions = null_transition + [dict(
     512            name=transition_object.transition_id,
     513            title=transition_object.title)
     514            for transition_object in transition_objects
     515            if transition_object.transition_id in allowed_transitions_ids]
     516        #import pdb; pdb.set_trace()
     517        return transitions
     518
     519    @property
     520    def getApplicationState(self):
     521        state = IWorkflowState(self.context).getState()
     522        return state
     523
    499524    @grok.action('Save')
    500525    def save(self, **data):
    501526        self.applyData(self.context, **data)
    502527        self.context._p_changed = True
     528        form = self.request.form
     529        if form.has_key('transition') and form['transition']:
     530            transition = form['transition']
     531            IWorkflowInfo(self.context).fireTransition(transition)
    503532        self.flash('Form has been saved.')
    504533        return
     
    535564        return False
    536565
     566    @property
     567    def getTransitions(self):
     568        return None
     569
    537570    @grok.action('Save')
    538571    def save(self, **data):
     
    555588            self.flash(self.dataNotComplete())
    556589            return
     590        state = IWorkflowState(self.context).getState()
     591        # Cannot happen but anyway ...
     592        if state != STARTED:
     593            self.flash('This form cannot be submitted.')
     594            return
     595        IWorkflowInfo(self.context).fireTransition('submit')
    557596        self.context.locked = True
    558597        self.flash('Form has been submitted.')
Note: See TracChangeset for help on using the changeset viewer.