Changeset 12904 for main/waeup.kwarapoly


Ignore:
Timestamp:
5 May 2015, 12:17:58 (10 years ago)
Author:
Henrik Bettermann
Message:

Customize matric_number construction methods.

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

Legend:

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

    r9614 r12904  
    11# -*- coding: utf-8 -*-
     2from hurry.workflow.interfaces import IWorkflowState
     3from zope.component import getUtility
    24from waeup.kofa.testing import FunctionalTestCase
    3 from zope.component import getUtility
     5from waeup.kofa.university.faculty import Faculty
     6from waeup.kofa.university.department import Department
    47from waeup.kofa.students.interfaces import IStudentsUtils
    58from waeup.kofa.students.tests.test_browser import StudentsFullSetup
    69from waeup.kwarapoly.testing import FunctionalLayer
    710
    8 class BedAllocationTests(StudentsFullSetup):
     11class StudentsUtilsTests(StudentsFullSetup):
    912
    1013    layer = FunctionalLayer
     
    4346        self.assertEqual(acc_details['bt'], 'regular_male_fi')
    4447        return
     48
     49    def test_setMatricNumber(self):
     50        utils = getUtility(IStudentsUtils)
     51        self.student.matric_number = None
     52        msg, mnumber = utils.setMatricNumber(self.student)
     53        self.assertEqual(msg, 'Matriculation number cannot be set.')
     54        self.assertEqual(mnumber, None)
     55        self.student['studycourse'].entry_mode = 'nd_ft'
     56        self.student['studycourse'].entry_session = 2013
     57        msg, mnumber = utils.setMatricNumber(self.student)
     58        self.assertEqual(self.student.matric_number, 'ND/13/dep1/FT/001')
     59        self.assertEqual(
     60            self.app['faculties']['fac1']['dep1'].next_matric_dict,
     61            {2013: 2})
     62        # setting a new matric number in 2014, extends next_matric_dict
     63        self.student['studycourse'].entry_session = 2014
     64        self.student.matric_number = None
     65        msg, mnumber = utils.setMatricNumber(self.student)
     66        self.assertEqual(
     67            self.app['faculties']['fac1']['dep1'].next_matric_dict,
     68            {2013: 2, 2014: 2})
     69        # setting a new matric number in 2014 again, increases the counter
     70        self.student.matric_number = None
     71        msg, mnumber = utils.setMatricNumber(self.student)
     72        self.assertEqual(
     73            self.app['faculties']['fac1']['dep1'].next_matric_dict,
     74            {2013: 2, 2014: 3})
     75        # matric number must not exist
     76        msg, mnumber = utils.setMatricNumber(self.student)
     77        self.assertEqual(msg, 'Matriculation number already set.')
     78        # certificate must be set.
     79        self.student.matric_number = None
     80        self.student['studycourse'].certificate = None
     81        msg, mnumber = utils.setMatricNumber(self.student)
     82        self.assertEqual(msg, 'No certificate assigned.')
     83        return
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py

    r12148 r12904  
    319319        return d
    320320
     321    def increaseMatricInteger(self, student):
     322        """Increase counter for matric numbers.
     323        """
     324        cert = getattr(student.get('studycourse', None), 'certificate', None)
     325        entry_session = getattr(
     326            student.get('studycourse', None), 'entry_session', None)
     327        dep = cert.__parent__.__parent__
     328        next_matric_dict = getattr(dep, 'next_matric_dict', None)
     329        if not next_matric_dict:
     330            # add next_matric_dict attribute
     331            dep.next_matric_dict = {}
     332        if not dep.next_matric_dict.get(entry_session, None):
     333            # initialize counter element
     334            dep.next_matric_dict[entry_session] = 2
     335            return
     336        # increase counter value of entry_session
     337        dep.next_matric_dict[entry_session] += 1
     338        return
     339
     340    def constructMatricNumber(self, student):
     341        """Fetch the matric number counter which fits the student and
     342        construct the new matric number of the student.
     343
     344        A typical matriculation number is like this: ND/14/STA/FT/015
     345
     346        ND = Study Mode Prefix
     347        14 = Year of Entry
     348        STA = Department Code
     349        FT = Study Mode Suffix
     350        015 = Serial Number (Every department starts from "001" every
     351        session and the numbers build up arithmetically)
     352        """
     353        cert = getattr(student.get('studycourse', None), 'certificate', None)
     354        entry_session = getattr(
     355            student.get('studycourse', None), 'entry_session', None)
     356        entry_mode = getattr(
     357            student.get('studycourse', None), 'entry_mode', None)
     358        if None in (cert, entry_session, entry_mode):
     359            return _('Matriculation number cannot be set.'), None
     360        try:
     361            (prefix, suffix) = entry_mode.split('_')
     362            (prefix, suffix) = (prefix.upper(), suffix.upper())
     363        except ValueError:
     364            return _('Matriculation number cannot be set.'), None
     365        dep = cert.__parent__.__parent__
     366        next_integer = getattr(
     367            dep, 'next_matric_dict', {}).get(entry_session, 1)
     368        entry_year = entry_session - 100*(entry_session/100)
     369        matric_number = "%s/%s/%s/%s/%03d" % (
     370            prefix, entry_year, student.depcode, suffix, next_integer)
     371        return None, matric_number
     372
    321373    PWCHANGE_STATES = (ADMITTED, CLEARED, RETURNING)
    322374
Note: See TracChangeset for help on using the changeset viewer.