Changeset 1673 for WAeUP_SRP/branches
- Timestamp:
- 9 Apr 2007, 16:01:51 (18 years ago)
- Location:
- WAeUP_SRP/branches/joachim-event-branch
- Files:
-
- 4 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/branches/joachim-event-branch/WAeUPTables.py
r1596 r1673 278 278 ###) 279 279 280 class OnlinePaymentsImport(WAeUPTable): ###( 281 282 meta_type = 'WAeUP Online Payment Transactions' 283 name = "online_payments_import" 284 key = "order_id" 285 def __init__(self): 286 WAeUPTable.__init__(self, self.name) 287 288 289 InitializeClass(CoursesCatalog) 290 ###) 291 280 292 class ReturningImport(WAeUPTable): ###( 281 293 -
WAeUP_SRP/branches/joachim-event-branch/WAeUPTool.py
r1596 r1673 532 532 ###) 533 533 534 security.declareProtected(ModifyPortalContent,"getInvalidCallbackTransactions")###( 535 def getCallbacksFromLog(self,filename): 536 """fix Online Payment Transactions from Z2.log entries""" 537 import transaction 538 import random 539 from cgi import parse_qs 540 from urlparse import urlparse 541 #from pdb import set_trace 542 wftool = self.portal_workflow 543 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 544 students_folder = self.portal_url.getPortalObject().campus.students 545 s = r'(?P<client_ip>\S+) - (?P<member_id>\S+) \[' 546 s += r'(?P<date>.*)\] "(?P<get>.*)" (?P<codes>\d+ \d+) "' 547 s += r'(?P<intersw>.*)" "(?P<agent>.*)"' 548 data = re.compile(s) 549 start = True 550 tr_count = 1 551 total = 0 552 #name = 'pume_results' 553 #name = 'epaymentsuccessful_z2log2' 554 name = filename 555 no_import = [] 556 imported = [] 557 logger = logging.getLogger('WAeUPTool.getFailedTransactions') 558 try: 559 transactions = open("%s/import/%s" % (i_home,name),"rb").readlines() 560 except: 561 logger.error('Error reading %s' % name) 562 return 563 tas = [] 564 for line in transactions: 565 dict = {} 566 items = data.search(line) 567 dict['idict'] = idict = items.groupdict() 568 #print idict 569 #from pdb import set_trace;set_trace() 570 urlparsed = urlparse(idict['get'][4:]) 571 #print urlparsed 572 path = urlparsed[2].split('/') 573 dict['student_id'] = student_id = path[8] 574 dict['payment_id'] = payment_id = path[10] 575 dict['qs_dict'] = qs_dict = parse_qs(urlparsed[4]) 576 tas.append(dict) 577 tr_count += 1 578 return tas 579 ###) 580 581 security.declareProtected(ModifyPortalContent,"importOnlinePaymentTransactions")###( 582 def importOnlinePaymentTransactions(self): 583 """load Online Payment Transactions from CSV values""" 584 import transaction 585 import random 586 #from pdb import set_trace 587 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 588 opt = self.online_payments_import 589 students_folder = self.portal_url.getPortalObject().campus.students 590 start = True 591 tr_count = 1 592 total = 0 593 #name = 'pume_results' 594 name = 'OnlineTransactions' 595 no_import = [] 596 imported = [] 597 logger = logging.getLogger('WAeUPTool.importOnlinePaymentTransactions') 598 try: 599 transactions = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 600 except: 601 logger.error('Error reading %s.csv' % name) 602 return 603 for pay_transaction in transactions: 604 if start: 605 start = False 606 logger.info('Start loading from %s.csv' % name) 607 s = ','.join(['"%s"' % fn for fn in pay_transaction.keys()]) 608 no_import.append('%s,"Error"' % s) 609 format = ','.join(['"%%(%s)s"' % fn for fn in pay_transaction.keys()]) 610 format_error = format + ',"%(Error)s"' 611 data = {} 612 613 # format of the first file sent from Tayo 614 #data['datetime'] = date = DateTime.DateTime(pay_transaction['Date']) 615 #data['student_id'] = student_id = pay_transaction['Payer ID'] 616 #data['order_id'] = order_id = pay_transaction['Order ID (Tranx Ref)'] 617 #data['response_code'] = response_code = pay_transaction['Resp Code'] 618 #data['amount'] = amount = pay_transaction['Amount'] 619 620 # format of the second file sent from Tayo 621 data['datetime'] = date = 0 622 data['student_id'] = student_id = pay_transaction['Payer ID'] 623 data['order_id'] = order_id = pay_transaction['Order ID (Tranx Ref)'] 624 data['response_code'] = response_code = '00' 625 data['amount'] = amount = pay_transaction['Amount'] 626 627 dup = False 628 if response_code == "12": 629 continue 630 try: 631 opt.addRecord(**data) 632 except ValueError: 633 dup = True 634 #from pdb import set_trace;set_trace() 635 if dup: 636 if response_code == "00": 637 opt.modifyRecord(**data) 638 else: 639 pay_transaction['Error'] = "Duplicate order Id" 640 no_import.append( format_error % pay_transaction) 641 logger.info("dupplicate order_id %(order_id)s for %(student_id)s %(response_code)s" % data) 642 continue 643 tr_count += 1 644 if tr_count > 1000: 645 if len(no_import) > 0: 646 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 647 '\n'.join(no_import) + '\n') 648 no_import = [] 649 em = '%d transactions committed\n' % (tr_count) 650 transaction.commit() 651 regs = [] 652 logger.info(em) 653 total += tr_count 654 tr_count = 0 655 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 656 '\n'.join(no_import)) 657 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 658 ###) 659 534 660 InitializeClass(WAeUPTool) -
WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/getNewStudentStatistics.py
r1596 r1673 12 12 return Student Statistics 13 13 """ 14 try: 15 from Products.zdb import set_trace 16 except: 17 def set_trace(): 18 pass 14 19 import logging 15 20 logger = logging.getLogger('Skins.getNewStudentStatistics') 16 21 17 22 try: 18 from Products.AdvancedQuery import Eq, Between, Le,In, Ge 23 from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp 19 24 aq_portal = context.portal_catalog.evalAdvancedQuery 20 25 aq_students = context.students_catalog.evalAdvancedQuery 21 26 except: 22 27 evalAdvancedQuery = None 28 29 def intersect(m,n): 30 return [i for i in m if i in n] 31 23 32 logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember()) 24 l = []25 33 if not context.isStaff(): 26 34 return l 27 dep= {}35 total_dict = {} 28 36 29 dep['id'] = "All Faculties"37 total_dict['id'] = "All Faculties" 30 38 31 freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE')) 32 total_new = aq_students(freshquery) 33 total_new = float(len(total_new)) 34 dep['new'] = "%.0f" % total_new 35 36 37 #from Products.zdb import set_trace;set_trace() 38 39 adm_res = context.portal_catalog(review_state ='admitted') 40 adm_ids = [r.getId for r in adm_res] 41 adm = len(adm_res) 42 dep['admitted'] = adm 43 dep['admitted_percent'] = "%.0f" % round(adm*100/total_new) 44 45 cpe_res = context.portal_catalog(review_state ='clearance_pin_entered') 46 cpe_ids = [r.getId for r in cpe_res] 47 cpe = len(cpe_res) 48 dep['clearance_pin_entered'] = cpe 49 dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total_new) 50 51 cr_res = context.portal_catalog(review_state='clearance_requested') 52 cr_ids = [r.getId for r in cr_res] 53 cr = len(cr_res) 54 dep['clearance_requested'] = cr 55 dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total_new) 56 57 cav_res = context.portal_catalog(review_state ='cleared_and_validated') 58 cav_ids = [r.getId for r in cav_res] 59 cav = len(cav_res) 60 dep['cleared_and_validated'] = cav 61 dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total_new) 62 63 or_res = context.portal_catalog(review_state='objection_raised') 64 or_ids = [r.getId for r in or_res] 65 ora = len(or_res) 66 dep['objection_raised'] = ora 67 dep['objection_raised_percent'] = "%.0f" % round(ora*100/total_new) 68 69 total_sfp = total_new - (cav + cr + cpe + adm + ora) 70 dep['rest'] = int(total_sfp) 71 dep['rest_percent'] = "%.0f" % round(total_sfp*100/total_new) 72 73 74 l.append(dep) 75 fs = context.portal_catalog(portal_type="Faculty") 76 for fid in [f.getId for f in fs]: 77 dep = {} 78 dep['id'] = fid 79 fquery = Eq('faculty',fid) 80 fac_res = aq_students(fquery & freshquery) 81 fac_ids = [r.id for r in fac_res] 82 total = float(len(fac_res)) 83 84 if total == 0: 85 continue 86 87 dep['new'] = "%.0f" % total 88 89 adm = len([s for s in fac_ids if s in adm_ids]) 90 dep['admitted'] = adm 91 dep['admitted_percent'] = 0 92 if total: 93 dep['admitted_percent'] = "%.0f" % round(adm*100/total) 94 95 cpe = len([s for s in fac_ids if s in cpe_ids]) 96 dep['clearance_pin_entered'] = cpe 97 dep['clearance_pin_entered_percent'] = 0 98 if total: 99 dep['clearance_pin_entered_percent'] = "%.0f" % round(cpe*100/total) 100 cr = len([s for s in fac_ids if s in cr_ids]) 101 dep['clearance_requested'] = cr 102 dep['clearance_requested_percent'] = 0 103 if total: 104 dep['clearance_requested_percent'] = "%.0f" % round(cr*100/total) 105 cav = len([s for s in fac_ids if s in cav_ids]) 106 dep['cleared_and_validated'] = cav 107 dep['cleared_and_validated_percent'] = 0 108 if total: 109 dep['cleared_and_validated_percent'] = "%.0f" % round(cav*100/total) 110 111 ora = len([s for s in fac_ids if s in or_ids]) 112 dep['objection_raised'] = ora 113 dep['objection_raised_percent'] = 0 114 if total: 115 dep['objection_raised_percent'] = "%.0f" % round(ora*100/total) 116 117 rest = int(total - (cav + cr + cpe + adm + ora)) 118 dep['rest'] = rest 119 dep['rest_percent'] = "%.0f" % round(rest*100/total) 120 121 l.append(dep) 39 ##freshquery = Eq('level','100') | (Eq('level','200') & Eq('entry_mode','DE')) 40 ##total_new = aq_students(freshquery) 41 ##total_new = float(len(total_new)) 42 newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*') 43 total_res = aq_portal(newquery) 44 new_ids = [r.getPath().split('/')[-2] for r in total_res] 45 total_new = float(len(total_res)) 46 total_dict['new'] = "%.0f" % total_new 47 special_states = ('admitted', 48 'clearance_pin_entered', 49 'clearance_requested', 50 'cleared_and_validated', 51 'objection_raised', 52 ) 53 state_count = 0 54 state_ids = {} 55 for state in special_states: 56 res = context.portal_catalog(review_state = state) 57 ids = [r.getId for r in res] 58 state_ids[state] = ids 59 count = len(res) 60 state_count += count 61 total_dict[state] = count 62 total_dict['%s_percent' % state] = "%.0f" % round(count*100/total_new) 63 total_dict['rest'] = "%.0f" % (total_new - state_count) 64 total_dict['rest_percent'] = "%.0f" % round((total_new - state_count)*100/total_new) 65 fac_res = {} 66 #fac_res['total'] = total_dict 67 faculties = context.portal_catalog(portal_type="Faculty") 68 for f in faculties: 69 dict = {} 70 dict['id'] = f.getId 71 dict['title'] = f.Title 72 sid_in_faculty = [s.id for s in context.students_catalog(faculty=f.getId)] 73 new_in_faculty = intersect(new_ids,sid_in_faculty) 74 dict['new'] = rest = len(new_in_faculty) 75 for state in special_states: 76 state_count = len(intersect(state_ids[state], new_in_faculty)) 77 rest -= state_count 78 dict[state] = state_count 79 dict['rest'] = rest 80 fac_res[f.getId] = dict 81 #set_trace() 82 ##for sid,review_state in new_ids: 83 ## scat_res = context.students_catalog(id = sid) 84 ## if not scat_res: 85 ## continue 86 ## student = scat_res[0] 87 ## faculty = student.faculty 88 ## if not fac_res.has_key(faculty): 89 ## continue 90 ## if review_state in special_states: 91 ## fac_res[faculty][review_state] = fac_res[faculty][review_state] + 1 92 ## else: 93 ## fac_res[faculty]['rest'] = fac_res[faculty]['rest'] + 1 94 l = [] 95 l.append(total_dict) 96 fac_ids = [f.getId for f in faculties] 97 fac_ids.sort() 98 check_dict = {} 99 check_dict['id'] = 'Check' 100 check_dict['new'] = 0 101 check_dict['new_percent'] = 0 102 check_dict['rest'] = 0 103 check_dict['rest_percent'] = 0 104 for state in special_states: 105 check_dict[state] = 0 106 check_dict["%s_percent" % state] = 0 107 108 for f in fac_ids: 109 total_fac = fac_res[f]['new'] 110 check_dict['new'] = check_dict['new'] + total_fac 111 check_dict['rest'] = check_dict['rest'] + fac_res[f]['rest'] 112 for state in special_states: 113 check_dict[state] = check_dict[state] + fac_res[f][state] 114 if total_fac != 0: 115 fac_res[f]['%s_percent' % state] = "%.0f" % round(fac_res[f][state]*100/total_fac) 116 else: 117 fac_res[f]['%s_percent' % state] = "%.0f" % 0.0 118 if total_fac != 0: 119 fac_res[f]['rest_percent'] = "%.0f" % round(fac_res[f]['rest']*100/total_fac) 120 else: 121 fac_res[f]['rest_percent'] = "%.0f" % 0.0 122 l.append(fac_res[f]) 123 l.append(check_dict) 122 124 123 125 return l -
WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/list_students.py
r1312 r1673 12 12 export student_list 13 13 """ 14 try: 15 from Products.zdb import set_trace 16 except: 17 def set_trace(): 18 pass 19 from Products.AdvancedQuery import Eq, Between, Le,In,MatchRegexp 20 aq_portal = context.portal_catalog.evalAdvancedQuery 21 aq_students = context.students_catalog.evalAdvancedQuery 14 22 request = context.REQUEST 15 23 setheader = request.RESPONSE.setHeader … … 33 41 lines.append(','.join(fields)) 34 42 format = '"%(' + ')s","%('.join(fields) + ')s"' 35 cleared = context.portal_catalog(review_state = "cleared_and_validated") 43 #cleared = context.portal_catalog(review_state = "cleared_and_validated") 44 query = In('review_state',('cleared_and_validated', 45 'school_fee_paid', 46 'courses_registered', 47 'courses_validated')) 48 cleared = aq_portal(query) 49 newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*') 50 #newquery = MatchRegexp('SearchableText','^5*') 51 new_students = aq_portal(newquery) 52 new_sids = [] 53 for ns in new_students: 54 new_sids.append(ns.getPath().split('/')[-2]) 36 55 for student in cleared: 56 if student.getId not in new_sids: 57 continue 37 58 erg = scat(id=student.getId) 38 59 if not erg:
Note: See TracChangeset for help on using the changeset viewer.