Changeset 6248


Ignore:
Timestamp:
30 May 2011, 11:38:19 (13 years ago)
Author:
Henrik Bettermann
Message:

Use a contextual source for the selection of study courses (certificates).

File:
1 edited

Legend:

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

    r6205 r6248  
    2727from grokcore.content.interfaces import IContainer
    2828from zc.sourcefactory.basic import BasicSourceFactory
     29from zc.sourcefactory.contextual import BasicContextualSourceFactory
    2930from zope import schema
    3031from zope.component import getUtility, getUtilitiesFor
    3132from zope.interface import Interface, Attribute
     33from zope.catalog.interfaces import ICatalog
    3234from zope.pluggableauth.interfaces import IPrincipalInfo
    3335from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
     
    7274    *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES])
    7375
     76class CertificateSource(BasicContextualSourceFactory):
     77    """A certificate source delivers all certificates provided
     78    in the portal.
     79    """
     80    def getValues(self, context):
     81        catalog = getUtility(ICatalog, name='certificates_catalog')
     82        return sorted(list(
     83                catalog.searchResults(
     84                    code=('', 'z*'))),
     85                    key=lambda value: value.code)
     86
     87    def getToken(self, context, value):
     88        return value.code
     89
     90    def getTitle(self, context, value):
     91        return "%s - %s" % (value.code, value.title[:64])
     92
     93class AppCatCertificateSource(CertificateSource):
     94    """An application certificate source delivers all courses which belong to
     95    a certain application_category.
     96    """
     97    def getValues(self, context):
     98        appcat = context.__parent__.application_category
     99        catalog = getUtility(ICatalog, name='certificates_catalog')
     100        return sorted(list(
     101                catalog.searchResults(
     102                    code=('', 'z*'),
     103                    application_category=(appcat,appcat))),
     104                    key=lambda value: value.code)
     105
    74106def year_range():
    75107    curr_year = datetime.now().year
     
    325357        readonly = True,
    326358        )
    327     course1 = schema.TextLine(
    328         # XXX: should be choice
     359    course1 = schema.Choice(
    329360        title = u'1st Choice Course of Study',
    330         required = False,
    331         )
    332     course2 = schema.TextLine(
    333         # XXX: should be choice
     361        source = AppCatCertificateSource(),
     362        required = False,
     363        )
     364    course2 = schema.Choice(
    334365        title = u'2nd Choice Course of Study',
     366        source = AppCatCertificateSource(),
    335367        required = False,
    336368        )
     
    403435        required = False,
    404436        )
    405     course_admitted = schema.TextLine(
     437    course_admitted = schema.Choice(
    406438        # XXX: should be choice
    407439        title = u'Admitted Course of Study',
     440        source = CertificateSource(),
    408441        required = False,
    409442        )
     
    422455        readonly = True,
    423456        )
    424 
    425457
    426458class IApplicant(IApplicantBaseData):
Note: See TracChangeset for help on using the changeset viewer.