Changeset 8202
- Timestamp:
- 18 Apr 2012, 05:12:32 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_applicant_data.csv
r7984 r8202 1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex 2 dp2011,1001,Aaren,Pieri,1990-01-02,xx@yy.zz,CERT1,m 3 dp2011,1002,Aaren,Finau,1990-01-03,xx@yy.zz,CERT1,m 4 dp2011,1003,Aaren,Berson,1990-01-04,xx@yy.zz,CERT1,m 1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex,middlename 2 dp2011,1001,Aaren,Pieri,1990-01-02,xx@yy.zz,CERT1,m,Peter 3 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
r7270 r8202 1 container_code,reg_number,firstname 2 dp2011,1001,Aaren 3 dp2011,1002,Alfons 4 dp2011,1003,Abraham 1 container_code,reg_number,firstname,middlename 2 dp2011,1001,Aaren, 3 dp2011,1002,Alfons, 4 dp2011,1003,Abraham, -
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/sample_faulty_applicant_data.csv
r7984 r8202 1 container_code,reg_number,firstname,lastname,date_of_birth,email,course1,sex 2 dp2011,1001,Aaren,Pieri,01/02/1990,xx@yy.zz,CERT1,m 1 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
r8200 r8202 48 48 '\n')[0].split(',') 49 49 50 # The same for students50 # The same for applicants 51 51 APPLICANT_SAMPLE_DATA = open( 52 52 os.path.join(os.path.dirname(__file__), 'sample_applicant_data.csv'), … … 56 56 'sample_faulty_applicant_data.csv'), 'rb').read() 57 57 58 59 58 APPLICANT_HEADER_FIELDS = APPLICANT_SAMPLE_DATA.split( 60 59 '\n')[0].split(',') … … 63 62 os.path.join(os.path.dirname(__file__), 64 63 'sample_applicant_data_update.csv'), 'rb').read() 64 65 APPLICANT_SAMPLE_DATA_UPDATE2 = open( 66 os.path.join(os.path.dirname(__file__), 67 'sample_applicant_data_update2.csv'), 'rb').read() 65 68 66 69 APPLICANT_HEADER_FIELDS_UPDATE = APPLICANT_SAMPLE_DATA_UPDATE.split( … … 231 234 self.csv_file_update = os.path.join( 232 235 self.workdir, 'sample_applicant_data_update.csv') 236 self.csv_file_update2 = os.path.join( 237 self.workdir, 'sample_applicant_data_update2.csv') 233 238 open(self.csv_file, 'wb').write(APPLICANT_SAMPLE_DATA) 234 239 open(self.csv_file_faulty, 'wb').write(FAULTY_APPLICANT_SAMPLE_DATA) 235 240 open(self.csv_file_update, 'wb').write(APPLICANT_SAMPLE_DATA_UPDATE) 241 open(self.csv_file_update2, 'wb').write(APPLICANT_SAMPLE_DATA_UPDATE2) 236 242 237 243 def test_interface(self): … … 306 312 self.csv_file_update, APPLICANT_HEADER_FIELDS_UPDATE, 'update') 307 313 self.assertEqual(num_warns,0) 314 # The middlename import value was None. 315 # Confirm that middlename has not been deleted. 316 container = self.app['applicants']['dp2011'] 317 for key in container.keys(): 318 if container[key].lastname == 'Pieri': 319 applicant = container[key] 320 break 321 self.assertEqual(applicant.middlename, 'Peter') 322 shutil.rmtree(os.path.dirname(fin_file)) 323 # Now we import another file which clears all middlename attributes. 324 num, num_warns, fin_file, fail_file = self.processor.doImport( 325 self.csv_file_update2, APPLICANT_HEADER_FIELDS_UPDATE, 'update') 326 self.assertEqual(num_warns,0) 327 assert applicant.middlename is None 308 328 shutil.rmtree(os.path.dirname(fin_file)) 309 329 -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r8176 r8202 37 37 _ = MessageFactory = zope.i18nmessageid.MessageFactory('waeup.kofa') 38 38 39 DELETIONMARKER = 'XXX' 40 39 41 CREATED = 'created' 40 42 ADMITTED = 'admitted' -
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8176 r8202 34 34 from waeup.kofa.interfaces import ( 35 35 IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount, 36 IObjectHistory, VALIDATED )36 IObjectHistory, VALIDATED, DELETIONMARKER) 37 37 from waeup.kofa.interfaces import MessageFactory as _ 38 38 from waeup.kofa.students.interfaces import ( … … 168 168 history.addMessage(msg) 169 169 elif hasattr(obj, key): 170 setattr(obj, key, value) 170 # Set attribute to None if value is marked for deletion 171 if value == DELETIONMARKER: 172 setattr(obj, key, None) 173 elif value is not None: 174 setattr(obj, key, value) 171 175 items_changed += '%s=%s, ' % (key,value) 172 176 parent = self.getParent(row, site) … … 296 300 # Skip fields not declared in interface. 297 301 if hasattr(obj, key): 298 setattr(obj, key, value) 299 if key == 'certificate': 300 value = value.code 302 # Set attribute to None if value is marked for deletion 303 if value == DELETIONMARKER: 304 setattr(obj, key, None) 305 elif value is not None: 306 setattr(obj, key, value) 307 if key == 'certificate': 308 value = value.code 301 309 items_changed += '%s=%s, ' % (key,value) 302 310 parent = self.getParent(row, site) … … 687 695 if hasattr(obj, key) and not key in [ 688 696 'current_session','current_level']: 689 setattr(obj, key, value) 697 # Set attribute to None if value is marked for deletion 698 if value == DELETIONMARKER: 699 setattr(obj, key, None) 700 elif value is not None: 701 setattr(obj, key, value) 690 702 items_changed += '%s=%s, ' % (key,value) 691 703 parent = self.getParent(row, site) -
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r7950 r8202 32 32 from waeup.kofa.interfaces import ( 33 33 IBatchProcessor, FatalCSVError, IObjectConverter, 34 ICSVExporter )34 ICSVExporter, DELETIONMARKER) 35 35 36 36 class BatchProcessor(grok.GlobalUtility): … … 204 204 # Skip fields not declared in interface. 205 205 if hasattr(obj, key): 206 setattr(obj, key, value) 206 # Set attribute to None if value is marked for deletion 207 if value == DELETIONMARKER: 208 setattr(obj, key, None) 209 elif value is not None: 210 setattr(obj, key, value) 207 211 return 208 212 -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_batching.py
r7858 r8202 104 104 105 105 def updateEntry(self, obj, row, site): 106 # This is not strictly necessary, as the default107 # updateEntry method does exactly the same108 106 for key, value in row.items(): 109 setattr(obj, key, value) 107 if value is not None: 108 setattr(obj, key, value) 110 109 111 110 class BatchProcessorTests(FunctionalTestCase):
Note: See TracChangeset for help on using the changeset viewer.