Changeset 11450 for main/waeup.kofa/trunk/src/waeup/kofa
- Timestamp:
- 27 Feb 2014, 06:25:18 (11 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/hostels/vocabularies.py
r10673 r11450 22 22 from zope.catalog.interfaces import ICatalog 23 23 from zc.sourcefactory.contextual import BasicContextualSourceFactory 24 from waeup.kofa.interfaces import SimpleKofaVocabulary 24 from waeup.kofa.interfaces import ( 25 SimpleKofaVocabulary, ContextualDictSourceFactoryBase) 25 26 from waeup.kofa.interfaces import MessageFactory as _ 26 from waeup.kofa.university.vocabularies import ContextualDictSourceFactoryBase27 27 28 28 NOT_OCCUPIED = u'not occupied' -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r11254 r11450 36 36 from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm 37 37 from waeup.kofa.schema import PhoneNumber 38 from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory 38 39 39 40 _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') … … 104 105 ) 105 106 107 class ContextualDictSourceFactoryBase(SmartBasicContextualSourceFactory): 108 """A base for contextual sources based on KofaUtils dicts. 109 110 To create a real source, you have to set the `DICT_NAME` attribute 111 which should be the name of a dictionary in KofaUtils. 112 """ 113 def getValues(self, context): 114 utils = getUtility(IKofaUtils) 115 return sorted(getattr(utils, self.DICT_NAME).keys()) 116 117 def getToken(self, context, value): 118 return str(value) 119 120 def getTitle(self, context, value): 121 utils = getUtility(IKofaUtils) 122 return getattr(utils, self.DICT_NAME)[value] 123 106 124 class SubjectSource(BasicSourceFactory): 107 125 """A source for school subjects used in exam documentation. -
main/waeup.kofa/trunk/src/waeup/kofa/payments/interfaces.py
r10914 r11450 18 18 from zope.interface import Attribute 19 19 from zope import schema 20 from waeup.kofa.university.vocabularies import ContextualDictSourceFactoryBase21 20 from waeup.kofa.interfaces import ( 22 IKofaObject, SimpleKofaVocabulary, academic_sessions_vocab) 21 IKofaObject, SimpleKofaVocabulary, academic_sessions_vocab, 22 ContextualDictSourceFactoryBase) 23 23 from waeup.kofa.interfaces import MessageFactory as _ 24 24 -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r10637 r11450 23 23 from waeup.kofa.browser.interfaces import IStudentNavigationBase 24 24 from waeup.kofa.interfaces import ( 25 IKofaObject, academic_sessions_vocab, validate_email, ICSVExporter) 25 IKofaObject, academic_sessions_vocab, validate_email, ICSVExporter, 26 ContextualDictSourceFactoryBase) 26 27 from waeup.kofa.interfaces import MessageFactory as _ 27 28 from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber … … 34 35 from waeup.kofa.university.vocabularies import ( 35 36 CourseSource, StudyModeSource, CertificateSource, SemesterSource, 36 ContextualDictSourceFactoryBase)37 ) 37 38 38 39 class PreviousPaymentCategorySource(ContextualDictSourceFactoryBase): -
main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py
r10831 r11450 21 21 from zope.catalog.interfaces import ICatalog 22 22 from zope.component import getUtility, queryUtility 23 from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils 23 from waeup.kofa.interfaces import ( 24 SimpleKofaVocabulary, IKofaUtils, ContextualDictSourceFactoryBase) 24 25 from waeup.kofa.interfaces import MessageFactory as _ 25 26 from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory … … 39 40 (_('Postgraduate Level'),999), 40 41 ) 41 42 #: An instance of :class:`waeup.kofa.utils.utils.KofaUtils` for fallback.43 KOFA_UTILS = KofaUtils()44 45 class ContextualDictSourceFactoryBase(SmartBasicContextualSourceFactory):46 """A base for contextual sources based on KofaUtils dicts.47 48 To create a real source, you have to set the `DICT_NAME` attribute49 which should be the name of a dictionary in KofaUtils.50 """51 def getValues(self, context):52 utils = queryUtility(IKofaUtils, default=KOFA_UTILS)53 return sorted(getattr(utils, self.DICT_NAME).keys())54 55 def getToken(self, context, value):56 return str(value)57 58 def getTitle(self, context, value):59 utils = queryUtility(IKofaUtils, default=KOFA_UTILS)60 return getattr(utils, self.DICT_NAME)[value]61 42 62 43 class SemesterSource(ContextualDictSourceFactoryBase):
Note: See TracChangeset for help on using the changeset viewer.