Changeset 6256 for main/waeup.sirp/trunk


Ignore:
Timestamp:
31 May 2011, 08:24:43 (13 years ago)
Author:
Henrik Bettermann
Message:

Move vocabularies and sources into a separate module like in university package. Unfortunately, ApplicantContainerProviderSource? can't be moved because it calls IApplicantsContainerProvider from the interface module.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/applicants
Files:
1 added
2 edited

Legend:

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

    r6255 r6256  
    2424import os
    2525import waeup.sirp.browser
    26 from datetime import datetime
     26
    2727from grokcore.content.interfaces import IContainer
    28 from zc.sourcefactory.basic import BasicSourceFactory
    29 from zc.sourcefactory.contextual import BasicContextualSourceFactory
     28
    3029from zope import schema
     30from zope.interface import Interface, Attribute
    3131from zope.component import getUtility, getUtilitiesFor
    32 from zope.interface import Interface, Attribute
    33 from zope.catalog.interfaces import ICatalog
    3432from zope.pluggableauth.interfaces import IPrincipalInfo
    3533from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
     34from zc.sourcefactory.basic import BasicSourceFactory
    3635from waeup.sirp.image.schema import ImageFile
    3736from waeup.sirp.image.image import WAeUPImageFile
    38 from waeup.sirp.interfaces import IWAeUPObject, SimpleWAeUPVocabulary
     37from waeup.sirp.interfaces import IWAeUPObject
    3938from waeup.sirp.university.vocabularies import application_categories
    40 from waeup.sirp.applicants.lgas import LGAS
    41 
     39from waeup.sirp.applicants.vocabularies import (
     40  year_range, application_types_vocab, application_pins_vocab,
     41  lgas_vocab, CertificateSource, AppCatCertificateSource,
     42  GenderSource, entry_session_vocab
     43  )
    4244
    4345IMAGE_PATH = os.path.join(
     
    5456    )
    5557
    56 #: Types of applications we support.
    57 APPLICATION_TYPES = (
    58     ('General Studies', 'app','APP'),
    59     ('Pre-NCE Programme', 'prence','PRE'),
    60     ('Post UME Screening Test', 'pume','PUME'),
    61     ('Post UDE Screening', 'pude','PUDE'),
    62     ('Part Time Degree in Education', 'sandwich','SAND'),
    63     ('Part-Time Degree Programmes', 'pt','PTP'),
    64     ('Diploma Programmes', 'dp','DPP'),
    65     ('PCE Screening', 'pce','PCE'),
    66     ('Certificate Programmes', 'ct','CTP'),
    67     ('Common Entry Screening Test', 'cest','CEST'),
    68     )
    69 
    70 #: A :class:`waeup.sirp.interfaces.SimpleWAeUPVocabulary` of supported
    71 #: application or screening types.
    72 application_types_vocab = SimpleWAeUPVocabulary(
    73     *[(x[0],x[1]) for x in APPLICATION_TYPES])
    74 application_pins_vocab = SimpleWAeUPVocabulary(
    75     *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES])
    76 lgas_vocab = SimpleWAeUPVocabulary(
    77     *sorted([(x[1],x[0]) for x in LGAS]))
    78 
    79 def year_range():
    80     curr_year = datetime.now().year
    81     return range(curr_year - 2, curr_year + 5)
    82 
    83 def entry_sessions():
    84     curr_year = datetime.now().year
    85     year_range = range(curr_year - 5, curr_year + 2)
    86     return [('%s/%s' % (year,year+1), '%s' % year) for year in year_range]
    87 
    88 entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions())
    89 
    90 class CertificateSource(BasicContextualSourceFactory):
    91     """A certificate source delivers all certificates provided
    92     in the portal.
    93     """
    94     def getValues(self, context):
    95         catalog = getUtility(ICatalog, name='certificates_catalog')
    96         return sorted(list(
    97                 catalog.searchResults(
    98                     code=('', 'z*'))),
    99                     key=lambda value: value.code)
    100 
    101     def getToken(self, context, value):
    102         return value.code
    103 
    104     def getTitle(self, context, value):
    105         return "%s - %s" % (value.code, value.title[:64])
    106 
    107 class AppCatCertificateSource(CertificateSource):
    108     """An application certificate source delivers all courses which belong to
    109     a certain application_category.
    110     """
    111     def getValues(self, context):
    112         appcat = context.__parent__.application_category
    113         catalog = getUtility(ICatalog, name='certificates_catalog')
    114         return sorted(list(
    115                 catalog.searchResults(
    116                     code=('', 'z*'),
    117                     application_category=(appcat,appcat))),
    118                     key=lambda value: value.code)
    119 
    120 class GenderSource(BasicSourceFactory):
    121     """A gender source delivers basically a mapping
    122        ``{'m': 'male', 'f': 'female'}``
    123 
    124        Using a source, we make sure that the tokens (which are
    125        stored/expected for instance from CSV files) are something one
    126        can expect and not cryptic IntIDs.
    127     """
    128     def getValues(self):
    129         return ['m', 'f']
    130 
    131     def getToken(self, value):
    132         return value[0].lower()
    133 
    134     def getTitle(self, value):
    135         if value == 'm':
    136             return 'male'
    137         if value == 'f':
    138             return 'female'
    139 
    14058class ApplicantContainerProviderSource(BasicSourceFactory):
    14159    """A source offering all available applicants container types.
     
    192110    """
    193111    pass
    194 
    195112
    196113class IApplicantsContainer(IWAeUPObject):
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_interfaces.py

    r6112 r6256  
    3030from zope.publisher.browser import TestRequest
    3131from waeup.sirp.applicants import interfaces
    32 from waeup.sirp.applicants.interfaces import (
     32from waeup.sirp.applicants.vocabularies import (
    3333    APPLICATION_TYPES, application_types_vocab, GenderSource,
    3434    )
Note: See TracChangeset for help on using the changeset viewer.