Changeset 9137


Ignore:
Timestamp:
31 Aug 2012, 20:19:08 (12 years ago)
Author:
Henrik Bettermann
Message:

Return error code after transfer.

Add history message.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

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

    r9136 r9137  
    2828from zope.interface import implementedBy
    2929from zope.securitypolicy.interfaces import IPrincipalRoleManager
     30from zope.schema.interfaces import ConstraintNotSatisfied
    3031
    3132from waeup.kofa.image import KofaImageFile
     
    149150        """
    150151        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         studycourse.previous_verdict = previous_verdict
     152        try:
     153            studycourse.certificate = certificate
     154            studycourse.entry_mode = 'transfer'
     155            studycourse.current_session = current_session
     156            studycourse.current_level = current_level
     157            studycourse.current_verdict = current_verdict
     158            studycourse.previous_verdict = previous_verdict
     159        except ConstraintNotSatisfied:
     160            return -1
    157161        old = self['studycourse']
    158162        studycourse.entry_session = old.entry_session
     
    160164        if 'studycourse_1' in self.keys():
    161165            if 'studycourse_2' in self.keys():
    162                 return False
     166                return -2
    163167            self['studycourse_2'] = old
    164168        else:
     
    169173            '%s - transferred from %s to %s' % (
    170174            self.student_id, old.certificate.code, studycourse.certificate.code))
    171         return True
     175        history = IObjectHistory(self)
     176        history.addMessage('Transferred from %s to %s' % (
     177            old.certificate.code, studycourse.certificate.code))
     178        return
    172179
    173180
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_student.py

    r9136 r9137  
    267267        self.assertRaises(
    268268            RequiredMissing, self.student.transfer, self.certificate2)
    269         success = self.student.transfer(self.certificate2,
    270             current_session=2013)
     269        error = self.student.transfer(self.certificate2, current_session=1000)
     270        self.assertTrue(error == -1)
     271        error = self.student.transfer(self.certificate2, current_session=2013)
     272        self.assertTrue(error == None)
    271273        self.assertEqual(self.student['studycourse_1'].certificate.code, 'CERT1')
    272274        self.assertEqual(self.student['studycourse'].certificate.code, 'CERT2')
     
    281283        self.assertTrue('system - K1000000 - transferred from CERT1 to CERT2'
    282284            in logcontent)
     285        messages = ' '.join(self.student.history.messages)
     286        self.assertMatches(
     287            '...<YYYY-MM-DD hh:mm:ss> UTC - '
     288            'Transferred from CERT1 to CERT2 by system', messages)
    283289
    284290        # The students_catalog has been updated.
     
    297303
    298304        # Students can be transferred (only) two times.
    299         success = self.student.transfer(self.certificate,
     305        error = self.student.transfer(self.certificate,
    300306            current_session=2013)
    301         self.assertTrue(success)
    302         success = self.student.transfer(self.certificate2,
     307        self.assertTrue(error == None)
     308        error = self.student.transfer(self.certificate2,
    303309            current_session=2013)
    304         self.assertFalse(success)
     310        self.assertTrue(error == -2)
    305311        self.assertEqual([i for i in self.student.keys()],
    306312            [u'accommodation', u'payments', u'studycourse',
Note: See TracChangeset for help on using the changeset viewer.