- Timestamp:
- 21 Sep 2012, 08:19:35 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async
- Property svn:mergeinfo changed
/main/waeup.kofa/branches/uli-async-update removed /main/waeup.kofa/branches/uli-autoinclude-less removed /main/waeup.kofa/trunk removed
- Property svn:mergeinfo changed
-
main/waeup.kofa/branches/uli-zc-async/src/waeup/kofa/students/batching.py
r9209 r9211 26 26 import grok 27 27 import csv 28 from time import time29 28 from zope.interface import Interface 30 29 from zope.schema import getFields … … 43 42 IStudentOnlinePayment, IStudentVerdictUpdate) 44 43 from waeup.kofa.students.workflow import ( 45 IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS, 46 FORBIDDEN_POSTGRAD_TRANS, FORBIDDEN_POSTGRAD_STATES) 44 IMPORTABLE_STATES, IMPORTABLE_TRANSITIONS) 47 45 from waeup.kofa.utils.batching import BatchProcessor 48 46 … … 172 170 if transition not in allowed_transitions: 173 171 return 'Transition not allowed.' 174 if transition in FORBIDDEN_POSTGRAD_TRANS and \175 obj.is_postgrad:176 return 'Transition not allowed (pg student).'177 state = row.get('state', IGNORE_MARKER)178 if state not in (IGNORE_MARKER, ''):179 if state in FORBIDDEN_POSTGRAD_STATES and \180 obj.is_postgrad:181 return 'State not allowed (pg student).'182 172 return None 183 173 … … 193 183 194 184 # Update password 195 # XXX: Tale DELETION_MARKER into consideration196 185 if row.has_key('password'): 197 186 passwd = row.get('password', IGNORE_MARKER) … … 233 222 parent = self.getParent(row, site) 234 223 if hasattr(obj,'student_id'): 235 # Update mode: the student exists and we can get the student_id. 236 # Create mode: the record contains the student_id 224 # Update mode: the student exists and we can get the student_id 237 225 parent.logger.info( 238 226 '%s - Student record updated: %s' … … 271 259 errs, inv_errs, conv_dict = converter.fromStringDict( 272 260 row, self.factory_name, mode=mode) 273 if row.has_key('transition'): 274 if row['transition'] not in IMPORTABLE_TRANSITIONS: 275 if row['transition'] not in (IGNORE_MARKER, ''): 276 errs.append(('transition','not allowed')) 277 if row.has_key('state'): 278 if row['state'] not in IMPORTABLE_STATES: 279 if row['state'] not in (IGNORE_MARKER, ''): 280 errs.append(('state','not allowed')) 281 else: 282 # State is an attribute of Student and must not 283 # be changed if empty. 284 conv_dict['state'] = IGNORE_MARKER 261 if row.has_key('transition') and \ 262 not row['transition'] in IMPORTABLE_TRANSITIONS: 263 if row['transition'] not in (IGNORE_MARKER, ''): 264 errs.append(('transition','not allowed')) 265 if row.has_key('state') and \ 266 not row['state'] in IMPORTABLE_STATES: 267 if row['state'] not in (IGNORE_MARKER, ''): 268 errs.append(('state','not allowed')) 269 else: 270 # state is an attribute of Student and must not 271 # be changed if empty 272 conv_dict['state'] = IGNORE_MARKER 273 285 274 try: 286 275 # Correct stud_id counter. As the IConverter for students … … 302 291 grok.baseclass() 303 292 304 # additional available fields 305 # beside 'student_id', 'reg_number' and 'matric_number' 293 #: required fields beside 'student_id', 'reg_number' and 'matric_number' 306 294 additional_fields = [] 307 295 308 #: header fields additional lyrequired296 #: header fields additional required 309 297 additional_headers = [] 310 298 … … 373 361 return errs, inv_errs, conv_dict 374 362 375 def getMapping(self, path, headerfields, mode):376 """Get a mapping from CSV file headerfields to actually used fieldnames.377 """378 result = dict()379 reader = csv.reader(open(path, 'rb'))380 raw_header = reader.next()381 for num, field in enumerate(headerfields):382 if field not in ['student_id', 'reg_number', 'matric_number',383 'p_id', 'code', 'level'384 ] and mode == 'remove':385 continue386 if field == u'--IGNORE--':387 # Skip ignored columns in failed and finished data files.388 continue389 result[raw_header[num]] = field390 return result391 392 363 393 364 class StudentStudyCourseProcessor(StudentProcessorBase): … … 435 406 StudentStudyCourseProcessor, self).checkConversion(row, mode=mode) 436 407 # We have to check if current_level is in range of certificate. 437 if conv_dict.has_key('certificate') and \ 438 conv_dict.has_key('current_level'): 439 cert = conv_dict['certificate'] 440 level = conv_dict['current_level'] 441 if level < cert.start_level or level > cert.end_level+120: 442 errs.append(('current_level','not in range')) 408 if conv_dict.has_key('certificate'): 409 cert = conv_dict['certificate'] 410 if conv_dict['current_level'] < cert.start_level or \ 411 conv_dict['current_level'] > cert.end_level+120: 412 errs.append(('current_level','not in range')) 443 413 return errs, inv_errs, conv_dict 444 445 def checkUpdateRequirements(self, obj, row, site):446 """Checks requirements the object must fulfill when being updated.447 448 Returns error messages as strings in case of requirement449 problems.450 """451 current_level = row.get('current_level', None)452 if current_level == 999 and \453 obj.__parent__.state in FORBIDDEN_POSTGRAD_STATES:454 return 'Not a pg student.'455 return None456 414 457 415 class StudentStudyLevelProcessor(StudentProcessorBase): … … 469 427 470 428 location_fields = [] 471 472 429 additional_fields = ['level'] 473 430 additional_headers = ['level'] … … 552 509 items_changed = super(CourseTicketProcessor, self).updateEntry( 553 510 obj, row, site) 554 parent = self.getParent(row, site)555 511 student = self.getParent(row, site).__parent__.__parent__ 556 512 student.__parent__.logger.info( 557 '%s - Course ticket in %supdated: %s'558 % (student.student_id, parent.level,items_changed))513 '%s - Course ticket updated: %s' 514 % (student.student_id, items_changed)) 559 515 return 560 516 … … 572 528 return 573 529 574 def delEntry(self, row, site):575 ticket = self.getEntry(row, site)576 parent = self.getParent(row, site)577 if ticket is not None:578 student = self._getStudent(row, site)579 student.__parent__.logger.info('%s - Course ticket in %s removed: %s'580 % (student.student_id, parent.level, ticket.code))581 del parent[ticket.code]582 return583 584 530 def checkConversion(self, row, mode='ignore'): 585 531 """Validates all values in row. … … 606 552 grok.name(util_name) 607 553 608 name = u' StudentPayment Processor'554 name = u'Payment Processor' 609 555 iface = IStudentOnlinePayment 610 556 factory_name = 'waeup.StudentOnlinePayment' … … 612 558 location_fields = [] 613 559 additional_fields = ['p_id'] 614 additional_headers = [] 615 616 def checkHeaders(self, headerfields, mode='ignore'): 617 super(StudentOnlinePaymentProcessor, self).checkHeaders(headerfields) 618 if mode in ('update', 'remove') and not 'p_id' in headerfields: 619 raise FatalCSVError( 620 "Need p_id for import in update and remove modes!") 621 return True 560 additional_headers = ['p_id'] 622 561 623 562 def parentsExist(self, row, site): … … 634 573 if payments is None: 635 574 return None 636 p_id = row.get('p_id', None)637 if p_id is None:638 return None639 575 # We can use the hash symbol at the end of p_id in import files 640 576 # to avoid annoying automatic number transformation 641 577 # by Excel or Calc 642 p_id = p_id.strip('#') 643 if not p_id.startswith('p'): 644 # For data migration from old SRP only 645 p_id = 'p' + p_id[7:] + '0' 646 entry = payments.get(p_id) 578 p_id = row['p_id'].strip('#') 579 if p_id.startswith('p'): 580 entry = payments.get(p_id) 581 else: 582 # For data migration from old SRP 583 entry = payments.get('p' + p_id[6:]) 647 584 return entry 648 585 … … 663 600 if not p_id.startswith('p'): 664 601 # For data migration from old SRP 665 obj.p_id = 'p' + p_id[ 7:] + '0'602 obj.p_id = 'p' + p_id[6:] 666 603 parent[obj.p_id] = obj 667 604 else: … … 669 606 return 670 607 671 def delEntry(self, row, site):672 payment = self.getEntry(row, site)673 parent = self.getParent(row, site)674 if payment is not None:675 student = self._getStudent(row, site)676 student.__parent__.logger.info('%s - Payment ticket removed: %s'677 % (student.student_id, payment.p_id))678 del parent[payment.p_id]679 return680 681 608 def checkConversion(self, row, mode='ignore'): 682 609 """Validates all values in row. … … 686 613 687 614 # We have to check p_id. 688 p_id = row.get('p_id', None) 689 if not p_id: 690 timestamp = ("%d" % int(time()*10000))[1:] 691 p_id = "p%s" % timestamp 692 conv_dict['p_id'] = p_id 693 return errs, inv_errs, conv_dict 694 else: 695 p_id = p_id.strip('#') 615 p_id = row['p_id'].strip('#') 696 616 if p_id.startswith('p'): 697 617 if not len(p_id) == 14:
Note: See TracChangeset for help on using the changeset viewer.