Changeset 1065 for WAeUP_SRP/trunk/Students.py
- Timestamp:
- 15 Dec 2006, 13:42:56 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1005 r1065 545 545 ###) 546 546 547 security.declareProtected(ModifyPortalContent,"updateStudyCourse")###( 548 def updateStudyCourse(self): 549 """update StudyCourse from CSV values""" 550 import transaction 551 import random 552 from pdb import set_trace 553 wftool = self.portal_workflow 554 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 555 csv_d = {'jamb_reg_no': "RegNumber", 556 'jamb_lastname': "Name", 557 'session': "Session", 558 'pume_tot_score': "PUME SCORE", 559 'jamb_score': "JambScore", 560 'jamb_sex': "Sex", 561 'jamb_state': "State", 562 ## 'jamb_first_cos': "AdminCourse", 563 'faculty': "AdminFaculty", 564 'course_code': "AdmitCoscode", 565 'stud_status':"AdmitStatus", 566 'department': "AdmitDept", 567 'jamb_lga': "LGA", 568 'app_email': "email", 569 'app_mobile': "PhoneNumbers", 570 } 571 csv_fields = [f[1] for f in csv_d.items()] 572 tr_count = 0 573 total = 0 574 #name = 'pume_results' 575 name = 'StudyCourseChange' 576 no_import = [] 577 s = ','.join(['"(%s)"' % fn for fn in csv_fields]) 578 no_import.append('"Error",%s' % s) 579 format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 580 no_certificate = "no certificate %s" % format 581 open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( 582 '\n'.join(no_import)) 583 logger = logging.getLogger('%s_import' % name) 584 logger.info('Start loading from %s.csv' % name) 585 l = self.portal_catalog({'meta_type': "Certificate"}) 586 try: 587 result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 588 except: 589 logger.error('Error reading %s.csv' % name) 590 return 591 for jamb in result: 592 jamb['Error'] = "Processing " 593 logger.info(format % jamb) 594 jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) 595 res = self.portal_catalog({'portal_type': "StudentApplication", 596 'SearchableText': jamb_reg_no }) 597 if not res: 598 em = 'Student with RegNo %s does not exists\n' % jamb_reg_no 599 logger.info(em) 600 jamb['Error'] = "Student not exists" 601 no_import.append(format % jamb) 602 continue 603 sid = res[0].getPath().split('/')[-2] 604 cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) 605 res = self.portal_catalog(portal_type = "Certificate", id = cert_id) 606 if not res: 607 em = 'No Certificate with ID %s \n' % cert_id 608 logger.info(em) 609 jamb['Error'] = "No Certificate %s" % cert_id 610 no_import.append( format % jamb) 611 continue 612 cert_brain = res[0] 613 catalog_entry = {} 614 student = getattr(self,sid) 615 # 616 # Study Course 617 # 618 study_course = student.study_course 619 dsc = {} 620 cert_pl = cert_brain.getPath().split('/') 621 catalog_entry['id'] = sid 622 catalog_entry['faculty'] = cert_pl[-4] 623 catalog_entry['department'] = cert_pl[-3] 624 catalog_entry['course'] = cert_id 625 dsc['study_course'] = cert_id 626 study_course.getContent().edit(mapping=dsc) 627 self.students_catalog.modifyRecord(**catalog_entry) 628 if tr_count > 10: 629 if len(no_import) > 1: 630 open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( 631 '\n'.join(no_import)) 632 no_import = [] 633 em = '%d transactions commited\n' % tr_count 634 transaction.commit() 635 logger.info(em) 636 total += tr_count 637 tr_count = 0 638 tr_count += 1 639 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 640 ###) 641 547 642 security.declareProtected(ModifyPortalContent,"OLDloadPumeResultsFromCSV")###( 548 643 def OLDloadPumeResultsFromCSV(self):
Note: See TracChangeset for help on using the changeset viewer.