Changeset 3374 for WAeUP_SRP/base/WAeUPImport.py
- Timestamp:
- 26 Mar 2008, 08:03:17 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/WAeUPImport.py
r3372 r3374 409 409 required_modes = ('create','edit','remove') 410 410 411 def old_getStudentRecord(self,mapping): ###(412 id_field_found = False413 msg = ''414 student_record = None415 id_count = 0416 for id_key in ('matric_no','id'):417 id_field = mapping.get(id_key,'')418 if id_field:419 id_count += 1420 search_key = id_key421 search_field = id_field422 while True:423 #if id_count > 1:424 # msg = "both id and matric_no are provided"425 # break426 if id_count == 0:427 msg = "neither id nor matric_no provided"428 break429 query = Eq(search_key,search_field)430 res = self.students_catalog.evalAdvancedQuery(query)431 if res:432 student_record = res[0]433 if search_key == "matric_no":434 mapping['id'] = student_record.id435 elif search_key == "id":436 mapping['matric_no'] = student_record.matric_no437 else:438 msg = "no student with %(search_key)s %(search_field)s" % vars()439 break440 return student_record,msg441 ###)442 443 411 def create(self,mapping):###( 444 412 students_folder = self.portal_url.getPortalObject().campus.students … … 462 430 break 463 431 result = self.findStudent('create',student_id=id,matric_no=matric_no) 464 #student_record,msg = self.getStudentRecord(mapping)465 432 msg = result['msg'] 466 433 if msg: … … 500 467 ###) 501 468 502 def create_old(self,mapping):###( 503 students_folder = self.portal_url.getPortalObject().campus.students 504 if getattr(self,'_v_courses',None) is None: 505 res = self.courses_catalog() 506 self._v_courses = {} 507 for brain in res: 508 self._v_courses[brain.code] = brain 509 if getattr(self,'_v_level_created',None) is None: 510 self._v_level_created = [] 469 def edit(self,mapping): ###( 511 470 msg = '' 512 471 key = '' 513 472 matric_no = mapping.get('matric_no','') 514 student_id = mapping.get('id','') 515 while True: 516 course_id = mapping.get('code') 517 if course_id not in self._v_courses.keys(): 518 msg = "no course with id: %s" % course_id 519 break 520 student_record,msg = self.getStudentRecord(mapping) 521 if msg: 522 break 523 student_id = student_record.id 524 level_id = mapping.get('level_id','') 525 code = mapping.get('code','') 526 if student_id not in self._v_level_created: 527 try: 528 context = getattr(getattr(students_folder, 529 "%(student_id)s" % vars()), 530 'study_course') 531 except: 532 msg = "could not create level %(level_id)s for %(student_id)s" % vars() 533 break 534 if level_id not in context.objectIds(): 535 context.invokeFactory('StudentStudyLevel',"%(level_id)s" % vars()) 536 level = getattr(context,"%(level_id)s" % vars()) 537 self.portal_workflow.doActionFor(level,'open') 538 # the session string must not be copied into the level object 539 current_verdict = getattr(student_record,'current_verdict','') 540 current_session = getattr(student_record,'current_session','') 541 if current_verdict and student_record.current_level == level_id: 542 level.getContent().edit(mapping={'verdict': "%s" % 543 current_verdict, 544 'session': "%s" % 545 current_session, 546 }) 547 self.portal_workflow.doActionFor(level,'close') 548 self._v_level_created += student_id, 549 mapping['key'] = key = "%(student_id)s|%(level_id)s|%(code)s" % vars() 550 for k in ('semester','credits',): 551 mapping[k] = getattr(self._v_courses[course_id],k) 552 try: 553 self.course_results.addRecord(**mapping) 554 except ValueError: 555 msg = "course result already exists: %s" % key 556 break 557 return key,msg,mapping 558 ###) 559 560 def edit(self,mapping): ###( 561 msg = '' 562 key = '' 473 id = mapping.get('id','') 563 474 while True: 564 475 result = self.findStudent('edit',student_id=id,matric_no=matric_no) 565 #student_record,msg = self.getStudentRecord(mapping)566 476 msg = result['msg'] 567 477 if msg: … … 584 494 key = '' 585 495 msg = '' 586 while True: 587 student_record,msg = self.getStudentRecord(mapping) 496 matric_no = mapping.get('matric_no','') 497 id = mapping.get('id','') 498 while True: 499 result = self.findStudent('edit',student_id=id,matric_no=matric_no) 500 msg = result['msg'] 588 501 if msg: 589 502 break 503 student_record = result['student_record'] 590 504 student_id = student_record.id 591 505 level_id = mapping.get('level_id','') … … 1331 1245 student_record = result['student_record'] 1332 1246 key_used = result['key_used'] 1333 # if student_id: 1334 # student_record = self.students_catalog.getRecordByKey(student_id) 1335 # if student_record is None: 1336 # #return '',"no student with id %s" % student_id 1337 # msg = "no student with id %s" % student_id 1338 # break 1339 # if matric_no and student_record.matric_no and matric_no != student_record.matric_no: 1340 # msg = 'student %s: matric_no %s does not match %s' % (student_record.id, 1341 # student_record.matric_no, 1342 # matric_no) 1343 # break 1344 # mapping['matric_no'] = student_record.matric_no 1345 # elif matric_no: 1346 # res = self.students_catalog(matric_no = matric_no) 1347 # if not res: 1348 # msg = "no student with matric_no %s" % matric_no 1349 # break 1350 # student_record = res[0] 1351 # editable_keys.remove('matric_no') 1352 # else: 1353 # msg = "no id or matric_no specified" 1354 # break 1355 editable_keys.remove(key_used) 1247 if key_used in editable_keys(): 1248 editable_keys.remove(key_used) 1356 1249 student_id = student_record.id 1357 1250 mapping['id'] = student_id
Note: See TracChangeset for help on using the changeset viewer.