Changeset 8008 for main/waeup.kofa/trunk
- Timestamp:
- 30 Mar 2012, 10:23:32 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/batching.py
r7933 r8008 81 81 name = u'Applicant Processor' 82 82 iface = IApplicant 83 location_fields = [ ]83 location_fields = ['container_code'] 84 84 factory_name = 'waeup.Applicant' 85 location_fields = ['container_code']86 85 87 86 mode = None -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/browser.py
r7997 r8008 27 27 from hurry.workflow.interfaces import ( 28 28 IWorkflowInfo, IWorkflowState, InvalidTransitionError) 29 from waeup.kofa.applicants.container import ApplicantsContainer 29 30 from waeup.kofa.applicants.interfaces import ( 30 31 IApplicant, IApplicantEdit, IApplicantsRoot, … … 169 170 return 170 171 # Add new applicants container... 171 provider = data['provider'][1] 172 container = provider.factory() 172 container = ApplicantsContainer() 173 173 self.applyData(container, **data) 174 174 container.code = code … … 363 363 @action(_('Create application record')) 364 364 def addApplicant(self, **data): 365 applicant = createObject( self.context.factory_name)365 applicant = createObject(u'waeup.Applicant') 366 366 self.applyData(applicant, **data) 367 367 self.context.addApplicant(applicant) … … 921 921 return 922 922 # Add applicant and create password 923 applicant = createObject( self.context.factory_name)923 applicant = createObject(u'waeup.Applicant') 924 924 self.applyData(applicant, **data) 925 925 self.context.addApplicant(applicant) -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py
r7903 r8008 25 25 from waeup.kofa.interfaces import MessageFactory as _ 26 26 from waeup.kofa.applicants.interfaces import ( 27 IApplicantsContainer, IApplicantsContainerAdd, 28 IApplicantsContainerProvider, IApplicant 27 IApplicantsContainer, IApplicantsContainerAdd, IApplicant 29 28 ) 30 29 from waeup.kofa.utils.helpers import attrs_to_fields … … 45 44 grok.implements(IApplicantsContainer,IApplicantsContainerAdd) 46 45 47 #: These are 'class-attributes'. Do not fiddle around with it in48 #: instances of this class.49 #:50 #: The title of this container as displayed in add-forms. It should51 #: give some idea about what kind of container this is (one or two words)52 container_title = _(u'Basic')53 #: The `container_description` gives a short explanation about for what54 #: purposes this container type serves (a few words only).55 container_description = _(u'handles basic applicants')56 #: `iface` is the interface of the child objects.57 iface = IApplicant58 #: The name of the child object factory. This name is used in views59 #: to create proper applicant objects.60 factory_name = 'waeup.Applicant'61 46 #: A dictionary to hold per language translations of description string. 62 47 description_dict = {} … … 101 86 """Add an applicant. 102 87 """ 103 if not self.iface.providedBy(applicant):88 if not IApplicant.providedBy(applicant): 104 89 raise TypeError( 105 '%s containers contain only %s instances' %( 106 self.container_title, self.iface)) 90 'ApplicantsContainers contain only IApplicant instances') 107 91 applicant_id = generate_applicant_id(container=self) 108 92 applicant.applicant_id = applicant_id … … 112 96 ApplicantsContainer = attrs_to_fields(ApplicantsContainer) 113 97 114 class ApplicantsContainerProvider(grok.GlobalUtility): 115 """A utility that provides basic applicants containers. 98 # ApplicantsContainers must be importable. So we need a factory. 99 class ApplicantsContainerFactory(grok.GlobalUtility): 100 """A factory for student online payments. 116 101 """ 117 grok.implements(IApplicantsContainerProvider) 118 grok.name('waeup.kofa.applicants.ApplicantsContainer') 102 grok.implements(IFactory) 103 grok.name(u'waeup.ApplicantsContainer') 104 title = u"Create a new container for applicants.", 105 description = u"This factory instantiates new IApplicantsContainer instances." 119 106 120 #: The applicants container type this provider provides: 121 #: :class:`ApplicantsContainer`. 122 factory = ApplicantsContainer 107 def __call__(self, *args, **kw): 108 return ApplicantsContainer() 123 109 124 factory = Factory(lambda : ApplicantsContainer, 'ApplicantsContainer') 125 grok.global_utility(factory, IFactory, name='waeup.ApplicantsContainer')110 def getInterfaces(self): 111 return implementedBy(ApplicantsContainer) -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/export.py
r7924 r8008 34 34 #: Fieldnames considered by this exporter 35 35 fields = ('code', 'title', 'prefix', 'entry_level', 'year', 36 ' provider', 'application_category', 'description',36 'application_category', 'description', 37 37 'startdate', 'enddate', 'strict_deadline') 38 38 … … 41 41 42 42 def mangle_value(self, value, name, context=None): 43 if name == 'provider' and isinstance(value, tuple):44 value = value[0]45 43 return super( 46 44 ApplicantsContainerExporter, self).mangle_value( -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/interfaces.py
r7984 r8008 189 189 """ 190 190 191 container_title = Attribute(192 u'classattribute: title for type of container')193 container_description = Attribute(194 u'classattribute: description for type of container')195 196 197 191 code = schema.TextLine( 198 192 title = _(u'Code'), 199 #default = u'-',200 193 required = True, 201 194 readonly = True, … … 205 198 title = _(u'Title'), 206 199 required = True, 207 #default = u'-',208 200 readonly = True, 209 201 ) … … 213 205 required = True, 214 206 source = ApplicationTypeSource(), 207 readonly = True, 208 ) 209 210 year = schema.Choice( 211 title = _(u'Year of Entrance'), 212 required = True, 213 values = year_range(), 215 214 readonly = True, 216 215 ) … … 219 218 title = _(u'Entry Level'), 220 219 vocabulary = course_levels, 221 #default = 100, 222 required = True, 223 ) 224 225 year = schema.Choice( 226 title = _(u'Year of Entrance'), 227 required = True, 228 values = year_range(), 229 readonly = True, 230 ) 231 232 provider = schema.Choice( 233 title = _(u'Applicants Container Type'), 234 required = True, 235 source = ApplicantContainerProviderSource(), 236 readonly = True, 220 required = True, 237 221 ) 238 222 … … 327 311 ) 328 312 329 provider = schema.Choice(330 title = _(u'Applicants Container Type'),331 required = True,332 source = ApplicantContainerProviderSource(),333 readonly = False,334 )335 336 313 IApplicantsContainerAdd[ 337 314 'prefix'].order = IApplicantsContainer['prefix'].order 338 315 IApplicantsContainerAdd[ 339 316 'year'].order = IApplicantsContainer['year'].order 340 IApplicantsContainerAdd[341 'provider'].order = IApplicantsContainer['provider'].order342 317 343 318 class IApplicantBaseData(IKofaObject): … … 553 528 'p_year'].order 554 529 555 class IApplicantsContainerProvider(Interface):556 """A provider for applicants containers.557 558 Applicants container providers are meant to be looked up as559 utilities. This way we can find all applicant container types560 defined somewhere.561 562 Each applicants container provider registered as utility provides563 one container type and one should be able to call the `factory`564 attribute to create an instance of the requested container type.565 566 .. THE FOLLOWING SHOULD GO INTO SPHINX DOCS (and be tested)567 568 Samples:569 570 Given, you had an IApplicantsContainer implementation somewhere571 and you would like to make it findable on request, then you would572 normally create an appropriate provider utility like this::573 574 import grok575 from waeup.kofa.applicants.interfaces import IApplicantsContainerProvider576 577 class MyContainerProvider(grok.GlobalUtility):578 grok.implements(IApplicantsContainerProvider)579 grok.name('MyContainerProvider') # Must be unique580 factory = MyContainer # A class implementing IApplicantsContainer581 # or derivations thereof.582 583 This utility would be registered on startup and could then be used584 like this:585 586 >>> from zope.component import getAllUtilitiesRegisteredFor587 >>> from waeup.kofa.applicants.interfaces import (588 ... IApplicantsContainerProvider)589 >>> all_providers = getAllUtilitiesRegisteredFor(590 ... IApplicantsContainerProvider)591 >>> all_providers592 [<MyContainerProvider object at 0x...>]593 594 You could look up this specific provider by name:595 596 >>> from zope.component import getUtility597 >>> p = getUtility(IApplicantsContainerProvider, name='MyProvider')598 >>> p599 <MyContainerProvider object at 0x...>600 601 An applicants container would then be created like this:602 603 >>> provider = all_providers[0]604 >>> container = provider.factory()605 >>> container606 <MyContainer object at 0x...>607 608 """609 factory = Attribute("A class that can create instances of the "610 "requested container type") -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_batching.py
r7933 r8008 151 151 self.assertEqual(container.entry_level, 100) 152 152 self.assertEqual(container.year, 2012) 153 self.assertEqual(154 container.provider[0],155 u'waeup.kofa.applicants.ApplicantsContainer')156 153 self.assertEqual(container.application_category, 'basic') 157 154 self.assertEqual( -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r7997 r8008 248 248 self.browser.getControl(name="form.year").value = ['2010'] 249 249 self.browser.getControl(name="form.entry_level").value = ['100'] 250 self.browser.getControl(name="form.provider").value = [251 'waeup.kofa.applicants.ApplicantsContainer']252 250 self.browser.getControl( 253 251 name="form.application_category").value = ['basic'] … … 264 262 self.browser.getControl(name="form.year").value = ['2010'] 265 263 self.browser.getControl(name="form.entry_level").value = ['100'] 266 self.browser.getControl(name="form.provider").value = [267 'waeup.kofa.applicants.ApplicantsContainer']268 264 self.browser.getControl( 269 265 name="form.application_category").value = ['basic'] … … 280 276 self.browser.getControl(name="form.year").value = ['2010'] 281 277 self.browser.getControl(name="form.entry_level").value = ['100'] 282 self.browser.getControl(name="form.provider").value = [283 'waeup.kofa.applicants.ApplicantsContainer']284 278 #self.browser.getControl(name="form.ac_prefix").value = ['APP'] 285 279 self.browser.getControl( -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_export.py
r7984 r8008 12 12 ApplicantsContainerExporter, ApplicantsExporter) 13 13 from waeup.kofa.applicants.interfaces import ( 14 IApplicantsContainerProvider,AppCatSource, ApplicationTypeSource)14 AppCatSource, ApplicationTypeSource) 15 15 from waeup.kofa.applicants.tests.test_batching import ( 16 16 ApplicantImportExportSetup) … … 53 53 container.year = 2012 54 54 container.entry_level = 100 55 provider = [56 x for x in getUtilitiesFor(IApplicantsContainerProvider)57 if x[0] == 'waeup.kofa.applicants.ApplicantsContainer'][0]58 container.provider = provider59 55 container.application_category = list(AppCatSource()(container))[0] 60 56 container.description = u'Some Description\nwith linebreak\n' … … 73 69 self.assertEqual( 74 70 result, 75 'code,title,prefix,entry_level,year, provider,application_category,'71 'code,title,prefix,entry_level,year,application_category,' 76 72 'description,startdate,enddate,strict_deadline\r\n' 77 73 78 'dp2012,General Studies 2012/13,app,100,2012,' 79 'waeup.kofa.applicants.ApplicantsContainer,basic,' 74 'dp2012,General Studies 2012/13,app,100,2012,basic,' 80 75 '"Some Description\nwith linebreak\n<<de>>man spriht deutsh",' 81 76 '2012-01-01,2012-01-31,1\r\n' -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r7993 r8008 257 257 ) 258 258 259 class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,IStudentPersonal): 259 class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance, 260 IStudentPersonal): 260 261 """Representation of a student. 261 262
Note: See TracChangeset for help on using the changeset viewer.