Changeset 7391 for main/waeup.sirp/trunk


Ignore:
Timestamp:
19 Dec 2011, 12:26:08 (13 years ago)
Author:
uli
Message:

Store application slip when creating students.

File:
1 edited

Legend:

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

    r7388 r7391  
    1818import os
    1919import grok
     20from cStringIO import StringIO
    2021from grok import index
    21 from zope.component import getUtility
     22from zope.component import getUtility, createObject, getUtility, getAdapter
    2223from zope.component.interfaces import IFactory
    23 from zope.component import createObject, getUtility
    2424from zope.catalog.interfaces import ICatalog
    2525from zope.securitypolicy.interfaces import IPrincipalRoleManager
     
    3131from waeup.sirp.interfaces import (
    3232    IObjectHistory, IFileStoreHandler, IFileStoreNameChooser, ISIRPUtils,
    33     IExtFileStore)
     33    IExtFileStore, IPDF)
     34from waeup.sirp.students.vocabularies import RegNumNotInSource
    3435from waeup.sirp.utils.helpers import attrs_to_fields, get_current_principal
    3536from waeup.sirp.applicants.interfaces import (
    3637    IApplicant, IApplicantEdit, IApplicantBaseData,
    3738    )
    38 from waeup.sirp.students.vocabularies import RegNumNotInSource
     39
    3940
    4041class Applicant(grok.Container):
     
    7778        return sirp_utils.fullname(self.firstname, self.lastname, middlename)
    7879
    79     def createStudent(self):
     80    def createStudent(self, view=None):
    8081        """Create a student, fill with base data, create a StudentApplication
    8182        object and copy applicant data.
     
    9697        site = grok.getSite()
    9798        site['students'].addStudent(student)
    98         # Fill student_id
     99
    99100        self.student_id = student.student_id
    100         # Fire transition 'create'
    101101        IWorkflowInfo(self).fireTransition('create')
     102
    102103        # Copy some base data
    103104        student.firstname = self.firstname
     
    107108        student.email = self.email
    108109        student.phone = self.phone
     110
    109111        # Save the certificate
    110112        student['studycourse'].certificate = self.course_admitted
    111113        self._copyPassportImage(student)
    112114
    113         # Save application slip (ExportPDFPage)
     115        # Save application slip
     116        self._createApplicationPDF(student, view=view)
    114117
    115118        return True, 'Student %s created' % student.student_id
     119
     120    def _createApplicationPDF(self, student, view=None):
     121        """Create an application slip as PDF and store it in student folder.
     122        """
     123        file_store = getUtility(IExtFileStore)
     124        applicant_slip = getAdapter(self, IPDF, name='application_slip')(
     125            view=view)
     126        file_id = IFileStoreNameChooser(student).chooseName(
     127            attr="application_slip.pdf")
     128        file_store.createFile(file_id, StringIO(applicant_slip))
     129        return
    116130
    117131    def _copyPassportImage(self, student):
Note: See TracChangeset for help on using the changeset viewer.