Ignore:
Timestamp:
31 Oct 2012, 16:01:42 (12 years ago)
Author:
Henrik Bettermann
Message:

Add clearance_comment attribute. When CO rejects clearance she is requested to enter a comment. This comment is stored with the student object and logged. The contact form is pre-filled with the comment. When a student is cleared the comment will be automatically removed.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
5 edited

Legend:

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

    r9467 r9484  
    390390    form_fields = grok.AutoFields(IContactForm).select('subject', 'body')
    391391
    392     def update(self, subject=u''):
     392    def update(self, subject=u'', body=u''):
    393393        self.form_fields.get('subject').field.default = subject
     394        self.form_fields.get('body').field.default = body
    394395        self.subject = subject
    395396        return
     
    586587            form_fields = grok.AutoFields(
    587588                IUGStudentClearance).omit('clearance_locked')
     589        if not getattr(self.context, 'clearance_comment'):
     590            form_fields = form_fields.omit('clearance_comment')
     591        else:
     592            form_fields['clearance_comment'].custom_widget = BytesDisplayWidget
    588593        return form_fields
    589594
     
    610615            form_fields = grok.AutoFields(
    611616                IUGStudentClearance).omit('clearance_locked')
     617        if not getattr(self.context, 'clearance_comment'):
     618            form_fields = form_fields.omit('clearance_comment')
    612619        return form_fields
    613620
     
    694701        return
    695702
    696 class StudentRejectClearancePage(UtilityView, grok.View):
     703class StudentRejectClearancePage(KofaEditFormPage):
    697704    """ Reject clearance by clearance officers
    698705    """
    699706    grok.context(IStudent)
    700707    grok.name('reject_clearance')
     708    label = _('Reject clearance')
    701709    grok.require('waeup.clearStudent')
    702 
    703     def update(self):
     710    form_fields = grok.AutoFields(
     711        IUGStudentClearance).select('clearance_comment')
     712
     713    @action(_('Save comment and reject clearance now'), style='primary')
     714    def reject(self, **data):
    704715        if self.context.state == CLEARED:
    705716            IWorkflowInfo(self.context).fireTransition('reset4')
     
    714725            self.redirect(self.url(self.context,'view_clearance'))
    715726            return
    716         args = {'subject':message}
     727        self.applyData(self.context, **data)
     728        comment = data['clearance_comment']
     729        self.context.writeLogMessage(
     730            self, 'comment: %s' % comment.replace('\n', '<br>'))
     731        args = {'subject':message, 'body':comment}
    717732        self.redirect(self.url(self.context) +
    718733            '/contactstudent?%s' % urlencode(args))
    719734        return
    720735
    721     def render(self):
    722         return
     736    #def render(self):
     737    #    return
    723738
    724739class StudentPersonalDisplayFormPage(KofaDisplayFormPage):
     
    19381953        if self.context.is_postgrad:
    19391954            form_fields = grok.AutoFields(IPGStudentClearance).omit(
    1940                 'clearance_locked', 'clr_code')
     1955                'clearance_locked', 'clr_code', 'clearance_comment')
    19411956        else:
    19421957            form_fields = grok.AutoFields(IUGStudentClearance).omit(
    1943                 'clearance_locked', 'clr_code')
     1958                'clearance_locked', 'clr_code', 'clearance_comment')
    19441959        return form_fields
    19451960
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r9437 r9484  
    274274        )
    275275
     276    clearance_comment = schema.Text(
     277        title = _(u"Officer's Comment"),
     278        required = False,
     279        #description = _(
     280        #    u'This comment will be deleted when student is cleared.'),
     281        )
     282
    276283class IPGStudentClearance(IUGStudentClearance):
    277284    """Representation of postgraduate student clearance data.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r9452 r9484  
    12091209        self.browser.open(self.clearance_path)
    12101210        self.browser.getLink("Reject clearance").click()
     1211        self.assertEqual(
     1212            self.browser.url, self.student_path + '/reject_clearance')
     1213        # Type comment why
     1214        self.browser.getControl(name="form.clearance_comment").value = """Dear Student,
     1215You did not fill properly.
     1216"""
     1217        self.browser.getControl("Save comment").click()
    12111218        self.assertTrue('Clearance has been annulled' in self.browser.contents)
    1212         urlmessage = 'Clearance+has+been+annulled.'
    1213         # CO does now see the contact form
    1214         self.assertEqual(self.browser.url, self.student_path +
    1215             '/contactstudent?subject=%s' % urlmessage)
     1219        url = ('http://localhost/app/students/K1000000/'
     1220              'contactstudent?body=Dear+Student%2C%0AYou+did+not+fill+properly.'
     1221              '%0A&subject=Clearance+has+been+annulled.')
     1222        # CO does now see the prefilled contact form and can send a message
     1223        self.assertEqual(self.browser.url, url)
    12161224        self.assertTrue('clearance started' in self.browser.contents)
     1225        self.assertTrue('name="form.subject" size="20" type="text" '
     1226            'value="Clearance has been annulled."'
     1227            in self.browser.contents)
     1228        self.assertTrue('name="form.body" rows="10" >Dear Student,'
     1229            in self.browser.contents)
     1230        self.browser.getControl("Send message now").click()
     1231        self.assertTrue('Your message has been sent' in self.browser.contents)
     1232        # The comment has been stored ...
     1233        self.assertEqual(self.student.clearance_comment,
     1234            u'Dear Student,\nYou did not fill properly.\n')
     1235        # ... and logged
     1236        logfile = os.path.join(
     1237            self.app['datacenter'].storage, 'logs', 'students.log')
     1238        logcontent = open(logfile).read()
     1239        self.assertTrue(
     1240            'INFO - mrclear - students.browser.StudentRejectClearancePage - '
     1241            'K1000000 - comment: Dear Student,<br>You did not fill '
     1242            'properly.<br>\n' in logcontent)
    12171243        self.browser.open(self.history_path)
    12181244        self.assertTrue("Reset to 'clearance started' by My Public Name" in
     
    12211247        self.browser.open(self.clearance_path)
    12221248        self.browser.getLink("Reject clearance").click()
     1249        self.browser.getControl("Save comment").click()
    12231250        self.assertTrue('Clearance request has been rejected'
    12241251            in self.browser.contents)
    12251252        self.assertTrue('clearance started' in self.browser.contents)
    1226         # CO does now also see the contact form and can send a message
    1227         self.browser.getControl(name="form.subject").value = 'Important subject'
    1228         self.browser.getControl(name="form.body").value = 'Clearance rejected'
    1229         self.browser.getControl("Send message now").click()
    1230         self.assertTrue('Your message has been sent' in self.browser.contents)
    12311253        # The CO can't clear students if not in state
    12321254        # clearance requested
     
    12401262        self.browser.getLink("Show students").click()
    12411263        self.assertTrue(self.student_id in self.browser.contents)
     1264
     1265
     1266        # When a student is cleared the comment is automatically deleted
     1267        IWorkflowInfo(self.student).fireTransition('request_clearance')
     1268        IWorkflowInfo(self.student).fireTransition('clear')
     1269        self.assertEqual(self.student.clearance_comment, None)
     1270
    12421271
    12431272    def test_handle_courses_by_ca(self):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9427 r9484  
    4343        result = open(self.outfile, 'rb').read()
    4444        self.assertTrue(
    45             'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
     45            'adm_code,clearance_comment,clearance_locked,clr_code,'
     46            'date_of_birth,email,employer,'
    4647            'firstname,lastname,matric_number,middlename,nationality,'
    4748            'perm_address,phone,reg_number,sex,student_id,suspended,password,'
    4849            'state,history,certcode,is_postgrad,current_level,current_session\r\n'
    4950
    50             'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
     51            'my adm code,,0,my clr code,1981-02-04#,anna@sample.com,,'
    5152            'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",'
    5253            '+234-123-12345#,123,f,A111111,0,,created'
     
    6364        result = open(self.outfile, 'rb').read()
    6465        self.assertTrue(
    65             'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
     66            'adm_code,clearance_comment,clearance_locked,clr_code,'
     67            'date_of_birth,email,employer,'
    6668            'firstname,lastname,matric_number,middlename,nationality,'
    6769            'perm_address,phone,reg_number,sex,student_id,suspended,password,'
    6870            'state,history,certcode,is_postgrad,current_level,current_session\r\n'
    6971
    70             'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
     72            'my adm code,,0,my clr code,1981-02-04#,anna@sample.com,,'
    7173            'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",'
    7274            '+234-123-12345#,123,f,A111111,0,,created'
     
    8284        result = open(self.outfile, 'rb').read()
    8385        self.assertTrue(
    84             'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
     86            'adm_code,clearance_comment,clearance_locked,clr_code,'
     87            'date_of_birth,email,employer,'
    8588            'firstname,lastname,matric_number,middlename,nationality,'
    8689            'perm_address,phone,reg_number,sex,student_id,suspended,password,'
    8790            'state,history,certcode,is_postgrad,current_level,current_session\r\n'
    8891
    89             'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,'
     92            'my adm code,,0,my clr code,1981-02-04#,anna@sample.com,,'
    9093            'Anna,Tester,234,M.,NG,"Studentroad 21\nLagos 123456\n",'
    9194            '+234-123-12345#,123,f,A111111,0,,created'
  • main/waeup.kofa/trunk/src/waeup/kofa/students/workflow.py

    r9295 r9484  
    256256            level_object.validated_by = usertitle
    257257            level_object.validation_date = datetime.utcnow()
     258    elif event.transition.transition_id == 'clear':
     259        obj.clearance_comment = None
    258260    elif event.transition.transition_id == 'reset8':
    259261        current_level = obj['studycourse'].current_level
Note: See TracChangeset for help on using the changeset viewer.