Changeset 1707
- Timestamp:
- 25 Apr 2007, 11:58:39 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1700 r1707 428 428 app = student.application 429 429 app_doc = app.getContent() 430 picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no)431 430 #import pdb;pdb.set_trace() 431 picture ="%s/import/pictures/%s.jpg" % (i_home,picture_id) 432 432 if os.path.exists(picture): 433 433 file = open(picture) … … 538 538 ###) 539 539 540 security.declareProtected(ModifyPortalContent,"create NewStudents")###(541 def create ParttimeStudents(self):542 """load ParttimeStudentdata from CSV values"""540 security.declareProtected(ModifyPortalContent,"createStudents")###( 541 def createStudents(self): 542 """load Studentdata from CSV values""" 543 543 import transaction 544 544 import random … … 546 546 wftool = self.portal_workflow 547 547 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 548 csv_d = {'jamb_reg_no': "Reg_No", 549 'jamb_firstname': "Firstname", 550 'jamb_middlename': "Middlename", 551 'jamb_lastname': "Lastname", 552 'jamb_sex': "Sex", 553 'entry_mode': 'Entry_mode', 554 'jamb_age': "Age", 555 'jamb_state': "State", 556 ## 'jamb_first_cos': "AdminCourse", 557 'faculty': "AdminFaculty", 558 'course_code': "AdmitCoscode", 559 'stud_status':"AdmitStatus", 560 'department': "AdmitDept", 561 'jamb_lga': "LGA", 548 csv_d = {'jamb_reg_no': "reg_no", 549 'entry_mode': 'entry_mode', 550 'jamb_firstname': "firstname", 551 'jamb_middlename': "middlename", 552 'jamb_lastname': "lastname", 553 'jamb_sex': "sex", 554 'jamb_state': "state", 555 'birthday': "date_of_birth", 562 556 'app_email': "email", 563 'app_mobile': "PhoneNumbers", 557 'study_course': "study_course", 558 'perm_address': "address", 564 559 } 565 560 csv_fields = [f[1] for f in csv_d.items()] … … 576 571 logger = logging.getLogger('Students.StudentsFolder.createNewStudents') 577 572 logger.info('Start loading from %s.csv' % name) 578 l = self.portal_catalog({'meta_type': "Certificate"})579 573 certs = {} 580 cert_docs = {}581 for f in l:582 certs[f.getId] = f.getObject().getContent()583 574 try: 584 result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb"))575 results = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 585 576 except: 586 577 logger.error('Error reading %s.csv' % name) 587 578 return 588 for jamb in result: 589 jamb['Error'] = "Processing " 590 logger.info(format % jamb) 591 jamb_reg_no = jamb.get(csv_d['jamb_reg_no']) 592 res = self.portal_catalog({'portal_type': "StudentApplication", 593 'SearchableText': jamb_reg_no }) 579 for result in results: 580 #result['Error'] = "Processing " 581 #logger.info(format % result) 582 jamb_reg_no = result.get(csv_d['jamb_reg_no']) 583 res = self.students_catalog(jamb_reg_no = jamb_reg_no) 594 584 if res: 595 585 em = 'Student with RegNo %s already exists\n' % jamb_reg_no 596 586 logger.info(em) 597 jamb['Error'] = "Student exists"598 no_import.append(format % jamb)599 continue 600 cert_id = makeCertificateCode( jamb.get(csv_d['course_code']))587 result['Error'] = "Student exists" 588 no_import.append(format % result) 589 continue 590 cert_id = makeCertificateCode(result.get(csv_d['study_course'])) 601 591 if cert_id not in certs.keys(): 602 em = 'No Certificate with ID %s \n' % cert_id603 logger.info(em)604 jamb['Error'] = "No Certificate %s"% cert_id605 no_import.append( format % jamb)606 continue607 res = self.portal_pumeresults(jamb_reg_no = jamb_reg_no)608 if len(res) == 1:609 self.portal_pumeresults.modifyRecord(jamb_reg_no = jamb_reg_no,610 status = jamb.get(csv_d['stud_status']),611 )612 jamb_reg_no =jamb.get(csv_d['jamb_reg_no'])592 res = self.portal_catalog(meta_type = "Certificate",id = cert_id) 593 if not res: 594 em = 'No Certificate with ID %s \n' % cert_id 595 logger.info(em) 596 result['Error'] = "No Certificate %s" % cert_id 597 no_import.append( format % result) 598 continue 599 cert = res[0] 600 cert_path = cert.getPath().split('/') 601 certificate = certs[cert_id] = {'faculty': cert_path[-4], 602 'department': cert_path[-3]} 613 603 cert_doc = certs[cert_id] 614 604 catalog_entry = {} 615 605 catalog_entry['jamb_reg_no'] = jamb_reg_no 616 jamb_name = jamb.get(csv_d['jamb_lastname']) 617 jamb_name.replace('>','') 618 jamb_name.replace('<','') 619 names = jamb_name.split() 620 letter = names[-1][0].upper() 621 sid = self.generateStudentId(letter) 622 not_created = True 623 while not_created: 624 try: 625 students_folder.invokeFactory('Student', sid) 626 not_created = False 627 except BadRequest: 628 sid = self.generateStudentId(letter) 606 firstname = result.get(csv_d['jamb_firstname']) 607 middlename = result.get(csv_d['jamb_middlename']) 608 lastname = result.get(csv_d['jamb_lastname']) 609 sid = self.generateStudentId('x') 610 students_folder.invokeFactory('Student', sid) 629 611 catalog_entry['id'] = sid 630 612 tr_count += 1 … … 632 614 student = getattr(self,sid) 633 615 student.manage_setLocalRoles(sid, ['Owner',]) 634 student.invokeFactory('StudentPume','pume')635 dp = {'Title': 'Pume Data'}636 616 student.invokeFactory('StudentApplication','application') 637 617 da = {'Title': 'Application Data'} 638 da["jamb_lastname"] = jamb_name 618 da["jamb_firstname"] = firstname 619 da["jamb_middlename"] = middlename 620 da["jamb_lastname"] = lastname 621 catalog_entry['entry_session'] = da["entry_session"] = self.getSessionId()[-2:] 622 catalog_entry['entry_level'] = da["entry_level"] = 'NA' 623 catalog_entry['sex'] = sex = result.get(csv_d['jamb_sex']).startswith('F') 639 624 da_fields = ('jamb_reg_no', 640 625 'jamb_sex', 641 #'jamb_state',642 'jamb_score',643 ## 'jamb_first_cos',644 'jamb_sex',645 626 'jamb_state', 646 ' jamb_lga',627 'entry_mode', 647 628 'app_email', 648 'app_mobile',649 629 ) 650 630 for f in da_fields: 651 da[f] = jamb.get(csv_d[f]) 652 catalog_entry['email'] = jamb.get(csv_d['app_email']) 631 da[f] = result.get(csv_d[f]) 632 catalog_entry['email'] = da['app_email'] 633 catalog_entry['entry_mode'] = da['entry_mode'] 653 634 app = student.application 654 635 app_doc = app.getContent() 636 app.getContent().edit(mapping=da) 655 637 picture ="%s/import/pictures/%s.jpg" % (i_home,jamb_reg_no) 656 #import pdb;pdb.set_trace() 657 if os.path.exists(picture): 658 file = open(picture) 659 if False: 660 img = PIL.Image.open(file) 661 img.thumbnail((150,200), 662 resample=PIL.Image.ANTIALIAS) 663 # We now need a buffer to write to. It can't be the same 664 # as the inbuffer as the PNG writer will write over itself. 665 outfile = StringIO() 666 img.save(outfile, format=img.format) 667 else: 668 outfile = file.read() 638 app.manage_setLocalRoles(sid, ['Owner',]) 639 picture_id = da['jamb_reg_no'].replace('/','_') 640 file = None 641 for ext in ('jpg','JPG'): 642 picture ="%s/import/pictures/%s.%s" % (i_home,picture_id,ext) 643 if os.path.exists(picture): 644 file = open(picture) 645 break 646 if file is not None: 647 outfile = file.read() 669 648 app_doc.manage_addFile('passport', 670 649 file=outfile, 671 650 title="%s.jpg" % jamb_reg_no) 672 app.getContent().edit(mapping=da)673 app.manage_setLocalRoles(sid, ['Owner',])674 651 #wftool.doActionFor(app,'close') 675 dp_fields = (676 #'pume_eng_score',677 #'pume_gen_score',678 'pume_tot_score',679 )680 dp['pume_tot_score'] = jamb.get(csv_d['pume_tot_score']) or "No Option Shaded"681 pume = student.pume682 pume.getContent().edit(mapping=dp)683 #wftool.doActionFor(pume,'close')684 pume.manage_setLocalRoles(sid, ['Owner',])685 #student.getContent().createSubObjects()686 652 dp = {} 687 if len(names) == 3: 688 dp['firstname'] = names[0].capitalize() 689 dp['middlename'] = names[1].capitalize() 690 dp['lastname'] = names[2].capitalize() 691 elif len(names) == 2: 692 dp['firstname'] = names[0].capitalize() 693 dp['middlename'] = '' 694 dp['lastname'] = names[1].capitalize() 695 else: 696 dp['firstname'] = '' 697 dp['middlename'] = '' 698 dp['lastname'] = jamb_name 699 dp['sex'] = jamb.get(csv_d['jamb_sex']) == 'F' 700 catalog_entry['sex'] = dp['sex'] 653 dp['firstname'] = firstname 654 dp['middlename'] = middlename 655 dp['lastname'] = lastname 656 dp['email'] = da['app_email'] 657 dp['sex'] = sex 701 658 catalog_entry['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp 702 659 student.invokeFactory('StudentPersonal','personal') … … 705 662 per_doc.edit(mapping = dp) 706 663 per.manage_setLocalRoles(sid, ['Owner',]) 707 if jamb.get(csv_d['stud_status']) == "Admitted": 708 wftool.doActionFor(student,'pume_pass') 709 wftool.doActionFor(student,'admit') 710 else: 711 wftool.doActionFor(student,'pume_fail') 712 wftool.doActionFor(student,'reject_admission') 713 continue 664 wftool.doActionFor(student,'pume_pass') 665 wftool.doActionFor(student,'admit') 714 666 # 715 667 # Clearance … … 717 669 student.invokeFactory('StudentClearance','clearance') 718 670 #wftool.doActionFor(student.clearance,'open') 719 dp = {'Title': 'Clearance/Eligibility Record'} 720 student.clearance.manage_setLocalRoles(sid, ['Owner',]) 671 clearance = student.clearance 672 dc = {'Title': 'Clearance/Eligibility Record'} 673 clearance = student.clearance 674 date_str = result.get(csv_d['birthday']) 675 date = DateTime.DateTime(date_str) 676 dc['birthday'] = date 677 clearance.getContent().edit(mapping=dc) 678 clearance.manage_setLocalRoles(sid, ['Owner',]) 721 679 # 722 680 # Study Course … … 725 683 study_course = student.study_course 726 684 dsc = {} 727 #from_certificate = ['title',728 # 'max_elect',729 # 'max_pass',730 # 'n_core',731 # 'nr_years',732 # 'probation_credits',733 # 'promotion_credits',734 # 'start_level',735 # ]736 #for f in from_certificate:737 # dsc[f] = getattr(cert_doc,f)738 #dsc['faculty'] = jamb.get(csv_d['faculty'])739 #dsc['department'] = jamb.get(csv_d['department'])740 catalog_entry['faculty'] = jamb.get(csv_d['faculty'])741 catalog_entry['department'] = jamb.get(csv_d['department'])742 catalog_entry['course'] = cert_id743 685 #catalog_entry['level'] = getattr(cert_doc,'start_level') 744 catalog_entry['level'] = '100' 745 dsc['study_course'] = cert_id 746 dsc['entry_level'] = '100' 747 #dsc['entry_session'] = jamb.get(csv_d['session']) 686 catalog_entry['session'] = dsc['current_session'] = da['entry_session'] 687 catalog_entry['level'] = dsc['current_level'] = 'NA' 688 catalog_entry['mode'] = dsc['current_mode'] = da['entry_mode'] 689 catalog_entry['course'] = dsc['study_course'] = cert_id 690 catalog_entry['faculty'] = certificate['faculty'] 691 catalog_entry['department'] = certificate['department'] 692 catalog_entry['verdict'] = dsc['current_verdict'] = 'NA' 693 catalog_entry['review_state'] = self.portal_workflow.getInfoFor(student,'review_state',None) 748 694 study_course.getContent().edit(mapping=dsc) 695 #import pdb;pdb.set_trace() 749 696 self.students_catalog.addRecord(**catalog_entry) 750 697 if tr_count > 10: -
WAeUP_SRP/trunk/WAeUPTables.py
r1705 r1707 231 231 key = "id" 232 232 affected_types = { ###( 233 'StudentApplication': 233 'StudentApplication': 234 {'id': 'application', 235 'fields': 234 236 ('jamb_reg_no', 235 237 'entry_mode', 238 'entry_level', 236 239 'entry_session', 237 ), 240 ) 241 }, 238 242 'StudentClearance': 243 {'id': 'clearance', 244 'fields': 239 245 ('matric_no', 240 ), 246 ) 247 }, 241 248 'StudentPersonal': 249 {'id': 'personal', 250 'fields': 242 251 ('name', 243 252 'sex', 244 253 'email', 245 254 'phone', 246 ), 255 ) 256 }, 247 257 'StudentStudyCourse': 258 {'id': 'study_course', 259 'fields': 248 260 ('course', 249 261 'faculty', … … 253 265 'session', 254 266 'verdict', 255 ), 267 ) 268 }, 256 269 } 257 270 ###) … … 380 393 else: 381 394 for pt in self.affected_types.keys(): 382 if n in self.affected_types[pt] :395 if n in self.affected_types[pt]['fields']: 383 396 if reindextypes.has_key(pt): 384 397 reindextypes[pt].append(n) … … 395 408 if pghandler: pghandler.report(i) 396 409 student_brain = students[i] 410 student_object = student_brain.getObject() 397 411 data = {} 398 412 modified = False … … 401 415 modified = True 402 416 data['review_state'] = student_brain.review_state 403 if reindextypes: 404 query = Eq('path',student_brain.getPath()) 405 sub_brains = aq_portal(query) 417 sub_objects = False 418 for pt in reindextypes.keys(): 406 419 modified = True 407 spath = student_brain.getPath()408 if len(sub_brains) > 1:409 for sub_brain in sub_brains:410 if not sub_brain.portal_type in reindextypes.keys():411 412 doc = sub_brain.getObject().getContent()413 for field in self.affected_types[sub_brain.portal_type]:414 if hasattr(self,'get_from_doc_%s' % field):415 data[field] = getattr(self,'get_from_doc_%s' % field)(doc)416 else:417 data[field] = getattr(doc,field)418 elif len(sub_brains) == 1and noattr:419 420 421 422 423 424 425 426 427 428 420 try: 421 doc = getattr(student_object,self.affected_types[pt]['id']).getContent() 422 sub_objects = True 423 except: 424 continue 425 for field in self.affected_types[pt]['fields']: 426 if hasattr(self,'get_from_doc_%s' % field): 427 data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 428 else: 429 data[field] = getattr(doc,field) 430 #from pdb import set_trace;set_trace() 431 if not sub_objects and noattr: 432 import_res = self.returning_import(id = sid) 433 if not import_res: 434 continue 435 import_record = import_res[0] 436 data['matric_no'] = import_record.matric_no 437 data['sex'] = import_record.Sex == 'F' 438 data['name'] = "%s %s %s" % (import_record.Firstname, 439 import_record.Middlename, 440 import_record.Lastname) 441 data['matric_no'] = import_record.Entryregno 429 442 if reindex_special and 'registered_courses' in reindex_special: 430 443 query = Eq('id','study_course') & Eq('path',student_brain.getPath()) … … 480 493 sid = data['id'] = student_brain.getId 481 494 data['review_state'] = student_brain.review_state 482 sub_brains = self.portal_catalog(path = spath) 483 if len(sub_brains) > 1: 484 for sub_brain in sub_brains: 485 if not sub_brain.portal_type in self.affected_types.keys(): 486 continue 487 doc = sub_brain.getObject().getContent() 488 for field in self.affected_types[sub_brain.portal_type]: 489 if hasattr(self,'get_from_doc_%s' % field): 490 data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 491 else: 492 data[field] = getattr(doc,field) 493 elif len(sub_brains) == 1: 494 #import pdb;pdb.set_trace() 495 sub_objects = False 496 for pt in self.affected_types.keys(): 497 modified = True 498 try: 499 doc = getattr(student_object,self.affected_types[pt]['id']).getContent() 500 sub_objects = True 501 except: 502 continue 503 for field in self.affected_types[pt]['fields']: 504 if hasattr(self,'get_from_doc_%s' % field): 505 data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 506 else: 507 data[field] = getattr(doc,field) 508 #from pdb import set_trace;set_trace() 509 if not sub_objects and noattr: 495 510 import_res = self.returning_import(id = sid) 496 511 if not import_res: … … 503 518 import_record.Lastname) 504 519 data['matric_no'] = import_record.Entryregno 520 ## sub_brains = self.portal_catalog(path = spath) 521 ## if len(sub_brains) > 1: 522 ## for sub_brain in sub_brains: 523 ## if not sub_brain.portal_type in self.affected_types.keys(): 524 ## continue 525 ## doc = sub_brain.getObject().getContent() 526 ## for field in self.affected_types[sub_brain.portal_type]: 527 ## if hasattr(self,'get_from_doc_%s' % field): 528 ## data[field] = getattr(self,'get_from_doc_%s' % field)(doc) 529 ## else: 530 ## data[field] = getattr(doc,field) 531 ## elif len(sub_brains) == 1: 532 ## #import pdb;pdb.set_trace() 533 ## import_res = self.returning_import(id = sid) 534 ## if not import_res: 535 ## continue 536 ## import_record = import_res[0] 537 ## data['matric_no'] = import_record.matric_no 538 ## data['sex'] = import_record.Sex == 'F' 539 ## data['name'] = "%s %s %s" % (import_record.Firstname, 540 ## import_record.Middlename, 541 ## import_record.Lastname) 542 ## data['matric_no'] = import_record.Entryregno 505 543 study_course = getattr(student_obj,'study_course',None) 506 544 current_level = data.get('level',None) … … 548 586 return 549 587 elif pt == 'CourseResult' and mt == 'CPS Proxy Folder': 550 from pdb import set_trace;set_trace() 551 588 pass 552 589 if event_type not in ('sys_modify_object'): 553 from pdb import set_trace;set_trace()590 #from pdb import set_trace;set_trace() 554 591 return 555 592 if mt == 'CPS Proxy Folder': -
WAeUP_SRP/trunk/WAeUPTool.py
r1700 r1707 42 42 import transaction 43 43 import csv,re,os 44 44 from Products.AdvancedQuery import Eq, Between, Le,In 45 46 def getObject(object,name): 47 if object.hasObject(name): 48 return getattr(object,name) 49 return None 50 45 51 class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase): 46 52 """WAeUP tool""" … … 57 63 ) 58 64 65 def rwrite(self,s): 66 response = self.REQUEST.RESPONSE 67 response.setHeader('Content-type','text/html; charset=ISO-8859-15') 68 response.write("%s<br />\r\n" % s) 59 69 60 70 def generateStudentId(self,letter): ###( -
WAeUP_SRP/trunk/profiles/default/schemas/student_application.xml
r1705 r1707 8 8 <field name="entry_mode" meta_type="CPS String Field"/> 9 9 <field name="entry_session" meta_type="CPS String Field"/> 10 <field name="entry_level" meta_type="CPS String Field"/> 10 11 <field name="objection_date" meta_type="CPS DateTime Field"/> 11 12 <field name="jamb_age" meta_type="CPS Int Field"/> -
WAeUP_SRP/trunk/profiles/default/students_catalog.xml
r1705 r1707 40 40 <indexed_attr value="level"/> 41 41 </index> 42 <index name="entry_level" meta_type="FieldIndex"> 43 <indexed_attr value="entry_level"/> 44 </index> 42 45 <index name="mode" meta_type="FieldIndex"> 43 46 <indexed_attr value="mode"/> … … 64 67 <column value="email"/> 65 68 <column value="phone"/> 69 <column value="entry_level"/> 66 70 <column value="level"/> 67 71 <column value="mode"/> -
WAeUP_SRP/trunk/skins/waeup_default/getSessionId.py
r1440 r1707 15 15 now = DateTime.DateTime() 16 16 if now.month() > 7: 17 return "%s" % now.year() 18 return "%s" % (now.year() - 1) 17 s = "%s" % now.year() 18 else: 19 s = "%s" % (now.year() - 1) 20 return s -
WAeUP_SRP/trunk/skins/waeup_utilities/setNewEntryMode.py
r1706 r1707 23 23 setheader = request.RESPONSE.setHeader 24 24 students = context.portal_url.getPortalObject().campus.students 25 import logging 26 logger = logging.getLogger('Skins.setNewEntryMode') 25 27 26 28 def rwrite(s): … … 30 32 brains = context.portal_catalog(portal_type = 'Student') 31 33 count = 0 34 commit_count = 0 32 35 #set_trace() 36 logger.info('setNewEntryMode start') 33 37 for brain in brains: 34 38 stud_obj = brain.getObject() 35 39 try: 36 40 app_doc = stud_obj.application.getContent() 37 try:38 sc_doc = stud_obj.study_course.getContent()39 except:40 sc_doc = None41 41 except: 42 42 continue 43 try: 44 sc_doc = stud_obj.study_course.getContent() 45 except: 46 sc_doc = None 43 47 em = getattr(app_doc,'entry_mode',None) 44 new_em = "%s_ft" % em.lower() 45 app_doc.edit(mapping={'entry_mode': new_em}) 48 if em in ('ume_ft','de_ft'): 49 new_em = em 50 else: 51 new_em = "%s_ft" % em.lower() 52 if em in ('ume_ft','UME'): 53 el = "100" 54 elif em in ('de_ft','DE'): 55 el = "200" 56 app_doc.edit(mapping={'entry_mode': new_em, 57 'entry_level': el}) 58 sid = brain.getId 46 59 if sc_doc: 47 60 sc_doc.edit(mapping={'current_mode': new_em}) 61 context.students_catalog.modifyRecord(id = sid, 62 mode=new_em, 63 entry_mode=new_em, 64 entry_level=el) 65 else: 66 context.students_catalog.modifyRecord(id = sid, 67 entry_mode=new_em, 68 entry_level=el) 69 48 70 count += 1 71 commit_count += 1 72 if commit_count > 1000: 73 context.waeup_tool.doCommit() 74 logger.info('committing %d total %d' % (commit_count,count)) 75 commit_count = 0 49 76 s = "%d: %s %s -> %s" % (count,brain.getPath(),em,new_em) 50 77 rwrite(s) 51 78 rwrite('Done') 79 logger.info('setNewEntryMode finish') 52 80 53 81
Note: See TracChangeset for help on using the changeset viewer.