Changeset 13535 for main


Ignore:
Timestamp:
7 Dec 2015, 11:44:46 (9 years ago)
Author:
Henrik Bettermann
Message:

Implement new matric number construction method.

Temporarily deactivate the method.

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

Legend:

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

    r13461 r13535  
    547547        self.browser.open(self.student_path)
    548548        self.browser.getLink("Get Matriculation Number").click()
    549         self.assertTrue('Matriculation number ND/15/dep1/FT/010 assigned.'
     549        self.assertTrue('Matriculation number ND/15/dep1/FT/001 assigned.'
    550550            in self.browser.contents)
    551         self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/010')
    552         self.assertEqual(self.app['faculties']['fac1']['dep1'].next_matric_dict,
    553                          {2015: 11})
     551        self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/001')
    554552        self.assertRaises(
    555553            LinkNotFoundError,
     
    560558        logcontent = open(logfile).read()
    561559        self.assertTrue('W1000000 - waeup.kwarapoly.students.browser.StudentGetMatricNumberView - '
    562                         'W1000000 - ND/15/dep1/FT/010 assigned' in logcontent)
     560                        'W1000000 - ND/15/dep1/FT/001 assigned' in logcontent)
    563561        return
    564562
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_utils.py

    r13390 r13535  
    55from waeup.kofa.university.faculty import Faculty
    66from waeup.kofa.university.department import Department
     7from waeup.kofa.students.student import Student
    78from waeup.kofa.students.interfaces import IStudentsUtils
    89from waeup.kofa.students.tests.test_browser import StudentsFullSetup
     
    4849
    4950    def test_setMatricNumber(self):
     51        # Add second student
     52        secondstudent = Student()
     53        secondstudent.firstname = u'second'
     54        secondstudent.lastname = u'Student'
     55        self.app['students'].addStudent(secondstudent)
     56        student_id = secondstudent.student_id
     57        secondstudent['studycourse'].certificate = self.certificate
     58        secondstudent['studycourse'].entry_session = 2015
     59        secondstudent['studycourse'].entry_mode = 'nd_ft'
     60        IWorkflowState(secondstudent).setState('school fee paid')
    5061        utils = getUtility(IStudentsUtils)
    5162        self.student.matric_number = None
     
    5970        IWorkflowState(self.student).setState('school fee paid')
    6071        msg, mnumber = utils.setMatricNumber(self.student)
    61         self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/010')
    62         self.assertEqual(
    63             self.app['faculties']['fac1']['dep1'].next_matric_dict,
    64             {2015: 11})
    65         # setting a new matric number in 2016, extends next_matric_dict
    66         self.student['studycourse'].entry_session = 2016
    67         self.student.matric_number = None
    68         msg, mnumber = utils.setMatricNumber(self.student)
    69         self.assertEqual(
    70             self.app['faculties']['fac1']['dep1'].next_matric_dict,
    71             {2015: 11, 2016: 11})
    72         # setting a new matric number in 2014 again, increases the counter
    73         self.student.matric_number = None
    74         msg, mnumber = utils.setMatricNumber(self.student)
    75         self.assertEqual(
    76             self.app['faculties']['fac1']['dep1'].next_matric_dict,
    77             {2015: 11, 2016: 12})
    78         # matric number must not exist
     72        self.assertEqual(self.student.matric_number, 'ND/15/dep1/FT/001')
    7973        msg, mnumber = utils.setMatricNumber(self.student)
    8074        self.assertEqual(msg, 'Matriculation number already set.')
    81         # certificate must be set.
     75        # Second student gets nex matric number
     76        msg, mnumber = utils.setMatricNumber(secondstudent)
     77        self.assertEqual(secondstudent.matric_number, 'ND/15/dep1/FT/002')
     78        self.student.matric_number = u'ND/15/dep1/FT/011'
     79        secondstudent.matric_number = None
     80        msg, mnumber = utils.setMatricNumber(secondstudent)
     81        self.assertEqual(secondstudent.matric_number, 'ND/15/dep1/FT/012')
     82        # Certificate must be set.
    8283        self.student.matric_number = None
    8384        self.student['studycourse'].certificate = None
  • main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py

    r13507 r13535  
    1919import random
    2020from time import time
    21 from zope.component import createObject, getUtility
     21from zope.component import createObject, getUtility, queryUtility
    2222from zope.catalog.interfaces import ICatalog
    2323from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
     
    313313
    314314    def increaseMatricInteger(self, student):
    315         """Increase counter for matric numbers.
    316         """
    317         cert = getattr(student.get('studycourse', None), 'certificate', None)
    318         entry_session = getattr(
    319             student.get('studycourse', None), 'entry_session', None)
    320         dep = cert.__parent__.__parent__
    321         next_matric_dict = getattr(dep, 'next_matric_dict', None)
    322         if not next_matric_dict:
    323             # add next_matric_dict attribute
    324             dep.next_matric_dict = {}
    325         if not dep.next_matric_dict.get(entry_session, None):
    326             # initialize counter element with 11
    327             dep.next_matric_dict[entry_session] = 11
    328             dep._p_changed = True
    329             return
    330         # increase counter value of entry_session
    331         dep.next_matric_dict[entry_session] += 1
    332         dep._p_changed = True
     315        """We don't use a persistent counter in Kwarapoly.
     316        """
    333317        return
    334318
     
    343327        STA = Department Code
    344328        FT = Study Mode Suffix
    345         015 = Serial Number (Every department starts from "001" every
     329        015 = Serial Number (Every programme starts from "001" every
    346330        session and the numbers build up arithmetically)
    347331        """
     332
     333        return _('Matriculation assgnment deactivated.'), None
     334
    348335        cert = getattr(student.get('studycourse', None), 'certificate', None)
    349336        entry_session = getattr(
     
    362349        except ValueError:
    363350            return _('Matriculation number cannot be set.'), None
    364         dep = cert.__parent__.__parent__
    365         next_integer = getattr(
    366             dep, 'next_matric_dict', {}).get(entry_session, 10)
    367 
    368         #############################################
    369         # self-repair, can be removed after a while
    370         if next_integer == 2:
    371             next_integer == 10
    372             dep.next_matric_dict[entry_session] = 10
    373             dep._p_changed = True
    374         #############################################
    375 
    376351        entry_year = entry_session - 100*(entry_session/100)
    377         matric_number = "%s/%s/%s/%s/%03d" % (
    378             prefix, entry_year, student.depcode, suffix, next_integer)
     352        part1 =  "%s/%s/%s/%s/" % (
     353            prefix, entry_year, student.depcode, suffix)
     354        cat = queryUtility(ICatalog, name='students_catalog')
     355        results = cat.searchResults(matric_number=(part1+'0000', part1+'9999'))
     356        if not len(results):
     357            return None, part1 + '001'
     358        try:
     359            numbers = [int(i.matric_number.replace(part1, ''))
     360                       for i in results if i.matric_number]
     361        except ValueError:
     362            return _('Matriculation number cannot be determined.'), None
     363        counter = max(numbers) + 1
     364        matric_number = "%s%03d" % (part1, counter)
    379365        return None, matric_number
    380366
Note: See TracChangeset for help on using the changeset viewer.