Changeset 1673


Ignore:
Timestamp:
9 Apr 2007, 16:01:51 (18 years ago)
Author:
joachim
Message:

merge up to 1672

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  
    278278###)
    279279
     280class 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
     289InitializeClass(CoursesCatalog)
     290###)
     291
    280292class ReturningImport(WAeUPTable): ###(
    281293
  • WAeUP_SRP/branches/joachim-event-branch/WAeUPTool.py

    r1596 r1673  
    532532    ###)
    533533
     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
    534660InitializeClass(WAeUPTool)
  • WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/getNewStudentStatistics.py

    r1596 r1673  
    1212return Student Statistics
    1313"""
     14try:
     15    from Products.zdb import set_trace
     16except:
     17    def set_trace():
     18        pass
    1419import logging
    1520logger = logging.getLogger('Skins.getNewStudentStatistics')
    1621
    1722try:
    18     from Products.AdvancedQuery import Eq, Between, Le,In, Ge
     23    from Products.AdvancedQuery import Eq, Between, Le,In, Ge,MatchRegexp
    1924    aq_portal = context.portal_catalog.evalAdvancedQuery
    2025    aq_students = context.students_catalog.evalAdvancedQuery
    2126except:
    2227    evalAdvancedQuery = None
     28
     29def intersect(m,n):
     30    return [i for i in m if i in n]
     31   
    2332logger.info('%s invoked statistics' % context.portal_membership.getAuthenticatedMember())
    24 l = []
    2533if not context.isStaff():
    2634    return l
    27 dep = {}
     35total_dict = {}
    2836
    29 dep['id'] = "All Faculties"
     37total_dict['id'] = "All Faculties"
    3038
    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))
     42newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*')
     43total_res = aq_portal(newquery)
     44new_ids = [r.getPath().split('/')[-2] for r in total_res]
     45total_new = float(len(total_res))
     46total_dict['new'] = "%.0f" % total_new
     47special_states =  ('admitted',
     48                   'clearance_pin_entered',
     49                   'clearance_requested',
     50                   'cleared_and_validated',
     51                   'objection_raised',
     52                   )
     53state_count = 0
     54state_ids = {}
     55for 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)
     63total_dict['rest'] = "%.0f" % (total_new - state_count)
     64total_dict['rest_percent'] = "%.0f" % round((total_new - state_count)*100/total_new)
     65fac_res = {}
     66#fac_res['total'] = total_dict
     67faculties = context.portal_catalog(portal_type="Faculty")
     68for 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
     94l = []
     95l.append(total_dict)
     96fac_ids = [f.getId for f in faculties]
     97fac_ids.sort()
     98check_dict = {}
     99check_dict['id'] = 'Check'
     100check_dict['new'] = 0
     101check_dict['new_percent'] = 0
     102check_dict['rest'] = 0
     103check_dict['rest_percent'] = 0
     104for state in special_states:
     105    check_dict[state] = 0
     106    check_dict["%s_percent" % state] = 0
     107   
     108for 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])
     123l.append(check_dict)   
    122124
    123125return l
  • WAeUP_SRP/branches/joachim-event-branch/skins/waeup_student/list_students.py

    r1312 r1673  
    1212export student_list
    1313"""
     14try:
     15    from Products.zdb import set_trace
     16except:
     17    def set_trace():
     18        pass
     19from Products.AdvancedQuery import Eq, Between, Le,In,MatchRegexp
     20aq_portal = context.portal_catalog.evalAdvancedQuery
     21aq_students = context.students_catalog.evalAdvancedQuery
    1422request = context.REQUEST
    1523setheader = request.RESPONSE.setHeader
     
    3341lines.append(','.join(fields))
    3442format = '"%(' + ')s","%('.join(fields) + ')s"'
    35 cleared = context.portal_catalog(review_state = "cleared_and_validated")
     43#cleared = context.portal_catalog(review_state = "cleared_and_validated")
     44query = In('review_state',('cleared_and_validated',
     45                           'school_fee_paid',
     46                           'courses_registered',
     47                           'courses_validated'))
     48cleared = aq_portal(query)
     49newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*')
     50#newquery = MatchRegexp('SearchableText','^5*')
     51new_students = aq_portal(newquery)
     52new_sids = []
     53for ns in new_students:
     54    new_sids.append(ns.getPath().split('/')[-2])
    3655for student in cleared:
     56    if student.getId not in new_sids:
     57        continue
    3758    erg = scat(id=student.getId)
    3859    if not erg:
Note: See TracChangeset for help on using the changeset viewer.