Changeset 8290 for main/waeup.kofa/trunk/src
- Timestamp:
- 26 Apr 2012, 17:01:32 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/applicants
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/batching.py
r8236 r8290 23 23 from zope.interface import Interface 24 24 from zope.component import queryUtility 25 from hurry.workflow.interfaces import IWorkflowState 25 26 from zope.catalog.interfaces import ICatalog 26 27 from waeup.kofa.interfaces import ( 27 IBatchProcessor, IObjectConverter, FatalCSVError, IGNORE_MARKER) 28 IBatchProcessor, IObjectConverter, FatalCSVError, IGNORE_MARKER, 29 IObjectHistory, IUserAccount) 30 from waeup.kofa.interfaces import MessageFactory as _ 28 31 from waeup.kofa.utils.batching import BatchProcessor 29 32 from waeup.kofa.applicants.interfaces import ( 30 33 IApplicantsContainer, IApplicant, IApplicantUpdateByRegNo) 34 from waeup.kofa.applicants.workflow import IMPORTABLE_STATES 31 35 32 36 class ApplicantsContainerProcessor(BatchProcessor): … … 89 93 def available_fields(self): 90 94 return sorted(list(set( 91 ['application_number','reg_number','container_code'] + getFields( 95 ['application_number','reg_number', 96 'container_code','state','password'] + getFields( 92 97 self.iface).keys()))) 93 98 … … 150 155 parent = self.getParent(row, site) 151 156 parent.addApplicant(obj) 157 # We have to log this if state is provided. If not, 158 # logging is done by the event handler handle_applicant_added 159 if row.has_key('state'): 160 parent.__parent__.logger.info( 161 '%s - Application initialized' % obj.applicant_id) 162 history = IObjectHistory(obj) 163 history.addMessage(_('Application initialized')) 152 164 return 153 165 … … 158 170 del parent[applicant.application_number] 159 171 pass 172 173 def updateEntry(self, obj, row, site): 174 """Update obj to the values given in row. 175 """ 176 items_changed = '' 177 178 # Remove application_number from row if empty 179 if row.has_key('application_number') and row['application_number'] in ( 180 None, IGNORE_MARKER): 181 row.pop('application_number') 182 183 # Update applicant_id fom application_number and container code 184 # if application_number is given 185 if row.has_key('application_number'): 186 obj.applicant_id = u'%s_%s' % ( 187 row['container_code'], row['application_number']) 188 row.pop('application_number') 189 190 # Update password 191 passwd = row.get('password', IGNORE_MARKER) 192 if passwd not in ('', IGNORE_MARKER): 193 IUserAccount(obj).setPassword(passwd) 194 row.pop('password') 195 196 # Update registration state 197 state = row.get('state', IGNORE_MARKER) 198 if state not in (IGNORE_MARKER, ''): 199 value = row['state'] 200 IWorkflowState(obj).setState(value) 201 msg = _("State '${a}' set", mapping = {'a':value}) 202 history = IObjectHistory(obj) 203 history.addMessage(msg) 204 row.pop('state') 205 206 # apply other values... 207 items_changed = super(ApplicantProcessor, self).updateEntry( 208 obj, row, site) 209 210 # Log actions... 211 parent = self.getParent(row, site) 212 if hasattr(obj,'application_number'): 213 # Update mode: the applicant exists and we can get the applicant_id 214 parent.__parent__.logger.info( 215 '%s - Application record updated: %s' 216 % (obj.applicant_id, items_changed)) 217 else: 218 # Create mode: the applicant does not yet exist 219 parent.logger.info('Application record imported: %s' % items_changed) 220 return items_changed 160 221 161 222 def getMapping(self, path, headerfields, mode): … … 186 247 errs, inv_errs, conv_dict = converter.fromStringDict( 187 248 row, self.factory_name, mode=mode) 249 if row.has_key('state') and \ 250 not row['state'] in IMPORTABLE_STATES: 251 if row['state'] not in (IGNORE_MARKER, ''): 252 errs.append(('state','not allowed')) 253 else: 254 # state is an attribute of Applicant and must not 255 # be changed if empty 256 conv_dict['state'] = IGNORE_MARKER 257 application_number = row.get('application_number', IGNORE_MARKER) 258 if application_number in (IGNORE_MARKER, ''): 259 conv_dict['application_number'] = IGNORE_MARKER 188 260 return errs, inv_errs, conv_dict -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/container.py
r8008 r8290 89 89 raise TypeError( 90 90 'ApplicantsContainers contain only IApplicant instances') 91 applicant_id = generate_applicant_id(container=self) 92 applicant.applicant_id = applicant_id 91 if applicant.applicant_id is None: 92 applicant_id = generate_applicant_id(container=self) 93 applicant.applicant_id = applicant_id 93 94 self[applicant.application_number] = applicant 94 95 return -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data.csv
r8202 r8290 1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename2 dp2011,1001,Aaren,Pieri,1990-01-02,xx@yy.zz,CERT1,m,Peter3 dp2011,1002,Aaren,Finau,1990-01-03,xx@yy.zz,CERT1,m,Claus4 dp2011,1003,Aaren,Berson,1990-01-04,xx@yy.zz,CERT1,m,Alfons1 application_number,container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename 2 1234,dp2011,1001,Aaren,Pieri,1990-01-02,xx@yy.zz,CERT1,m,Peter 3 2345,dp2011,1002,Aaren,Finau,1990-01-03,xx@yy.zz,CERT1,m,Claus 4 ,dp2011,1003,Aaren,Berson,1990-01-04,xx@yy.zz,CERT1,m,Alfons -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data_update.csv
r8202 r8290 1 container_code,reg_number,firstname,middlename 2 dp2011,1001,Aaren, 3 dp2011,1002,Alfons, 4 dp2011,1003,Abraham, 1 container_code,reg_number,firstname,middlename,state 2 dp2011,1001,Aaren,, 3 dp2011,1002,Alfons,,admitted 4 dp2011,1003,Abraham,, -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data_update2.csv
r8202 r8290 1 container_code,reg_number,firstname,middlename 2 dp2011,1001,Aaren,XXX 3 dp2011,1002,Alfons,XXX 4 dp2011,1003,Abraham,XXX 1 container_code,reg_number,firstname,middlename,application_number 2 dp2011,1001,Aaren,XXX, 3 dp2011,1002,Alfons,XXX, 4 dp2011,1003,Abraham,XXX, -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_faulty_applicant_data.csv
r8202 r8290 1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename2 dp2011,1001,Aaren,Pieri,01/02/1990,xx@yy.zz,CERT1,m,Claus1 application_number,container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename 2 ,dp2011,1001,Aaren,Pieri,01/02/1990,xx@yy.zz,CERT1,m,Claus -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_batching.py
r8202 r8290 311 311 num, num_warns, fin_file, fail_file = self.processor.doImport( 312 312 self.csv_file_update, APPLICANT_HEADER_FIELDS_UPDATE, 'update') 313 #content = open(fail_file).read() 313 314 self.assertEqual(num_warns,0) 314 315 # The middlename import value was None. … … 320 321 break 321 322 self.assertEqual(applicant.middlename, 'Peter') 323 # state of Pieri has not changed 324 self.assertEqual(container['1234'].state,'initialized') 325 # state of Finau has changed 326 self.assertEqual(container['2345'].state,'admitted') 322 327 shutil.rmtree(os.path.dirname(fin_file)) 323 328 # Now we import another file which clears all middlename attributes. -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/workflow.py
r8260 r8290 33 33 NOT_ADMITTED = 'not admitted' 34 34 CREATED = 'created' 35 36 IMPORTABLE_STATES = (INITIALIZED, PAID, SUBMITTED, ADMITTED, NOT_ADMITTED) 35 37 36 38 application_states_dict = {
Note: See TracChangeset for help on using the changeset viewer.