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

Add special permission and view for triggering transitions

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
1 added
5 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
  • main/waeup.kofa/trunk/src/waeup/kofa/students/browser_templates/basemanagepage.pt

    r8486 r9273  
    2727            </td>
    2828          </tr>
    29           <tr>
    30             <td class="fieldname" i18n:translate="">Registration Transition:</td>
    31             <td>
    32               <select id="transition" name="transition">
    33                 <option tal:repeat="transition view/getTransitions"
    34                         tal:attributes="value transition/name">
    35                   <span tal:replace="transition/title">TRANSITIONTITLE</span>
    36                 </option>
    37               </select>
    38             </td>
    39           </tr>
    4029
    4130        </tbody>
  • main/waeup.kofa/trunk/src/waeup/kofa/students/permissions.py

    r8367 r9273  
    5656    grok.name('waeup.validateStudent')
    5757
     58class TriggerTransition(grok.Permission):
     59    grok.name('waeup.triggerTransition')
     60
    5861# Local role
    5962class StudentRecordOwner(grok.Role):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9257 r9273  
    113113        self.student_path = self.container_path + '/' + self.student_id
    114114        self.manage_student_path = self.student_path + '/manage_base'
     115        self.trigtrans_path = self.student_path + '/trigtrans'
    115116        self.clearance_path = self.student_path + '/view_clearance'
    116117        self.personal_path = self.student_path + '/view_personal'
     
    435436        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    436437        self.assertEqual(self.browser.url, self.student_path)
     438        self.browser.getLink("Trigger").click()
     439        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     440        # Managers can trigger transitions
     441        self.browser.getControl(name="transition").value = ['admit']
     442        self.browser.getControl("Save").click()
     443        # Managers can edit base
     444        self.browser.open(self.student_path)
    437445        self.browser.getLink("Manage").click()
    438         self.assertEqual(self.browser.headers['Status'], '200 Ok')
    439446        self.assertEqual(self.browser.url, self.manage_student_path)
    440         # Managers can edit base data and fire transitions
    441         self.browser.getControl(name="transition").value = ['admit']
     447        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    442448        self.browser.getControl(name="form.firstname").value = 'John'
    443449        self.browser.getControl(name="form.lastname").value = 'Tester'
     
    720726        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    721727        student = self.app['students'][self.student_id]
    722         self.browser.open(self.manage_student_path)
     728        self.browser.open(self.trigtrans_path)
    723729        self.assertTrue(student.clearance_locked)
    724730        self.browser.getControl(name="transition").value = ['admit']
     
    761767        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
    762768        student = self.app['students'][self.student_id]
    763         self.browser.open(self.manage_student_path)
     769        self.browser.open(self.trigtrans_path)
    764770        self.assertTrue('<option value="reset6">' in self.browser.contents)
    765771        self.assertTrue('<option value="register_courses">' in self.browser.contents)
    766772        self.assertTrue('<option value="reset5">' in self.browser.contents)
    767773        self.certificate.study_mode = 'pg_ft'
    768         self.browser.open(self.manage_student_path)
     774        self.browser.open(self.trigtrans_path)
    769775        self.assertFalse('<option value="reset6">' in self.browser.contents)
    770776        self.assertFalse('<option value="register_courses">' in self.browser.contents)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/viewlets.py

    r9257 r9273  
    166166    target = 'manage_base'
    167167
     168class StudentTrigTransActionButton(ManageActionButton):
     169    grok.order(2)
     170    grok.context(IStudent)
     171    grok.view(StudentBaseDisplayFormPage)
     172    grok.require('waeup.triggerTransition')
     173    icon = 'actionicon_trigtrans.png'
     174    text = _(u'Trigger transition')
     175    target = 'trigtrans'
     176
    168177class AdmissionSlipActionButton(ManageActionButton):
    169178    grok.order(4)
Note: See TracChangeset for help on using the changeset viewer.