Changeset 13535 for main/waeup.kwarapoly
- Timestamp:
- 7 Dec 2015, 11:44:46 (9 years ago)
- 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 547 547 self.browser.open(self.student_path) 548 548 self.browser.getLink("Get Matriculation Number").click() 549 self.assertTrue('Matriculation number ND/15/dep1/FT/0 10assigned.'549 self.assertTrue('Matriculation number ND/15/dep1/FT/001 assigned.' 550 550 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') 554 552 self.assertRaises( 555 553 LinkNotFoundError, … … 560 558 logcontent = open(logfile).read() 561 559 self.assertTrue('W1000000 - waeup.kwarapoly.students.browser.StudentGetMatricNumberView - ' 562 'W1000000 - ND/15/dep1/FT/0 10assigned' in logcontent)560 'W1000000 - ND/15/dep1/FT/001 assigned' in logcontent) 563 561 return 564 562 -
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/tests/test_utils.py
r13390 r13535 5 5 from waeup.kofa.university.faculty import Faculty 6 6 from waeup.kofa.university.department import Department 7 from waeup.kofa.students.student import Student 7 8 from waeup.kofa.students.interfaces import IStudentsUtils 8 9 from waeup.kofa.students.tests.test_browser import StudentsFullSetup … … 48 49 49 50 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') 50 61 utils = getUtility(IStudentsUtils) 51 62 self.student.matric_number = None … … 59 70 IWorkflowState(self.student).setState('school fee paid') 60 71 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') 79 73 msg, mnumber = utils.setMatricNumber(self.student) 80 74 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. 82 83 self.student.matric_number = None 83 84 self.student['studycourse'].certificate = None -
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/students/utils.py
r13507 r13535 19 19 import random 20 20 from time import time 21 from zope.component import createObject, getUtility 21 from zope.component import createObject, getUtility, queryUtility 22 22 from zope.catalog.interfaces import ICatalog 23 23 from waeup.kofa.interfaces import CLEARED, RETURNING, PAID … … 313 313 314 314 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 """ 333 317 return 334 318 … … 343 327 STA = Department Code 344 328 FT = Study Mode Suffix 345 015 = Serial Number (Every departmentstarts from "001" every329 015 = Serial Number (Every programme starts from "001" every 346 330 session and the numbers build up arithmetically) 347 331 """ 332 333 return _('Matriculation assgnment deactivated.'), None 334 348 335 cert = getattr(student.get('studycourse', None), 'certificate', None) 349 336 entry_session = getattr( … … 362 349 except ValueError: 363 350 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 while370 if next_integer == 2:371 next_integer == 10372 dep.next_matric_dict[entry_session] = 10373 dep._p_changed = True374 #############################################375 376 351 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) 379 365 return None, matric_number 380 366
Note: See TracChangeset for help on using the changeset viewer.