Changeset 11589
- Timestamp:
- 22 Apr 2014, 07:13:16 (11 years ago)
- Location:
- main/waeup.kofa/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/CHANGES.txt
r11585 r11589 4 4 1.2dev (unreleased) 5 5 =================== 6 7 * Add setMatricNumber method to StudentsUtils. 6 8 7 9 * When sending mails, always set from-address to 'no-reply@waeup.org'. -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r11451 r11589 668 668 ) 669 669 670 next_matric_integer = schema.Int( 671 title = _(u'Next Matriculation Number Integer'), 672 description = _(u'Integer used for constructing the next ' 673 'matriculation number'), 674 default = 0, 675 readonly = False, 676 required = False, 677 ) 678 670 679 class ISessionConfiguration(IKofaObject): 671 680 """A session configuration object. -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r11450 r11589 89 89 """ 90 90 91 def setMatricNumber(student): 92 """Set matriculation number of student. 93 94 If the student's matric number is unset a new matric number is 95 constructed using the next_matric_integer attribute of 96 the site configuration container and according to the 97 matriculation number construction rules defined in the 98 _constructMatricNumber method. The new matric number is set, 99 the students catalog updated and next_matric_integer 100 increased by one. 101 102 This method is tested but not used in the base package. It can 103 be used in custom packages by adding respective views 104 and by customizing _composeMatricNumber according to the 105 university's matriculation number construction rules. 106 107 The method can be disabled by setting next_matric_integer to zero. 108 """ 109 91 110 def getAccommodation_details(student): 92 111 """Determine the accommodation dates of a student. -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_utils.py
r11588 r11589 1 1 # -*- coding: utf-8 -*- 2 2 import unittest 3 from zope.component import getUtility 3 import grok 4 from zope.component import getUtility, queryUtility, createObject 5 from zope.catalog.interfaces import ICatalog 4 6 from waeup.kofa.students.interfaces import IStudentsUtils 5 7 from waeup.kofa.students.utils import formatted_text … … 37 39 # In this case current_level remains unchanged and no error is raised. 38 40 self.assertEqual(self.student['studycourse'].current_level, 600) 41 42 def test_setMatricNumber(self): 43 site = grok.getSite() 44 utils = getUtility(IStudentsUtils) 45 msg, mnumber = utils.setMatricNumber(self.student) 46 self.assertEqual(msg, 'Matriculation number cannot be set.') 47 self.assertEqual(mnumber, None) 48 site['configuration'].next_matric_integer = 1 49 msg, mnumber = utils.setMatricNumber(self.student) 50 self.assertEqual(msg, 'Matriculation number already set.') 51 self.assertEqual(mnumber, None) 52 self.assertEqual(self.student.matric_number, '234') 53 self.student.matric_number = None 54 msg, mnumber = utils.setMatricNumber(self.student) 55 self.assertEqual(msg, None) 56 self.assertEqual(mnumber, 1) 57 self.assertEqual(self.student.matric_number, '1') 58 self.assertEqual(site['configuration'].next_matric_integer, 2) 59 # Student can be found in catalog. 60 cat = queryUtility(ICatalog, name='students_catalog') 61 results = list(cat.searchResults(matric_number=('1', '1'))) 62 self.assertEqual(self.student,results[0]) 63 # Add another student. 64 another_student = createObject('waeup.Student') 65 another_student.matric_number = u'2' 66 self.app['students'].addStudent(another_student) 67 # Matric number can't be assigned twice. 68 self.student.matric_number = None 69 msg, mnumber = utils.setMatricNumber(self.student) 70 self.assertEqual(msg, 'Matriculation number exists.') 71 self.assertEqual(mnumber, None) 72 self.assertEqual(self.student.matric_number, None) 73 return 74 -
main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py
r11550 r11589 25 25 from reportlab.lib.styles import getSampleStyleSheet 26 26 from reportlab.platypus import Paragraph, Image, Table, Spacer 27 from zope.event import notify 27 28 from zope.schema.interfaces import ConstraintNotSatisfied 28 29 from zope.component import getUtility, createObject … … 35 36 from waeup.kofa.students.interfaces import IStudentsUtils 36 37 from waeup.kofa.students.workflow import ADMITTED 37 from waeup.kofa.students.vocabularies import StudyLevelSource 38 from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource 38 39 from waeup.kofa.browser.pdf import ( 39 40 ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, … … 515 516 return None, payment 516 517 518 def _constructMatricNumber(self, student, next_integer): 519 return unicode(next_integer) 520 521 def setMatricNumber(self, student): 522 """Set matriculation number of student. 523 524 If the student's matric number is unset a new matric number is 525 constructed using the next_matric_integer attribute of 526 the site configuration container and according to the 527 matriculation number construction rules defined in the 528 _constructMatricNumber method. The new matric number is set, 529 the students catalog updated and next_matric_integer 530 increased by one. 531 532 This method is tested but not used in the base package. It can 533 be used in custom packages by adding respective views 534 and by customizing _composeMatricNumber according to the 535 university's matriculation number construction rules. 536 537 The method can be disabled by setting next_matric_integer to zero. 538 """ 539 next_integer = grok.getSite()['configuration'].next_matric_integer 540 if next_integer == 0: 541 return _('Matriculation number cannot be set.'), None 542 if student.matric_number is not None: 543 return _('Matriculation number already set.'), None 544 try: 545 student.matric_number = self._constructMatricNumber( 546 student, next_integer) 547 except MatNumNotInSource: 548 return _('Matriculation number exists.'), None 549 notify(grok.ObjectModifiedEvent(student)) 550 grok.getSite()['configuration'].next_matric_integer += 1 551 return None, next_integer 552 517 553 def getAccommodationDetails(self, student): 518 554 """Determine the accommodation data of a student.
Note: See TracChangeset for help on using the changeset viewer.