Changeset 6638 for main/waeup.sirp/trunk


Ignore:
Timestamp:
27 Aug 2011, 14:14:47 (13 years ago)
Author:
Henrik Bettermann
Message:

Add studentbasemanagepage which allows performing transitions. Add tests.

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

Legend:

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

    r6637 r6638  
    322322    grok.require('waeup.manageStudents')
    323323    form_fields = grok.AutoFields(IStudentBase).omit('student_id')
    324     #grok.template('editstudentbase')
     324    grok.template('studentbasemanagepage')
    325325    label = 'Edit base data'
    326326
    327     @property
    328     def title(self):
    329         return 'Student: %s' % self.context.name
     327    def update(self):
     328        datepicker.need() # Enable jQuery datepicker in date fields.
     329        super(StudentBaseManageFormPage, self).update()
     330        self.wf_info = IWorkflowInfo(self.context)
     331        return
     332
     333    @property
     334    def title(self):
     335        return 'Student: %s' % self.context.name
     336
     337    def getTransitions(self):
     338        """Return a list of dicts of allowed transition ids and titles.
     339
     340        Each list entry provides keys ``name`` and ``title`` for
     341        internal name and (human readable) title of a single
     342        transition.
     343        """
     344        allowed_transitions = self.wf_info.getManualTransitions()
     345        return [dict(name='', title='No transition')] +[
     346            dict(name=x, title=y) for x, y in allowed_transitions]
     347
     348    @grok.action('Save')
     349    def save(self, **data):
     350        changed_fields = self.applyData(self.context, **data)
     351        changed_fields = changed_fields.values()
     352        fields_string = '+'.join(' + '.join(str(i) for i in b) for b in changed_fields)
     353        self.context._p_changed = True
     354        form = self.request.form
     355        if form.has_key('transition') and form['transition']:
     356            transition_id = form['transition']
     357            self.wf_info.fireTransition(transition_id)
     358        self.flash('Form has been saved.')
     359        ob_class = self.__implemented__.__name__.replace('waeup.sirp.','')
     360        self.context.loggerInfo(ob_class, 'saved: % s' % fields_string)
     361        return
    330362
    331363class StudentClearanceDisplayFormPage(WAeUPDisplayFormPage):
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_browser.py

    r6637 r6638  
    200200        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    201201        self.assertEqual(self.browser.url, self.manage_student_path)
     202        # Managers can fire transitions
     203        self.browser.getControl(name="transition").value = ['admit']
     204        self.browser.getControl("Save").click()
     205        self.assertTrue('Form has been saved' in self.browser.contents)
    202206
    203207        self.browser.open(self.student_path)
     
    236240        self.assertEqual(self.browser.headers['Status'], '200 Ok')
    237241        self.assertEqual(self.browser.url, self.history_student_path)
    238         self.assertMatches('...Student object created by system...', self.browser.contents)
     242        self.assertMatches('...Student admitted by system...', self.browser.contents)
    239243
    240244        return
  • main/waeup.sirp/trunk/src/waeup/sirp/students/workflow.py

    r6637 r6638  
    1818        source = None,
    1919        condition = NullCondition,
    20         msg = 'Student object created',
     20        msg = 'Student record created',
    2121        destination = CREATED),
    2222
     
    3131        transition_id = 'reset1',
    3232        title = 'Reset student',
    33         msg = 'Student reset',
     33        msg = 'Student record reset',
    3434        source = ADMITTED,
    3535        destination = CREATED),
Note: See TracChangeset for help on using the changeset viewer.