Ignore:
Timestamp:
14 Dec 2011, 14:06:24 (13 years ago)
Author:
Henrik Bettermann
Message:

This my recent version of the createStudent method.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
2 deleted
2 edited

Legend:

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

    r7341 r7344  
    8080
    8181    def createStudent(self):
    82         """Create a student object based on the applicant base data
    83         and copy applicant object.
    84         """
     82        """Create a student, fill with base data, create a StudentApplication
     83        object and copy applicant data.
     84        """
     85        # Is applicant in the correct state?
     86        if self.state != 'admitted':
     87            return False, "Applicant has not yet been admitted."
     88        # Does registration number exist?
    8589        student = createObject(u'waeup.Student')
    86         # Check first if registration number exists
    8790        try:
    8891            student.reg_number = self.reg_number
    8992        except RegNumNotInSource:
    9093            return False, 'Registration Number exists.'
    91         catalog = getUtility(ICatalog, name='certificates_catalog')
    92         #import pdb; pdb.set_trace()
    93         code = self.course_admitted['code']
     94        # Has the course_admitted field been properly filled?
     95        code = self.course_admitted.get('code')
    9496        if code:
     97            catalog = getUtility(ICatalog, name='certificates_catalog')
    9598            cert = [i for i in catalog.searchResults(code=(code,code))][0]
    9699        else:
    97100            return False, 'No course admitted provided.'
     101        # Add student object
    98102        site = grok.getSite()
    99103        site['students'].addStudent(student)
     104        # Fill student_id
     105        self.student_id = student.student_id
     106        # Fire transition 'create'
     107        IWorkflowInfo(self).fireTransition('create')
     108
    100109        # TODO: Split fullname in students package and copy first,
    101         # middle and lastaname
    102        
     110        # middle and lastname
     111
     112        # Copy some base data
    103113        student.fullname = self.fullname
    104114        student.sex = self.sex
     
    106116        student.email = self.email
    107117        student.phone = self.phone
     118        # Save the certificate
    108119        student['studycourse'].certificate = cert
     120        # Create StudentApplication object ...
     121        application = createObject(u'waeup.StudentApplication')
     122        # ... copy applicant base data
    109123        form_fields = grok.AutoFields(IApplicantBaseData)
    110124        field_names = [i.__name__ for i in form_fields]
    111         application = createObject(u'waeup.StudentApplication')
    112125        for name in field_names:
    113126            value = getattr(self,name,None)
     
    115128                setattr(application,name,value)
    116129        site['students'][student.student_id]['application'] = application
    117         return True, 'Student with Id %s created' % student.student_id
     130        return True, 'Student %s created' % student.student_id
    118131
    119132# Set all attributes of Applicant required in IApplicant as field
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7340 r7344  
    483483    grok.require('waeup.viewStudent')
    484484    form_fields = grok.AutoFields(IApplicantBaseData)
     485    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    485486    title = 'Application Data'
    486487    pnav = 4
Note: See TracChangeset for help on using the changeset viewer.