Ignore:
Timestamp:
22 Apr 2014, 07:13:16 (10 years ago)
Author:
Henrik Bettermann
Message:
 
Location:
main/waeup.kofa/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r11585 r11589  
    441.2dev (unreleased)
    55===================
     6
     7* Add setMatricNumber method to StudentsUtils.
    68
    79* When sending mails, always set from-address to 'no-reply@waeup.org'.
  • main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py

    r11451 r11589  
    668668        )
    669669
     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
    670679class ISessionConfiguration(IKofaObject):
    671680    """A session configuration object.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r11450 r11589  
    8989        """
    9090
     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
    91110    def getAccommodation_details(student):
    92111        """Determine the accommodation dates of a student.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_utils.py

    r11588 r11589  
    11# -*- coding: utf-8 -*-
    22import unittest
    3 from zope.component import getUtility
     3import grok
     4from zope.component import getUtility, queryUtility, createObject
     5from zope.catalog.interfaces import ICatalog
    46from waeup.kofa.students.interfaces import IStudentsUtils
    57from waeup.kofa.students.utils import formatted_text
     
    3739        # In this case current_level remains unchanged and no error is raised.
    3840        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  
    2525from reportlab.lib.styles import getSampleStyleSheet
    2626from reportlab.platypus import Paragraph, Image, Table, Spacer
     27from zope.event import notify
    2728from zope.schema.interfaces import ConstraintNotSatisfied
    2829from zope.component import getUtility, createObject
     
    3536from waeup.kofa.students.interfaces import IStudentsUtils
    3637from waeup.kofa.students.workflow import ADMITTED
    37 from waeup.kofa.students.vocabularies import StudyLevelSource
     38from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource
    3839from waeup.kofa.browser.pdf import (
    3940    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
     
    515516        return None, payment
    516517
     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
    517553    def getAccommodationDetails(self, student):
    518554        """Determine the accommodation data of a student.
Note: See TracChangeset for help on using the changeset viewer.