Changeset 1121 for WAeUP_SRP/trunk/Students.py
- Timestamp:
- 21 Dec 2006, 21:48:19 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1119 r1121 369 369 ###) 370 370 371 security.declareProtected(ModifyPortalContent,"createDEStudents")###( 372 def createDEStudents(self): 373 """load Fulltime Studentdata from CSV values""" 374 import transaction 375 import random 376 #from pdb import set_trace 377 wftool = self.portal_workflow 378 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 379 csv_d = {'jamb_reg_no': "RegNumber", 380 'jamb_lastname': "Name", 381 'session': "Session", 382 'pume_tot_score': "PUDE SCORE", 383 ##'jamb_score': "JambScore", 384 'entry_mode': "EntryMode", 385 'jamb_sex': "Sex", 386 'jamb_state': "State", 387 'jamb_first_cos': "AdminCourse", 388 'faculty': "AdminFaculty", 389 'course_code': "AdmitCoscode", 390 'stud_status':"AdmitStatus", 391 'department': "AdmitDept", 392 'jamb_lga': "LGA", 393 'app_email': "email", 394 'app_mobile': "PhoneNumbers", 395 } 396 csv_fields = [f[1] for f in csv_d.items()] 397 tr_count = 0 398 total = 0 399 #name = 'pume_results' 400 name = 'DE_Admitted' 401 no_import = [] 402 s = ','.join(['"(%s)"' % fn for fn in csv_fields]) 403 no_import.append('"Error",%s' % s) 404 format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 405 no_certificate = "no certificate %s" % format 406 open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) 407 logger = logging.getLogger('Import.%s' % name) 408 logger.info('start loading from %s.csv' % name) 409 l = self.portal_catalog({'meta_type': "Certificate"}) 410 certs = {} 411 cert_docs = {} 412 for f in l: 413 certs[f.getId] = f.getObject().getContent() 414 try: 415 result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 416 except: 417 logger.error('Error reading %s.csv' % name) 418 return 419 for jamb in result: 420 jamb['Error'] = "Processing " 421 logger.info(format % jamb) 422 jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) 423 res = self.portal_catalog({'portal_type': "StudentApplication", 424 'SearchableText': jamb_reg_no }) 425 if res: 426 em = 'Student with RegNo %s already exists\n' % jamb_reg_no 427 logger.info(em) 428 jamb['Error'] = "Student exists" 429 no_import.append(format % jamb) 430 continue 431 cert_id = makeCertificateCode(jamb.get(csv_d['course_code'])) 432 if cert_id not in certs.keys(): 433 em = 'No Certificate with ID %s \n' % cert_id 434 logger.info(em) 435 jamb['Error'] = "No Certificate %s" % cert_id 436 no_import.append( format % jamb) 437 continue 438 jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) 439 cert_doc = certs[cert_id] 440 catalog_entry = {} 441 catalog_entry['jamb_reg_no'] = jamb_reg_no 442 jamb_name = jamb.get(csv_d['jamb_lastname']) 443 jamb_name.replace('>','') 444 jamb_name.replace('<','') 445 names = jamb_name.split() 446 letter = names[-1][0].upper() 447 sid = self.generateStudentId(letter) 448 not_created = True 449 while not_created: 450 try: 451 students_folder.invokeFactory('Student', sid) 452 not_created = False 453 except BadRequest: 454 sid = self.generateStudentId(letter) 455 catalog_entry['id'] = sid 456 tr_count += 1 457 logger.info('%(total)s+%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars()) 458 student = getattr(self,sid) 459 student.manage_setLocalRoles(sid, ['Owner',]) 460 student.invokeFactory('StudentPume','pume') 461 dp = {'Title': 'Pume Data'} 462 student.invokeFactory('StudentApplication','application') 463 da = {'Title': 'Application Data'} 464 da["jamb_lastname"] = jamb_name 465 da_fields = ('jamb_reg_no', 466 'jamb_sex', 467 'entry_mode', 468 #'jamb_score', 469 'jamb_first_cos', 470 'jamb_sex', 471 'jamb_state', 472 'jamb_lga', 473 'app_email', 474 'app_mobile', 475 ) 476 for f in da_fields: 477 da[f] = jamb.get(csv_d[f]) 478 catalog_entry['email'] = jamb.get(csv_d['app_email']) 479 app = student.application 480 app_doc = app.getContent() 481 picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) 482 #import pdb;pdb.set_trace() 483 if os.path.exists(picture): 484 file = open(picture) 485 if False: 486 img = PIL.Image.open(file) 487 img.thumbnail((150,200), 488 resample=PIL.Image.ANTIALIAS) 489 # We now need a buffer to write to. It can't be the same 490 # as the inbuffer as the PNG writer will write over itself. 491 outfile = StringIO() 492 img.save(outfile, format=img.format) 493 else: 494 outfile = file.read() 495 app_doc.manage_addFile('passport', 496 file=outfile, 497 title="%s.jpg" % jamb_reg_no) 498 app.getContent().edit(mapping=da) 499 app.manage_setLocalRoles(sid, ['Owner',]) 500 #wftool.doActionFor(app,'close') 501 dp_fields = ( 502 #'pume_eng_score', 503 #'pume_gen_score', 504 'pume_tot_score', 505 ) 506 dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded" 507 pume = student.pume 508 pume.getContent().edit(mapping=dp) 509 #wftool.doActionFor(pume,'close') 510 pume.manage_setLocalRoles(sid, ['Owner',]) 511 #student.getContent().createSubObjects() 512 dp = {} 513 if len(names) == 3: 514 dp['firstname'] = names[0].capitalize() 515 dp['middlename'] = names[1].capitalize() 516 dp['lastname'] = names[2].capitalize() 517 elif len(names) == 2: 518 dp['firstname'] = names[0].capitalize() 519 dp['middlename'] = '' 520 dp['lastname'] = names[1].capitalize() 521 else: 522 dp['firstname'] = '' 523 dp['middlename'] = '' 524 dp['lastname'] = jamb_name 525 dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' 526 catalog_entry['sex'] = dp['sex'] 527 catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp 528 student.invokeFactory('StudentPersonal','personal') 529 per = student.personal 530 per_doc = per.getContent() 531 per_doc.edit(mapping = dp) 532 per.manage_setLocalRoles(sid, ['Owner',]) 533 if jamb.get(csv_d['stud_status']) == "Admitted": 534 wftool.doActionFor(student,'pume_pass') 535 wftool.doActionFor(student,'admit') 536 else: 537 wftool.doActionFor(student,'pume_fail') 538 wftool.doActionFor(student,'reject_admission') 539 continue 540 # 541 # Clearance 542 # 543 student.invokeFactory('StudentClearance','clearance') 544 #wftool.doActionFor(student.clearance,'open') 545 dp = {'Title': 'Clearance/Eligibility Record'} 546 student.clearance.manage_setLocalRoles(sid, ['Owner',]) 547 # 548 # Study Course 549 # 550 student.invokeFactory('StudentStudyCourse','study_course') 551 study_course = student.study_course 552 dsc = {} 553 from_certificate = ['title', 554 'max_elect', 555 'max_pass', 556 'n_core', 557 'nr_years', 558 'probation_credits', 559 'promotion_credits', 560 'start_level', 561 ] 562 for f in from_certificate: 563 dsc[f] = getattr(cert_doc,f) 564 dsc['faculty'] = jamb.get(csv_d['faculty']) 565 dsc['department'] = jamb.get(csv_d['department']) 566 catalog_entry['faculty'] = jamb.get(csv_d['faculty']) 567 catalog_entry['department'] = jamb.get(csv_d['department']) 568 catalog_entry['course'] = cert_id 569 catalog_entry['level'] = getattr(cert_doc,'start_level') 570 dsc['study_course'] = cert_id 571 dsc['entry_session'] = jamb.get(csv_d['session']) 572 study_course.getContent().edit(mapping=dsc) 573 self.students_catalog.addRecord(**catalog_entry) 574 if tr_count > 5: 575 if len(no_import) > 1: 576 open("%s/import/%s_not_imported.csv" % (i_home,name),"w+").write( 577 '\n'.join(no_import)) 578 no_import = [] 579 em = '%d transactions commited\n' % tr_count 580 transaction.commit() 581 logger.info(em) 582 total += tr_count 583 tr_count = 0 584 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 585 ###) 586 371 587 security.declareProtected(ModifyPortalContent,"createNewStudents")###( 372 588 def createNewStudents(self): … … 403 619 format = '"%(Error)s",' + ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 404 620 no_certificate = "no certificate %s" % format 405 open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write( 406 '\n'.join(no_import)) 621 open("%s/import/%s_not_imported.csv" % (i_home,name),"w").write('\n'.join(no_import)) 407 622 logger = logging.getLogger('Import.%s' % name) 408 logger.info(' Start loading from %s.csv' % name)623 logger.info('start loading from %s.csv' % name) 409 624 l = self.portal_catalog({'meta_type': "Certificate"}) 410 625 certs = {} … … 436 651 no_import.append( format % jamb) 437 652 continue 653 res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no) 654 if len(res) == 1: 655 self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no, 656 status = jamb.get(csv_d['stud_status']), 657 ) 658 jamb_reg_no =jamb.get(csv_d['jamb_reg_no']) 438 659 cert_doc = certs[cert_id] 439 660 catalog_entry = {}
Note: See TracChangeset for help on using the changeset viewer.