Ignore:
Timestamp:
6 May 2015, 10:13:38 (10 years ago)
Author:
Henrik Bettermann
Message:

Implement automatic matric_number assignment. Students can induce the
assignment if they have paid school fees by clicking the
'Get Matriculation Number' button. Numbering is per department and session.

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

Legend:

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

    r12877 r12907  
    5050
    5151from waeup.kwarapoly.students.interfaces import (
     52    ICustomStudent,
    5253    ICustomStudentOnlinePayment,
    5354    ICustomStudentPersonal,
     
    509510#
    510511# Burn this remark after reading.
     512
     513
     514class StudentGetMatricNumberPage(UtilityView, grok.View):
     515    """ Construct and set the matriculation number.
     516    """
     517    grok.context(ICustomStudent)
     518    grok.name('get_matric_number')
     519    grok.require('waeup.viewStudent')
     520
     521    def update(self):
     522        students_utils = getUtility(IStudentsUtils)
     523        msg, mnumber = students_utils.setMatricNumber(self.context)
     524        if msg:
     525            self.flash(msg, type="danger")
     526        else:
     527            self.flash(_('Matriculation number %s assigned.' % mnumber))
     528            self.context.writeLogMessage(self, '%s assigned' % mnumber)
     529        self.redirect(self.url(self.context))
     530        return
     531
     532    def render(self):
     533        return
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_browser.py

    r12148 r12907  
    528528        self.assertEqual(self.student.state, 'courses registered')
    529529        return
     530
     531    def test_set_matric_number(self):
     532        # Login as student
     533        self.browser.open(self.login_path)
     534        IWorkflowState(self.student).setState('school fee paid')
     535        self.browser.open(self.login_path)
     536        self.browser.getControl(name="form.login").value = self.student_id
     537        self.browser.getControl(name="form.password").value = 'spwd'
     538        self.browser.getControl("Login").click()
     539        self.assertRaises(
     540            LinkNotFoundError,
     541            self.browser.getLink, 'Get Matriculation Number')
     542        self.student.matric_number = None
     543        self.student['studycourse'].entry_mode = 'nd_ft'
     544        self.student['studycourse'].entry_session = 2014
     545        self.browser.open(self.student_path)
     546        self.browser.getLink("Get Matriculation Number").click()
     547        self.assertTrue('Matriculation number ND/14/dep1/FT/001 assigned.'
     548            in self.browser.contents)
     549        self.assertEqual(self.student.matric_number, 'ND/14/dep1/FT/001')
     550        self.assertRaises(
     551            LinkNotFoundError,
     552            self.browser.getLink, 'Get Matriculation Number')
     553        # Setting matric number is logged.
     554        logfile = os.path.join(
     555            self.app['datacenter'].storage, 'logs', 'students.log')
     556        logcontent = open(logfile).read()
     557        self.assertTrue('W1000000 - waeup.kwarapoly.students.browser.StudentGetMatricNumberPage - '
     558                        'W1000000 - ND/14/dep1/FT/001 assigned' in logcontent)
     559        return
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_utils.py

    r12904 r12907  
    5151        self.student.matric_number = None
    5252        msg, mnumber = utils.setMatricNumber(self.student)
     53        self.assertEqual(msg, 'Wrong state.')
     54        IWorkflowState(self.student).setState('school fee paid')
     55        msg, mnumber = utils.setMatricNumber(self.student)
    5356        self.assertEqual(msg, 'Matriculation number cannot be set.')
    5457        self.assertEqual(mnumber, None)
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py

    r12904 r12907  
    2424from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
    2525from waeup.kofa.accesscodes import create_accesscode
    26 from waeup.kofa.interfaces import CLEARED, RETURNING, ADMITTED, IKofaUtils
     26from waeup.kofa.interfaces import (
     27    CLEARED, RETURNING, ADMITTED, PAID, IKofaUtils)
    2728from waeup.kofa.fees import FeeTable
    2829from waeup.kofa.hostels.hostel import NOT_OCCUPIED
     
    356357        entry_mode = getattr(
    357358            student.get('studycourse', None), 'entry_mode', None)
     359        if student.state not in (PAID, ):
     360            return _('Wrong state.'), None
    358361        if None in (cert, entry_session, entry_mode):
    359362            return _('Matriculation number cannot be set.'), None
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/viewlets.py

    r11931 r12907  
    1818
    1919import grok
     20from zope.component import getUtility
    2021from waeup.kofa.students.viewlets import (
    2122    AddPreviousPaymentActionButton, AddBalancePaymentActionButton,
    2223    ManageActionButton)
    23 from waeup.kofa.students.interfaces import IStudent
     24from waeup.kofa.students.interfaces import IStudent, IStudentsUtils
    2425from waeup.kofa.students.browser import StudentBaseDisplayFormPage
    2526from waeup.kofa.students.workflow import (
     
    8687            return ''
    8788        return self.view.url(self.view.context, self.target)
     89
     90
     91class GetMatricNumberActionButton(ManageActionButton):
     92    grok.order(10)
     93    grok.context(IStudent)
     94    grok.view(StudentBaseDisplayFormPage)
     95    grok.require('waeup.viewStudent')
     96    icon = 'actionicon_count.png'
     97    text = _('Get Matriculation Number')
     98
     99    @property
     100    def target_url(self):
     101        students_utils = getUtility(IStudentsUtils)
     102        if self.context.matric_number:
     103            return ''
     104        error, matric_number = students_utils.constructMatricNumber(
     105            self.context)
     106        if error:
     107            return ''
     108        return self.view.url(self.view.context, 'get_matric_number')
Note: See TracChangeset for help on using the changeset viewer.