Changeset 8843 for main/waeup.kofa


Ignore:
Timestamp:
27 Jun 2012, 14:01:32 (12 years ago)
Author:
Henrik Bettermann
Message:

Catch error if certificate has been removed between application submission and student creation.

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

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/applicant.py

    r8742 r8843  
    2727from zope.securitypolicy.interfaces import IPrincipalRoleManager
    2828from zope.interface import implementedBy
    29 from zope.schema.interfaces import RequiredMissing
     29from zope.schema.interfaces import RequiredMissing, ConstraintNotSatisfied
    3030from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    3131from waeup.kofa.app import University
     
    3737from waeup.kofa.interfaces import MessageFactory as _
    3838from waeup.kofa.students.vocabularies import RegNumNotInSource
     39from waeup.kofa.students.studycourse import StudentStudyCourse
    3940from waeup.kofa.utils.helpers import attrs_to_fields
    4041from waeup.kofa.applicants.interfaces import IApplicant, IApplicantEdit
     
    119120        if self.course_admitted is None:
    120121            return False, _('No course admitted provided.')
    121         # Add student object
     122        # Set student attributes
    122123        try:
    123124            for name in self.create_names:
     
    125126        except RequiredMissing, err:
    126127            return False, _('RequiredMissing: %s' % err)
     128        except:
     129            return False, _('Error: %s' % err)
     130        # Finally prove if the certificate still exists
     131        try:
     132            StudentStudyCourse().certificate = self.course_admitted
     133        except ConstraintNotSatisfied, err:
     134            return False, _('ConstraintNotSatisfied: %s' % self.course_admitted.code)
     135        # Add student
    127136        site = grok.getSite()
    128137        site['students'].addStudent(student)
    129         self.student_id = student.student_id
    130138        IWorkflowInfo(self).fireTransition('create')
    131139        IWorkflowInfo(student).fireTransition('admit')
    132 
    133140        # Set password
    134141        IUserAccount(student).setPassword(self.application_number)
    135 
    136142        # Save the certificate and set session attributes
    137143        student['studycourse'].certificate = self.course_admitted
     
    143149        # Update the catalog
    144150        notify(grok.ObjectModifiedEvent(student))
    145 
    146151        # Save application slip
    147152        self._createApplicationPDF(student, view=view)
  • main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_applicantcopier.py

    r8667 r8843  
    6767        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
    6868        self.browser.getControl("Save").click()
     69        # Maybe the certificate has meanwhile been removed
     70        del self.app['faculties']['fac1']['dep1'].certificates['CERT1']
     71        (success, msg) = self.applicant.createStudent()
     72        self.assertFalse(success)
     73        self.assertTrue('ConstraintNotSatisfied: CERT1' in msg)
     74        # Ok, lets add the certificate and try again
     75        self.app['faculties']['fac1']['dep1'].certificates.addCertificate(
     76            self.certificate)
    6977        (success, msg) = self.applicant.createStudent()
    7078        self.assertTrue('created' in msg)
Note: See TracChangeset for help on using the changeset viewer.