Ignore:
Timestamp:
21 Sep 2012, 06:10:00 (12 years ago)
Author:
Henrik Bettermann
Message:

Add StudyCourseCOEditFormPage (see Uniben ticket 626).

Location:
main/waeup.uniben/trunk/src/waeup/uniben/students
Files:
2 edited

Legend:

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

    r9205 r9210  
    1818import grok
    1919from zope.i18n import translate
     20from zope.schema.interfaces import ConstraintNotSatisfied
     21from waeup.kofa.interfaces import REQUESTED
    2022from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
     23from waeup.kofa.browser import KofaEditFormPage
     24from waeup.kofa.browser.viewlets import ManageActionButton
     25from waeup.kofa.browser.layout import action
    2126from waeup.kofa.students.browser import (
    22     StudentClearPage, StudentRejectClearancePage)
     27    StudentClearPage, StudentRejectClearancePage,
     28    StudyCourseDisplayFormPage, msave, emit_lock_message)
    2329from kofacustom.nigeria.students.browser import (
    2430    NigeriaOnlinePaymentDisplayFormPage,
     
    2632    NigeriaExportPDFPaymentSlipPage)
    2733
    28 from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
     34from waeup.uniben.students.interfaces import (
     35    ICustomStudentOnlinePayment, ICustomStudentStudyCourse)
     36from waeup.uniben.interfaces import MessageFactory as _
    2937
    3038class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
     
    7078#        self.redirect(self.url(self.context,'view_clearance'))
    7179#        return
     80
     81class StudyCourseEditActionButton(ManageActionButton):
     82    grok.order(1)
     83    grok.context(ICustomStudentStudyCourse)
     84    grok.view(StudyCourseDisplayFormPage)
     85    grok.require('waeup.clearStudent')
     86    text = _('Edit level')
     87    target = 'edit_level'
     88
     89    @property
     90    def target_url(self):
     91        if self.context.is_current and self.context.student.state == REQUESTED:
     92            return self.view.url(self.view.context, self.target)
     93        return False
     94
     95class StudyCourseCOEditFormPage(KofaEditFormPage):
     96    """ Page to edit the student study course data by clearance officers
     97
     98    This form page is available only in Uniben.
     99    """
     100    grok.context(ICustomStudentStudyCourse)
     101    grok.name('edit_level')
     102    grok.require('waeup.clearStudent')
     103    label = _('Edit current level')
     104    pnav = 4
     105    form_fields = grok.AutoFields(
     106        ICustomStudentStudyCourse).select('current_level')
     107
     108    def update(self):
     109        if not (self.context.is_current and
     110            self.context.student.state == REQUESTED):
     111            emit_lock_message(self)
     112            return
     113        super(StudyCourseCOEditFormPage, self).update()
     114        return
     115
     116    @action(_('Save'), style='primary')
     117    def save(self, **data):
     118        try:
     119            msave(self, **data)
     120        except ConstraintNotSatisfied:
     121            # The selected level might not exist in certificate
     122            self.flash(_('Current level not available for certificate.'))
     123            return
     124        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
     125        return
  • main/waeup.uniben/trunk/src/waeup/uniben/students/tests/test_browser.py

    r9206 r9210  
    2020import tempfile
    2121from StringIO import StringIO
    22 from hurry.workflow.interfaces import IWorkflowState
     22from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
     23from zope.securitypolicy.interfaces import IPrincipalRoleManager
    2324from zope.component.hooks import setSite, clearSite
    2425from zope.component import getUtility, createObject
    2526from zope.interface import verify
     27from zope.event import notify
     28from waeup.kofa.authentication import LocalRoleSetEvent
    2629from waeup.kofa.app import University
    2730from waeup.kofa.students.tests.test_browser import StudentsFullSetup
     
    372375        self.assertEqual(error, None)
    373376        return
     377
     378    def test_edit_level_by_co(self):
     379        # Create clearance officer
     380        self.app['users'].addUser('mrclear', 'mrclearsecret')
     381        self.app['users']['mrclear'].email = 'mrclear@foo.ng'
     382        self.app['users']['mrclear'].title = 'Carlo Pitter'
     383        # Assign local ClearanceOfficer role
     384        department = self.app['faculties']['fac1']['dep1']
     385        prmlocal = IPrincipalRoleManager(department)
     386        prmlocal.assignRoleToPrincipal('waeup.local.ClearanceOfficer', 'mrclear')
     387        notify(LocalRoleSetEvent(
     388            department, 'waeup.local.ClearanceOfficer', 'mrclear', granted=True))
     389        IWorkflowState(self.student).setState('clearance started')
     390        # Login as clearance officer
     391        self.browser.open(self.login_path)
     392        self.browser.getControl(name="form.login").value = 'mrclear'
     393        self.browser.getControl(name="form.password").value = 'mrclearsecret'
     394        self.browser.getControl("Login").click()
     395        self.assertMatches('...You logged in...', self.browser.contents)
     396        # Only in state clearance requested the CO does see the
     397        # 'Edit level' button ...
     398        self.browser.open(self.studycourse_path)
     399        self.assertFalse('Edit level' in self.browser.contents)
     400        # ... and can open the edit_level view
     401        self.browser.open(self.studycourse_path + '/edit_level')
     402        self.assertMatches('...is locked...', self.browser.contents)
     403        self.assertEqual(self.browser.url, self.studycourse_path)
     404        IWorkflowInfo(self.student).fireTransition('request_clearance')
     405        self.browser.open(self.studycourse_path)
     406        self.assertTrue('Edit level' in self.browser.contents)
     407        self.browser.getLink("Edit level").click()
     408        self.browser.getControl(name="form.current_level").value = ['200']
     409        self.browser.getControl("Save").click()
     410        self.assertMatches('...has been saved...', self.browser.contents)
     411        self.assertEqual(self.student.current_level, 200)
Note: See TracChangeset for help on using the changeset viewer.