Changeset 6256 for main/waeup.sirp/trunk
- Timestamp:
- 31 May 2011, 08:24:43 (13 years ago)
- 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 24 24 import os 25 25 import waeup.sirp.browser 26 from datetime import datetime 26 27 27 from grokcore.content.interfaces import IContainer 28 from zc.sourcefactory.basic import BasicSourceFactory 29 from zc.sourcefactory.contextual import BasicContextualSourceFactory 28 30 29 from zope import schema 30 from zope.interface import Interface, Attribute 31 31 from zope.component import getUtility, getUtilitiesFor 32 from zope.interface import Interface, Attribute33 from zope.catalog.interfaces import ICatalog34 32 from zope.pluggableauth.interfaces import IPrincipalInfo 35 33 from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal 34 from zc.sourcefactory.basic import BasicSourceFactory 36 35 from waeup.sirp.image.schema import ImageFile 37 36 from waeup.sirp.image.image import WAeUPImageFile 38 from waeup.sirp.interfaces import IWAeUPObject , SimpleWAeUPVocabulary37 from waeup.sirp.interfaces import IWAeUPObject 39 38 from waeup.sirp.university.vocabularies import application_categories 40 from waeup.sirp.applicants.lgas import LGAS 41 39 from 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 ) 42 44 43 45 IMAGE_PATH = os.path.join( … … 54 56 ) 55 57 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 supported71 #: 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().year81 return range(curr_year - 2, curr_year + 5)82 83 def entry_sessions():84 curr_year = datetime.now().year85 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 provided92 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.code103 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 to109 a certain application_category.110 """111 def getValues(self, context):112 appcat = context.__parent__.application_category113 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 mapping122 ``{'m': 'male', 'f': 'female'}``123 124 Using a source, we make sure that the tokens (which are125 stored/expected for instance from CSV files) are something one126 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 140 58 class ApplicantContainerProviderSource(BasicSourceFactory): 141 59 """A source offering all available applicants container types. … … 192 110 """ 193 111 pass 194 195 112 196 113 class IApplicantsContainer(IWAeUPObject): -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_interfaces.py
r6112 r6256 30 30 from zope.publisher.browser import TestRequest 31 31 from waeup.sirp.applicants import interfaces 32 from waeup.sirp.applicants. interfaces import (32 from waeup.sirp.applicants.vocabularies import ( 33 33 APPLICATION_TYPES, application_types_vocab, GenderSource, 34 34 )
Note: See TracChangeset for help on using the changeset viewer.