source: WAeUP_SRP/trunk/skins/waeup_epayment/dumpSCPayments.py @ 8794

Last change on this file since 8794 was 2670, checked in by Henrik Bettermann, 17 years ago

further modifications for session change

  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1## Script (Python) "dumpSCPayments.py"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: dumpSCPayments.py 2670 2007-11-15 22:07:14Z henrik $
11"""
12"""
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21if str(member) not in ('admin','joachim'):
22    return
23
24
25import logging
26import DateTime
27logger = logging.getLogger('Skins.dumpSCPayments')
28from Products.AdvancedQuery import Eq, Between, Le,In
29aq_pins = context.portal_pins.evalAdvancedQuery
30aq_student = context.students_catalog.evalAdvancedQuery
31#students_folder = context.portal_url.getPortalObject().campus.students
32
33request = context.REQUEST
34session = request.SESSION
35response = request.RESPONSE
36setheader = request.RESPONSE.setHeader
37def rwrite(s):
38    response.setHeader('Content-type','text/html; charset=ISO-8859-15')
39    response.write("%s<br>\n\r" % s)
40
41cost_dict = {}
42for k,v in context.getScratchCardCost():
43    cost_dict[''.join(k.split('_'))] = v
44
45used_query = ~Eq('student','') & ~In('prefix_batch',('APP1','APP2','APP3','APP4','APP5',))
46
47pins = aq_pins(used_query,sortSpecs=('student',))
48#set_trace()
49count = 1
50student_id = 'xxx'
51d = {}
52l = []
53sum_total = 0.0
54log_after = 100
55logger.info("start")
56for pin in pins:
57    if pin.pin.startswith('APP'):
58        continue
59    if student_id != pin.student:
60        if d:
61            res = aq_student(Eq('id',pin.student))
62            if not res:
63                logger.info("student_id %s not found" % pin.student)
64                continue
65            student = res[0]
66            d['name'] = student.name
67            d['faculty'] = student.faculty
68            d['department'] = student.department
69            d['course'] = student.course
70            d['matric_no'] = student.matric_no
71            #d['costs'] = ' '.join(costs)
72            d['pins'] = ' '.join(pins)
73            d['sum'] = sum
74            sum_total += sum
75            # rwrite(("%d: " % count) + "%(student_id)s %(pins)s %(costs)s %(sum)8.2f" % d +\
76            #         " %(faculty)s %(department)s %(course)s" % d)
77            l +=d,
78            d = {}
79            if not count % log_after:
80                logger.info("processed %d/%d" % (log_after,count))
81                # if not count % 1000:
82                #     break
83            count += 1
84        student_id = d['student_id'] = pin.student
85        costs = ["%8.2f" % cost_dict[pin.prefix_batch],]
86        pins = [pin.pin,]
87        sum = cost_dict[pin.prefix_batch]
88    else:
89        costs += ("%8.2f" % cost_dict[pin.prefix_batch]),
90        pins += pin.pin,
91        sum += cost_dict[pin.prefix_batch]
92fields= ('student_id','name','pins','sum','matric_no','faculty','department','course')
93csv_name = context.waeup_tool.dumpListToCSV(l,'sc_payments',fields=fields)
94logger.info('%s dumped sc payments to %s' % (member,csv_name))
95logger.info("finished for %d students total N %12.2f %12.2f Euros" % (count,sum_total,sum_total/170))
96
97
Note: See TracBrowser for help on using the repository browser.