Changeset 7260 for main/waeup.sirp/trunk/src/waeup
- Timestamp:
- 4 Dec 2011, 07:56:39 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp/applicants
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/applicant.py
r7255 r7260 17 17 ## 18 18 import os 19 from random import SystemRandom as r20 19 import grok 21 20 from grok import index … … 34 33 ) 35 34 36 def generate_applicant_id(container=None):37 if container is not None:38 aid = u"%s_%d" % (container.code, r().randint(99999,1000000))39 while aid in container.keys():40 aid = u"%s_%d" % (container.code, r().randint(99999,1000000))41 return aid42 else:43 # In some tests we don't use containers44 return u"xxx_1234"45 46 35 class Applicant(grok.Container): 47 36 grok.implements(IApplicant,IApplicantEdit) 48 37 grok.provides(IApplicant) 49 38 50 def __init__(self , container=None):39 def __init__(self): 51 40 super(Applicant, self).__init__() 52 self.applicant_id = generate_applicant_id(container)53 41 self.password = None 54 42 IWorkflowInfo(self).fireTransition('init') 55 43 self.application_date = None 44 self.applicant_id = None 56 45 return 57 46 … … 72 61 @property 73 62 def application_number(self): 74 return self.applicant_id.split('_')[1] 63 try: 64 return self.applicant_id.split('_')[1] 65 except AttributeError: 66 return None 75 67 76 68 @property … … 110 102 111 103 def __call__(self, *args, **kw): 112 return Applicant( kw['container'])104 return Applicant() 113 105 114 106 def getInterfaces(self): -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py
r7259 r7260 424 424 @grok.action('Create application record') 425 425 def addApplicant(self, **data): 426 applicant = createObject(u'waeup.Applicant' , container = self.context)426 applicant = createObject(u'waeup.Applicant') 427 427 self.applyData(applicant, **data) 428 428 self.context.addApplicant(applicant) -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/container.py
r7240 r7260 19 19 Containers for university applicants. 20 20 """ 21 from random import SystemRandom as r 21 22 import grok 22 23 from zope.component.factory import Factory … … 27 28 ) 28 29 from waeup.sirp.utils.helpers import attrs_to_fields 30 31 def generate_applicant_id(container=None): 32 if container is not None: 33 aid = u"%s_%d" % (container.code, r().randint(99999,1000000)) 34 while aid in container.keys(): 35 aid = u"%s_%d" % (container.code, r().randint(99999,1000000)) 36 return aid 37 else: 38 # In some tests we don't use containers 39 return u"xxx_1234" 29 40 30 41 class ApplicantsContainer(grok.Container): … … 89 100 raise TypeError( 90 101 'ApplicantsContainers contain only IApplicant instances') 102 applicant_id = generate_applicant_id(container=self) 103 applicant.applicant_id = applicant_id 91 104 self[applicant.application_number] = applicant 92 105 return -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/interfaces.py
r7255 r7260 257 257 title = u'Applicant Id', 258 258 required = False, 259 readonly = True,259 readonly = False, 260 260 ) 261 261 -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_applicant.py
r7255 r7260 123 123 # we can get an image filename for applicants not in a container 124 124 appl = Applicant() 125 appl.applicant_id = u'dummy_123456' 125 126 chooser = IFileStoreNameChooser(appl) 126 127 result = chooser.chooseName() 127 128 # the file would be stored in a ``_default`` directory. 128 129 self.assertEqual( 129 result, '__img-applicant___default/ xxx_1234.jpg')130 result, '__img-applicant___default/dummy_123456.jpg') 130 131 return 131 132 … … 134 135 fake_container.__name__ = 'folder' 135 136 fake_container.code = 'folder' 136 appl = Applicant(container=fake_container) 137 appl = Applicant() 138 appl.applicant_id = u'folder_123456' 137 139 appl.__parent__ = fake_container 138 140 chooser = IFileStoreNameChooser(appl) … … 147 149 fake_container.__name__ = 'folder' 148 150 fake_container.code = 'folder' 149 appl = Applicant(container=fake_container) 151 appl = Applicant() 152 appl.applicant_id = u'folder_123456' 150 153 appl.__parent__ = fake_container 151 154 chooser = IFileStoreNameChooser(appl) … … 193 196 194 197 def test_factory(self): 195 obj = self.factory( container=None)198 obj = self.factory() 196 199 assert isinstance(obj, Applicant) 197 200 -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_browser.py
r7259 r7260 117 117 118 118 # Add an applicant 119 self.applicant = Applicant(container=applicantscontainer) 120 app['applicants']['app2009'][ 121 self.applicant.application_number] = self.applicant 119 self.applicant = Applicant() 120 app['applicants']['app2009'].addApplicant(self.applicant) 122 121 IUserAccount( 123 122 self.app['applicants']['app2009'][ -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/tests/test_catalog.py
r7240 r7260 61 61 setSite(self.app) 62 62 self.app['applicants']['mystuff'] = self.container 63 self.applicant = Applicant(container=self.container) 64 self.app['applicants']['mystuff'][ 65 self.applicant.application_number] = self.applicant 63 self.applicant = Applicant() 64 self.app['applicants']['mystuff'].addApplicant(self.applicant) 66 65 return 67 66
Note: See TracChangeset for help on using the changeset viewer.