Changeset 8221 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 19 Apr 2012, 15:11:32 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/batching.py
r8214 r8221 59 59 factory_name = 'waeup.Student' 60 60 61 mode = None62 63 61 @property 64 62 def available_fields(self): … … 154 152 """Update obj to the values given in row. 155 153 """ 154 items_changed = '' 155 156 156 # Remove student_id from row if empty 157 157 if row.has_key('student_id') and row['student_id'] is None: 158 158 row.pop('student_id') 159 items_changed = '' 160 for key, value in row.items(): 161 # Set student password and all fields declared in interface. 162 if key == 'password' and value != '': 163 IUserAccount(obj).setPassword(value) 164 elif key == 'reg_state': 165 IWorkflowState(obj).setState(value) 166 msg = _("State '${a}' set", mapping = {'a':value}) 167 history = IObjectHistory(obj) 168 history.addMessage(msg) 169 elif hasattr(obj, key): 170 # Set attribute to None if value is marked for deletion 171 #if value == DELETION_MARKER: 172 # setattr(obj, key, None) 173 #elif value is not None: 174 # setattr(obj, key, value) 175 #else: 176 # # No change, no change log 177 # continue 178 if value != '<IGNORE>': 179 setattr(obj, key, value) 180 181 items_changed += '%s=%s, ' % (key,value) 159 160 # Update password 161 passwd = row.get('password', '') 162 if passwd: 163 IUserAccount(obj).setPassword(passwd) 164 row.pop('password') 165 166 # Update registration state 167 if 'reg_state' in row.keys(): 168 value = row['reg_state'] 169 IWorkflowState(obj).setState(value) 170 msg = _("State '${a}' set", mapping = {'a':value}) 171 history = IObjectHistory(obj) 172 history.addMessage(msg) 173 row.pop('reg_state') 174 175 # apply other values... 176 items_changed = super(StudentProcessor, self).updateEntry( 177 obj, row, site) 178 179 # Log actions... 182 180 parent = self.getParent(row, site) 183 181 if hasattr(obj,'student_id'): … … 189 187 # Create mode: the student does not yet exist 190 188 parent.logger.info('Student data imported: %s' % items_changed) 191 return 189 return items_changed 192 190 193 191 def getMapping(self, path, headerfields, mode): … … 198 196 raw_header = reader.next() 199 197 for num, field in enumerate(headerfields): 200 if field not in [ 201 'student_id', 'reg_number', 'matric_number'] and mode == 'remove':198 if field not in ['student_id', 'reg_number', 'matric_number' 199 ] and mode == 'remove': 202 200 continue 203 201 if field == u'--IGNORE--': … … 242 240 location_fields = [] 243 241 244 mode = None245 246 242 @property 247 243 def available_fields(self): … … 302 298 """Update obj to the values given in row. 303 299 """ 304 items_changed = '' 305 for key, value in row.items(): 306 # Skip fields not declared in interface. 307 if hasattr(obj, key): 308 # Set attribute to None if value is marked for deletion 309 setattr(obj, key, value) 310 if key == 'certificate': 311 value = value.code 312 313 #if value == DELETIONMARKER: 314 # setattr(obj, key, None) 315 #elif value is not None: 316 # setattr(obj, key, value) 317 # if key == 'certificate': 318 # value = value.code 319 items_changed += '%s=%s, ' % (key,value) 300 items_changed = super(StudentStudyCourseProcessor, self).updateEntry( 301 obj, row, site) 320 302 parent = self.getParent(row, site) 321 303 parent.__parent__.logger.info( … … 331 313 converter = IObjectConverter(self.iface) 332 314 errs, inv_errs, conv_dict = converter.fromStringDict( 333 row, self.factory_name )315 row, self.factory_name, mode=mode) 334 316 # We have to check if current_level is in range of certificate. 335 # This is not done by the converter. This kind of conversion336 # checking does only work if a combination of certificate and337 # current_level is provided.338 317 if conv_dict.has_key('certificate'): 339 certificate = conv_dict['certificate'] 340 start_level = certificate.start_level 341 end_level = certificate.end_level 342 if conv_dict['current_level'] < start_level or \ 343 conv_dict['current_level'] > end_level+120: 318 cert = conv_dict['certificate'] 319 if conv_dict['current_level'] < cert.start_level or \ 320 conv_dict['current_level'] > cert.end_level+120: 344 321 errs.append(('current_level','not in range')) 345 322 return errs, inv_errs, conv_dict … … 360 337 location_fields = [] 361 338 362 mode = None363 364 339 @property 365 340 def available_fields(self): … … 431 406 converter = IObjectConverter(self.iface) 432 407 errs, inv_errs, conv_dict = converter.fromStringDict( 433 row, self.factory_name )408 row, self.factory_name, mode=mode) 434 409 # We have to check if level is a valid integer. 435 410 # This is not done by the converter. … … 457 432 location_fields = [] 458 433 459 mode = None460 461 434 @property 462 435 def available_fields(self): 463 436 return sorted(list(set( 464 ['student_id','reg_number','matric_number','level', 'code'] + getFields(465 437 ['student_id','reg_number','matric_number','level', 438 'code'] + getFields(self.iface).keys()))) 466 439 467 440 def checkHeaders(self, headerfields, mode='ignore'): … … 538 511 converter = IObjectConverter(self.iface) 539 512 errs, inv_errs, conv_dict = converter.fromStringDict( 540 row, self.factory_name )513 row, self.factory_name, mode=mode) 541 514 # We have to check if course really exists. 542 515 # This is not done by the converter. … … 562 535 563 536 location_fields = [] 564 565 mode = None566 537 567 538 @property … … 648 619 converter = IObjectConverter(self.iface) 649 620 errs, inv_errs, conv_dict = converter.fromStringDict( 650 row, self.factory_name )621 row, self.factory_name, mode=mode) 651 622 # We have to check p_id. 652 623 p_id = row['p_id'].strip('#') … … 699 670 """Update obj to the values given in row. 700 671 """ 701 items_changed = '' 702 for key, value in row.items(): 703 # Skip fields not declared in interface plus 704 # current_session and current_level 705 if hasattr(obj, key) and not key in [ 706 'current_session','current_level']: 707 setattr(obj, key, value) 708 # Set attribute to None if value is marked for deletion 709 #if value == DELETIONMARKER: 710 # setattr(obj, key, None) 711 #elif value is not None: 712 # setattr(obj, key, value) 713 items_changed += '%s=%s, ' % (key,value) 672 # Don't set current_session, current_level 673 vals_to_set = dict((key, val) for key, val in row.items() 674 if key not in ('current_session','current_level')) 675 items_changed = super(StudentVerdictProcessor, self).updateEntry( 676 obj, vals_to_set, site) 714 677 parent = self.getParent(row, site) 715 678 parent.__parent__.logger.info( … … 727 690 converter = IObjectConverter(self.iface) 728 691 errs, inv_errs, conv_dict = converter.fromStringDict( 729 row, self.factory_name )692 row, self.factory_name, mode=mode) 730 693 return errs, inv_errs, conv_dict
Note: See TracChangeset for help on using the changeset viewer.