Changeset 7341 for main


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

Do not store a reference to a certificate but a dictionary with the code, title, department title and faculty title of certificates. In this way we can preserve the information even if the certificate has been removed.

The assignment of dynamic roles is not necessary in the application section. We can assign local roles in applicants containers. That's sufficient.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/applicants
Files:
6 edited

Legend:

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

    r7240 r7341  
    1010    ApplicantsRoot, get_applicant_data, application_exists,
    1111    )
    12 from waeup.sirp.applicants.dynamicroles import (
    13     ApplicantPrincipalRoleManager,)
    1412
    1513__all__ = [
     
    1816    'ApplicantImageNameChooser',
    1917    'ApplicantImageStoreHandler',
    20     'ApplicantPrincipalRoleManager',
    2118    'ApplicantsContainer',
    2219    'ApplicantsRoot',
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicant.py

    r7338 r7341  
    2020from grok import index
    2121from zope.component.interfaces import IFactory
    22 from zope.component import createObject
     22from zope.component import createObject, getUtility
     23from zope.catalog.interfaces import ICatalog
    2324from zope.securitypolicy.interfaces import IPrincipalRoleManager
    2425from zope.interface import implementedBy
     
    3132from waeup.sirp.utils.helpers import attrs_to_fields, get_current_principal
    3233from waeup.sirp.applicants.interfaces import (
    33     IApplicant, IApplicantEdit,
     34    IApplicant, IApplicantEdit, IApplicantBaseData,
    3435    )
     36from waeup.sirp.students.vocabularies import RegNumNotInSource
    3537
    3638class Applicant(grok.Container):
     
    7880
    7981    def createStudent(self):
    80         """Create a student object from applicatnt data
     82        """Create a student object based on the applicant base data
    8183        and copy applicant object.
    8284        """
    8385        student = createObject(u'waeup.Student')
     86        # Check first if registration number exists
     87        try:
     88            student.reg_number = self.reg_number
     89        except RegNumNotInSource:
     90            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        if code:
     95            cert = [i for i in catalog.searchResults(code=(code,code))][0]
     96        else:
     97            return False, 'No course admitted provided.'
    8498        site = grok.getSite()
    85 
    8699        site['students'].addStudent(student)
     100        # TODO: Split fullname in students package and copy first,
     101        # middle and lastaname
     102       
    87103        student.fullname = self.fullname
    88         return student.student_id
     104        student.sex = self.sex
     105        student.date_of_birth = self.date_of_birth
     106        student.email = self.email
     107        student.phone = self.phone
     108        student['studycourse'].certificate = cert
     109        form_fields = grok.AutoFields(IApplicantBaseData)
     110        field_names = [i.__name__ for i in form_fields]
     111        application = createObject(u'waeup.StudentApplication')
     112        for name in field_names:
     113            value = getattr(self,name,None)
     114            if value:
     115                setattr(application,name,value)
     116        site['students'][student.student_id]['application'] = application
     117        return True, 'Student with Id %s created' % student.student_id
    89118
    90119# Set all attributes of Applicant required in IApplicant as field
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py

    r7332 r7341  
    438438    grok.template('applicantdisplaypage')
    439439    form_fields = grok.AutoFields(IApplicant).omit(
    440         'locked', 'course_admitted', 'password')
     440        'locked',
     441        'password')
    441442    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    442443    label = 'Applicant'
     
    468469            container_title, self.context.application_number)
    469470
    470     def getCourseAdmitted(self):
    471         """Return link, title and code in html format to the certificate
    472            admitted.
    473         """
    474         course_admitted = self.context.course_admitted
    475         if ICertificate.providedBy(course_admitted):
    476             url = self.url(course_admitted)
    477             title = course_admitted.title
    478             code = course_admitted.code
    479             return '<a href="%s">%s - %s</a>' %(url,code,title)
    480         return ''
     471    def getDepartmentAdmitted(self):
     472        course_admitted = getattr(self.context,'course_admitted',None)
     473        if course_admitted:
     474            return course_admitted['dep']
     475
     476    def getFacultyAdmitted(self):
     477        course_admitted = getattr(self.context,'course_admitted',None)
     478        if course_admitted:
     479            return course_admitted['fac']
    481480
    482481class ApplicantBaseDisplayFormPage(ApplicantDisplayFormPage):
     
    485484    form_fields = grok.AutoFields(IApplicant).select(
    486485        'applicant_id', 'firstname', 'lastname','email', 'course1')
     486
     487class CreateStudentPage(grok.View):
     488    """Create a student object from applicatnt data
     489    and copy applicant object.
     490    """
     491    grok.context(IApplicant)
     492    grok.name('createstudent')
     493    grok.require('waeup.manageStudent')
     494
     495    def update(self):
     496        msg = self.context.createStudent()[1]
     497        self.flash(msg)
     498        self.redirect(self.url(self.context))
     499        return
     500
     501    def render(self):
     502        return
    487503
    488504class AcceptanceFeePaymentAddPage(grok.View):
     
    656672    grok.require('waeup.viewApplication')
    657673    form_fields = grok.AutoFields(IApplicant).omit(
    658         'locked', 'course_admitted')
     674        'locked',
     675        )
    659676    form_fields['date_of_birth'].custom_widget = FriendlyDateDisplayWidget('le')
    660677    prefix = 'form'
     
    666683            container_title, self.context.application_number)
    667684
    668     def getCourseAdmitted(self):
    669         """Return title and code in html format to the certificate
    670            admitted.
    671         """
    672         course_admitted = self.context.course_admitted
    673         if ICertificate.providedBy(course_admitted):
    674             title = course_admitted.title
    675             code = course_admitted.code
    676             return '%s - %s' %(code,title)
    677         return ''
     685    def getDepartmentAdmitted(self):
     686        course_admitted = getattr(self.context,'course_admitted',None)
     687        if course_admitted:
     688            return course_admitted['dep']
     689
     690    def getFacultyAdmitted(self):
     691        course_admitted = getattr(self.context,'course_admitted',None)
     692        if course_admitted:
     693            return course_admitted['fac']
     694
    678695
    679696    def setUpWidgets(self, ignore_request=False):
     
    738755            f_text = Paragraph(f_text, style["Normal"])
    739756            data.append([f_label,f_text])
    740         f_label = '<font size=12>Admitted Course of Study:</font>'
    741         f_text = '<font size=12>%s</font>' % self.getCourseAdmitted()
     757        #f_label = '<font size=12>Admitted Course of Study:</font>'
     758        #f_text = '<font size=12>%s</font>' % self.getCourseAdmitted()
     759        #f_label = Paragraph(f_label, style["Normal"])
     760        #f_text = Paragraph(f_text, style["Normal"])
     761        #data.append([f_label,f_text])
     762
     763        f_label = '<font size=12>Department:</font>'
     764        f_text = '<font size=12>%s</font>' % self.getDepartmentAdmitted()
    742765        f_label = Paragraph(f_label, style["Normal"])
    743766        f_text = Paragraph(f_text, style["Normal"])
    744767        data.append([f_label,f_text])
     768
     769        f_label = '<font size=12>Faculty:</font>'
     770        f_text = '<font size=12>%s</font>' % self.getFacultyAdmitted()
     771        f_label = Paragraph(f_label, style["Normal"])
     772        f_text = Paragraph(f_text, style["Normal"])
     773        data.append([f_label,f_text])
     774
    745775        # Create table
    746776        table = Table(data,style=SLIP_STYLE)
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantdisplaypage.pt

    r7254 r7341  
    2727    <tr>
    2828      <td class="fieldname">
    29           Admitted Course of Study:
     29          Department:
    3030      </td>
    3131      <td>
    32         <span tal:replace="structure view/getCourseAdmitted" />
     32        <span tal:replace="view/getDepartmentAdmitted" />
     33      </td>
     34    </tr>
     35    <tr>
     36      <td class="fieldname">
     37          Faculty:
     38      </td>
     39      <td>
     40        <span tal:replace="view/getFacultyAdmitted" />
    3341      </td>
    3442    </tr>
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py

    r7338 r7341  
    3232    ISIRPObject, year_range, validate_email, academic_sessions_vocab)
    3333from waeup.sirp.university.vocabularies import application_categories
    34 from waeup.sirp.students.vocabularies import (
    35   lgas_vocab, CertificateSource, GenderSource,
    36   )
     34from waeup.sirp.students.vocabularies import lgas_vocab, GenderSource
    3735from waeup.sirp.applicants.vocabularies import (
    3836  application_types_vocab, application_pins_vocab,
    39   AppCatCertificateSource,
     37  AppCatCertificateTitleSource, CertificateTitleSource
    4038  )
    4139from waeup.sirp.payments.interfaces import IOnlinePayment
     
    345343    course1 = schema.Choice(
    346344        title = u'1st Choice Course of Study',
    347         source = CertificateSource(),
     345        source = CertificateTitleSource(),
    348346        required = True,
    349347        )
    350348    course2 = schema.Choice(
    351349        title = u'2nd Choice Course of Study',
    352         source = CertificateSource(),
     350        source = CertificateTitleSource(),
    353351        required = False,
    354352        )
     
    365363        required = False,
    366364        )
     365    notice = schema.Text(
     366        title = u'Notice',
     367        required = False,
     368        )
    367369    course_admitted = schema.Choice(
    368370        title = u'Admitted Course of Study',
    369         source = CertificateSource(),
    370         default = None,
    371         required = False,
    372         )
    373     notice = schema.Text(
    374         title = u'Notice',
     371        source = CertificateTitleSource(),
     372        default = None,
    375373        required = False,
    376374        )
     
    425423    course1 = schema.Choice(
    426424        title = u'1st Choice Course of Study',
    427         source = AppCatCertificateSource(),
     425        source = AppCatCertificateTitleSource(),
    428426        required = True,
    429427        )
    430428    course2 = schema.Choice(
    431429        title = u'2nd Choice Course of Study',
    432         source = AppCatCertificateSource(),
     430        source = AppCatCertificateTitleSource(),
    433431        required = False,
    434432        )
     
    445443    course_admitted = schema.Choice(
    446444        title = u'Admitted Course of Study',
    447         source = CertificateSource(),
     445        source = CertificateTitleSource(),
    448446        default = None,
    449447        required = False,
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/vocabularies.py

    r7321 r7341  
    2121from zope.catalog.interfaces import ICatalog
    2222from waeup.sirp.interfaces import SimpleSIRPVocabulary
    23 from waeup.sirp.students.vocabularies import CertificateSource
     23from zc.sourcefactory.contextual import BasicContextualSourceFactory
    2424
    2525#: Types of applications we support.
     
    4444    *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES])
    4545
     46class CertificateTitleSource(BasicContextualSourceFactory):
     47    """A certificate title source delivers all certificates titles provided
     48    in the portal.
     49    """
     50    def getValues(self, context):
     51        catalog = getUtility(ICatalog, name='certificates_catalog')
     52        certs = list(catalog.searchResults(code=('', 'z*')))
     53        certs = [dict(
     54            code = i.code,
     55            title = i.title,
     56            dep = i.__parent__.__parent__.longtitle(),
     57            fac = i.__parent__.__parent__.__parent__.longtitle()
     58            ) for i in certs]
     59        return sorted(certs, key=lambda value: value['code'])
    4660
    47 class AppCatCertificateSource(CertificateSource):
    48     """An application certificate source delivers all courses which belong to
     61    def getToken(self, context, value):
     62        return value['code']
     63
     64    def getTitle(self, context, value):
     65        return "%s - %s" % (value['code'], value['title'][:64])
     66
     67class AppCatCertificateTitleSource(CertificateTitleSource):
     68    """An application certificate source delivers all course titles which belong to
    4969    a certain application_category.
    5070    """
     
    5272        appcat = context.__parent__.application_category
    5373        catalog = getUtility(ICatalog, name='certificates_catalog')
    54         return sorted(list(
    55                 catalog.searchResults(
    56                     code=('', 'z*'),
    57                     application_category=(appcat,appcat))),
    58                     key=lambda value: value.code)
     74        certs = list(catalog.searchResults(code=('', 'z*'),
     75            application_category=(appcat,appcat)))
     76        certs = [dict(
     77            code = i.code,
     78            title = i.title,
     79            dep = i.__parent__.__parent__.longtitle(),
     80            fac = i.__parent__.__parent__.__parent__.longtitle()
     81            ) for i in certs]
     82        return sorted(certs, key=lambda value: value['code'])
     83
     84
Note: See TracChangeset for help on using the changeset viewer.