[2665] | 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 | """ |
---|
| 13 | try: |
---|
| 14 | from Products.zdb import set_trace |
---|
| 15 | except: |
---|
| 16 | def set_trace(): |
---|
| 17 | pass |
---|
| 18 | |
---|
| 19 | mtool = context.portal_membership |
---|
| 20 | member = mtool.getAuthenticatedMember() |
---|
| 21 | if str(member) not in ('admin','joachim'): |
---|
| 22 | return |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | import logging |
---|
| 26 | import DateTime |
---|
[2670] | 27 | logger = logging.getLogger('Skins.dumpSCPayments') |
---|
[2665] | 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 29 | aq_pins = context.portal_pins.evalAdvancedQuery |
---|
| 30 | aq_student = context.students_catalog.evalAdvancedQuery |
---|
| 31 | #students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 32 | |
---|
| 33 | request = context.REQUEST |
---|
| 34 | session = request.SESSION |
---|
| 35 | response = request.RESPONSE |
---|
| 36 | setheader = request.RESPONSE.setHeader |
---|
| 37 | def rwrite(s): |
---|
| 38 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 39 | response.write("%s<br>\n\r" % s) |
---|
| 40 | |
---|
| 41 | cost_dict = {} |
---|
| 42 | for k,v in context.getScratchCardCost(): |
---|
| 43 | cost_dict[''.join(k.split('_'))] = v |
---|
| 44 | |
---|
| 45 | used_query = ~Eq('student','') & ~In('prefix_batch',('APP1','APP2','APP3','APP4','APP5',)) |
---|
[2670] | 46 | |
---|
[2665] | 47 | pins = aq_pins(used_query,sortSpecs=('student',)) |
---|
| 48 | #set_trace() |
---|
| 49 | count = 1 |
---|
| 50 | student_id = 'xxx' |
---|
| 51 | d = {} |
---|
| 52 | l = [] |
---|
| 53 | sum_total = 0.0 |
---|
| 54 | log_after = 100 |
---|
| 55 | logger.info("start") |
---|
| 56 | for 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] |
---|
[2667] | 66 | d['name'] = student.name |
---|
[2665] | 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 |
---|
[2670] | 84 | student_id = d['student_id'] = pin.student |
---|
[2665] | 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] |
---|
[2667] | 92 | fields= ('student_id','name','pins','sum','matric_no','faculty','department','course') |
---|
[2665] | 93 | csv_name = context.waeup_tool.dumpListToCSV(l,'sc_payments',fields=fields) |
---|
| 94 | logger.info('%s dumped sc payments to %s' % (member,csv_name)) |
---|
| 95 | logger.info("finished for %d students total N %12.2f %12.2f Euros" % (count,sum_total,sum_total/170)) |
---|
[2670] | 96 | |
---|
| 97 | |
---|