Changeset 8309 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 29 Apr 2012, 12:55:52 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8300 r8309 41 41 IStudentStudyLevel, ICourseTicket, 42 42 IStudentOnlinePayment, IStudentVerdictUpdate) 43 from waeup.kofa.students.workflow import IMPORTABLE_STATES 43 from waeup.kofa.students.workflow import ( 44 IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS) 44 45 from waeup.kofa.utils.batching import BatchProcessor 45 46 … … 64 65 return sorted(list(set( 65 66 ['student_id','reg_number','matric_number', 66 'password', 'state' ] + fields.keys())))67 'password', 'state', 'transition'] + fields.keys()))) 67 68 68 69 def checkHeaders(self, headerfields, mode='create'): 70 if 'state' in headerfields and 'transition' in headerfields: 71 raise FatalCSVError( 72 "State and transition can't be imported at the same time!") 69 73 if not 'reg_number' in headerfields and not 'student_id' \ 70 74 in headerfields and not 'matric_number' in headerfields: … … 148 152 pass 149 153 154 def checkUpdateRequirements(self, obj, row, site): 155 """Checks requirements the object must fulfill when being updated. 156 157 This method is not used in case of deleting or adding objects. 158 159 Returns error messages as strings in case of requirement 160 problems. 161 """ 162 transition = row.get('transition', IGNORE_MARKER) 163 if transition not in (IGNORE_MARKER, ''): 164 allowed_transitions = IWorkflowInfo(obj).getManualTransitionIds() 165 if transition not in allowed_transitions: 166 return 'Transition not allowed.' 167 return None 168 150 169 def updateEntry(self, obj, row, site): 151 170 """Update obj to the values given in row. … … 173 192 history.addMessage(msg) 174 193 row.pop('state') 194 transition = row.get('transition', IGNORE_MARKER) 195 if transition not in (IGNORE_MARKER, ''): 196 value = row['transition'] 197 IWorkflowInfo(obj).fireTransition(value) 198 row.pop('transition') 175 199 176 200 # apply other values... … … 218 242 errs, inv_errs, conv_dict = converter.fromStringDict( 219 243 row, self.factory_name, mode=mode) 244 if row.has_key('transition') and \ 245 not row['transition'] in IMPORTABLE_TRANSITIONS: 246 if row['transition'] not in (IGNORE_MARKER, ''): 247 errs.append(('transition','not allowed')) 220 248 if row.has_key('state') and \ 221 249 not row['state'] in IMPORTABLE_STATES: -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py
r8289 r8309 37 37 from waeup.kofa.students.student import Student 38 38 from waeup.kofa.testing import FunctionalLayer, FunctionalTestCase 39 from waeup.kofa.interfaces import IBatchProcessor 39 from waeup.kofa.interfaces import IBatchProcessor, FatalCSVError 40 40 41 41 STUDENT_SAMPLE_DATA = open( … … 58 58 59 59 STUDENT_HEADER_FIELDS_UPDATE2 = STUDENT_SAMPLE_DATA_UPDATE2.split( 60 '\n')[0].split(',') 61 62 STUDENT_SAMPLE_DATA_UPDATE3 = open( 63 os.path.join(os.path.dirname(__file__), 'sample_student_data_update3.csv'), 64 'rb').read() 65 66 STUDENT_HEADER_FIELDS_UPDATE3 = STUDENT_SAMPLE_DATA_UPDATE3.split( 67 '\n')[0].split(',') 68 69 STUDENT_SAMPLE_DATA_UPDATE4 = open( 70 os.path.join(os.path.dirname(__file__), 'sample_student_data_update4.csv'), 71 'rb').read() 72 73 STUDENT_HEADER_FIELDS_UPDATE4 = STUDENT_SAMPLE_DATA_UPDATE4.split( 60 74 '\n')[0].split(',') 61 75 … … 179 193 self.csv_file_update2 = os.path.join( 180 194 self.workdir, 'sample_student_data_update2.csv') 195 self.csv_file_update3 = os.path.join( 196 self.workdir, 'sample_student_data_update3.csv') 197 self.csv_file_update4 = os.path.join( 198 self.workdir, 'sample_student_data_update4.csv') 181 199 self.csv_file_migration = os.path.join( 182 200 self.workdir, 'sample_student_data_migration.csv') … … 186 204 open(self.csv_file_update, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE) 187 205 open(self.csv_file_update2, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE2) 206 open(self.csv_file_update3, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE3) 207 open(self.csv_file_update4, 'wb').write(STUDENT_SAMPLE_DATA_UPDATE4) 188 208 open(self.csv_file_migration, 'wb').write(STUDENT_SAMPLE_DATA_MIGRATION) 189 209 open(self.csv_file_duplicates, 'wb').write(STUDENT_SAMPLE_DATA_DUPLICATES) … … 293 313 assert claus.phone is None 294 314 shutil.rmtree(os.path.dirname(fin_file)) 315 316 def test_import_update3(self): 317 num, num_warns, fin_file, fail_file = self.processor.doImport( 318 self.csv_file, STUDENT_HEADER_FIELDS) 319 shutil.rmtree(os.path.dirname(fin_file)) 320 num, num_warns, fin_file, fail_file = self.processor.doImport( 321 self.csv_file_update3, STUDENT_HEADER_FIELDS_UPDATE3, 'update') 322 content = open(fail_file).read() 323 self.assertEqual( 324 content, 325 'reg_number,student_id,transition,--ERRORS--\r\n' 326 '<IGNORE>,X666666,request_clearance,Transition not allowed.\r\n' 327 ) 328 self.assertEqual(num_warns,1) 329 self.assertEqual(self.app['students']['Y777777'].state,'returning') 330 331 def test_import_update4(self): 332 num, num_warns, fin_file, fail_file = self.processor.doImport( 333 self.csv_file, STUDENT_HEADER_FIELDS) 334 shutil.rmtree(os.path.dirname(fin_file)) 335 self.assertRaises( 336 FatalCSVError, self.processor.doImport, self.csv_file_update4, 337 STUDENT_HEADER_FIELDS_UPDATE4, 'update') 295 338 296 339 def test_import_remove(self): -
main/waeup.kofa/trunk/src/waeup/kofa/students/workflow.py
r7996 r8309 152 152 destination = VALIDATED), 153 153 ) 154 155 IMPORTABLE_TRANSITIONS = [i.transition_id for i in REGISTRATION_TRANSITIONS] 154 156 155 157 LOCK_CLEARANCE_TRANS = ('reset2', 'request_clearance')
Note: See TracChangeset for help on using the changeset viewer.