Changeset 9131 for main


Ignore:
Timestamp:
31 Aug 2012, 09:21:59 (12 years ago)
Author:
Henrik Bettermann
Message:

Add method for transferring students when the student has changed the course of study.

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r9035 r9131  
    220220        )
    221221
     222    def transfer(certificate, current_session,
     223        current_level, current_verdict):
     224        """ Creates a new studycourse and backups the old one.
     225
     226        """
     227
    222228class IUGStudentClearance(IKofaObject):
    223229    """Representation of undergraduate student clearance data.
  • main/waeup.kofa/trunk/src/waeup/kofa/students/student.py

    r8737 r9131  
    143143        return is_postgrad
    144144
     145    def transfer(self, certificate, current_session=None,
     146        current_level=None, current_verdict=None):
     147        """ Creates a new studycourse and backups the old one.
     148
     149        """
     150        studycourse = createObject(u'waeup.StudentStudyCourse')
     151        studycourse.certificate = certificate
     152        studycourse.entry_mode = 'transfer'
     153        studycourse.current_session = current_session
     154        studycourse.current_level = current_level
     155        studycourse.current_verdict = current_verdict
     156        old = self['studycourse']
     157        # Students can be transferred only two times.
     158        if 'studycourse_1' in self.keys():
     159            if 'studycourse_2' in self.keys():
     160                return False
     161            self['studycourse_2'] = old
     162        else:
     163            self['studycourse_1'] = old
     164        del self['studycourse']
     165        self['studycourse'] = studycourse
     166        self.__parent__.logger.info(
     167            '%s - transferred from %s to %s' % (
     168            self.student_id, old.certificate.code, studycourse.certificate.code))
     169        return True
     170
    145171
    146172# Set all attributes of Student required in IStudent as field
  • main/waeup.kofa/trunk/src/waeup/kofa/students/studycourse.py

    r8972 r9131  
    6464            return False
    6565        return self.certificate.study_mode.startswith('pg')
     66
     67    @property
     68    def is_current(self):
     69        if '_' in self.__name__:
     70            return False
     71        return True
    6672
    6773    def addStudentStudyLevel(self, cert, studylevel):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py

    r8920 r9131  
    2121import re
    2222import unittest
     23import grok
    2324from cStringIO import StringIO
    2425from datetime import tzinfo
    25 from zope.component import getUtility
     26from zope.component import getUtility, queryUtility, createObject
     27from zope.catalog.interfaces import ICatalog
    2628from zope.component.interfaces import IFactory
     29from zope.event import notify
    2730from zope.interface import verify
     31from zope.schema.interfaces import RequiredMissing
    2832from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser
    2933from waeup.kofa.students.export import EXPORTER_NAMES
     
    236240        return
    237241
     242class StudentTransferTests(StudentImportExportSetup):
     243
     244    layer = FunctionalLayer
     245
     246    def setUp(self):
     247        super(StudentTransferTests, self).setUp()
     248
     249        # Add additional certificate
     250        self.certificate2 = createObject('waeup.Certificate')
     251        self.certificate2.code = 'CERT2'
     252        self.certificate2.application_category = 'basic'
     253        self.certificate2.start_level = 200
     254        self.certificate2.end_level = 500
     255        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     256            self.certificate2)
     257
     258        # Add student with subobjects
     259        student = Student()
     260        self.app['students'].addStudent(student)
     261        student = self.setup_student(student)
     262        notify(grok.ObjectModifiedEvent(student))
     263        self.student = self.app['students'][student.student_id]
     264        return
     265
     266    def test_transfer_student(self):
     267        self.assertRaises(
     268            RequiredMissing, self.student.transfer, self.certificate2)
     269        success = self.student.transfer(self.certificate2, current_session=2013)
     270        self.assertEqual(self.student['studycourse_1'].certificate.code, 'CERT1')
     271        self.assertEqual(self.student['studycourse'].certificate.code, 'CERT2')
     272        self.assertEqual(self.student['studycourse_1'].current_session, 2012)
     273        self.assertEqual(self.student['studycourse'].current_session, 2013)
     274        self.assertEqual(self.student['studycourse_1'].__name__, 'studycourse_1')
     275        logfile = os.path.join(
     276            self.app['datacenter'].storage, 'logs', 'students.log')
     277        logcontent = open(logfile).read()
     278        self.assertTrue('system - K1000000 - transferred from CERT1 to CERT2'
     279            in logcontent)
     280
     281        # The students_catalog has been updated.
     282        cat = queryUtility(ICatalog, name='students_catalog')
     283        results = cat.searchResults(certcode=('CERT1', 'CERT1'))
     284        results = [x for x in results]
     285        self.assertEqual(len(results), 0)
     286        results = cat.searchResults(certcode=('CERT2', 'CERT2'))
     287        results = [x for x in results]
     288        self.assertEqual(len(results), 1)
     289        assert results[0] is self.app['students'][self.student.student_id]
     290        results = cat.searchResults(current_session=(2013,2013))
     291        results = [x for x in results]
     292        self.assertEqual(len(results), 1)
     293        assert results[0] is self.app['students'][self.student.student_id]
     294
     295        # Students can be transferred (only) two times.
     296        success = self.student.transfer(self.certificate, current_session=2013)
     297        self.assertTrue(success)
     298        success = self.student.transfer(self.certificate2, current_session=2013)
     299        self.assertFalse(success)
     300        self.assertEqual([i for i in self.student.keys()],
     301            [u'accommodation', u'payments', u'studycourse',
     302             u'studycourse_1', u'studycourse_2'])
     303
     304        # The students_catalog has been updated again.
     305        cat = queryUtility(ICatalog, name='students_catalog')
     306        results = cat.searchResults(certcode=('CERT1', 'CERT1'))
     307        results = [x for x in results]
     308        self.assertEqual(len(results), 1)
     309        assert results[0] is self.app['students'][self.student.student_id]
     310        return
    238311
    239312class StudentFactoryTest(FunctionalTestCase):
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/utils.py

    r8853 r9131  
    123123
    124124    STUDY_MODES_DICT = {
     125        'transfer': 'Transfer',
    125126        'ug_ft': 'Undergraduate Full-Time',
    126127        'ug_pt': 'Undergraduate Part-Time',
Note: See TracChangeset for help on using the changeset viewer.