Ignore:
Timestamp:
2 Oct 2012, 16:50:57 (12 years ago)
Author:
Henrik Bettermann
Message:

Add special permission and view for triggering transitions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py

    r9257 r9273  
    407407        return
    408408
    409     def getTransitions(self):
    410         """Return a list of dicts of allowed transition ids and titles.
    411 
    412         Each list entry provides keys ``name`` and ``title`` for
    413         internal name and (human readable) title of a single
    414         transition.
    415         """
    416         allowed_transitions = [t for t in self.wf_info.getManualTransitions()
    417             if not t[0].startswith('pay')]
    418         if self.context.is_postgrad:
    419             allowed_transitions = [t for t in allowed_transitions
    420                 if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
    421         return [dict(name='', title=_('No transition'))] +[
    422             dict(name=x, title=y) for x, y in allowed_transitions]
    423 
    424409    @action(_('Save'), style='primary')
    425410    def save(self, **data):
     
    440425            changed_fields = []
    441426        if password:
    442             # Now we know that the form has no errors and can set password ...
     427            # Now we know that the form has no errors and can set password
    443428            IUserAccount(self.context).setPassword(password)
    444429            changed_fields.append('password')
    445         # ... and execute transition
    446         if form.has_key('transition') and form['transition']:
    447             transition_id = form['transition']
    448             self.wf_info.fireTransition(transition_id)
    449430        fields_string = ' + '.join(changed_fields)
    450431        self.flash(_('Form has been saved.'))
    451432        if fields_string:
    452433            self.context.writeLogMessage(self, 'saved: % s' % fields_string)
     434        return
     435
     436class StudentTriggerTransitionFormPage(KofaEditFormPage):
     437    """ View to manage student base data
     438    """
     439    grok.context(IStudent)
     440    grok.name('trigtrans')
     441    grok.require('waeup.triggerTransition')
     442    grok.template('trigtrans')
     443    label = _('Trigger registration transition')
     444    pnav = 4
     445
     446    def getTransitions(self):
     447        """Return a list of dicts of allowed transition ids and titles.
     448
     449        Each list entry provides keys ``name`` and ``title`` for
     450        internal name and (human readable) title of a single
     451        transition.
     452        """
     453        wf_info = IWorkflowInfo(self.context)
     454        allowed_transitions = [t for t in wf_info.getManualTransitions()
     455            if not t[0].startswith('pay')]
     456        if self.context.is_postgrad:
     457            allowed_transitions = [t for t in allowed_transitions
     458                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
     459        return [dict(name='', title=_('No transition'))] +[
     460            dict(name=x, title=y) for x, y in allowed_transitions]
     461
     462    @action(_('Save'), style='primary')
     463    def save(self, **data):
     464        form = self.request.form
     465        if form.has_key('transition') and form['transition']:
     466            transition_id = form['transition']
     467            wf_info = IWorkflowInfo(self.context)
     468            wf_info.fireTransition(transition_id)
    453469        return
    454470
Note: See TracChangeset for help on using the changeset viewer.