[3257] | 1 | ## Script (Python) "ti_493_resolve" |
---|
| 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: ti_493_resolve.py 3258 2008-02-29 09:44:47Z 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 |
---|
| 27 | logger = logging.getLogger('Skins.ti_493_resolve') |
---|
| 28 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 29 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
| 30 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 31 | payments_catalog = context.payments_catalog |
---|
| 32 | aq_payments = payments_catalog.evalAdvancedQuery |
---|
| 33 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
| 34 | |
---|
| 35 | request = context.REQUEST |
---|
| 36 | session = request.SESSION |
---|
| 37 | response = request.RESPONSE |
---|
| 38 | setheader = request.RESPONSE.setHeader |
---|
| 39 | def rwrite(s): |
---|
| 40 | response.setHeader('Content-type','text/html; charset=ISO-8859-15') |
---|
| 41 | response.write("%s<br>\n\r" % s) |
---|
| 42 | logger.info('start') |
---|
| 43 | portal_payments = aq_portal(Eq('portal_type','Payment')) |
---|
| 44 | sc_payments = aq_payments(Eq('type','sc')) |
---|
[3258] | 45 | logger.info('found %d payments, %d SC payments' % (len(portal_payments),len(sc_payments))) |
---|
| 46 | student_ids = [r.student_id for r in sc_payments] |
---|
[3257] | 47 | count = 0 |
---|
| 48 | found = 0 |
---|
| 49 | set_trace() |
---|
| 50 | for payment in portal_payments: |
---|
| 51 | count +=1 |
---|
| 52 | student_id = payment.relative_path.split('/')[2] |
---|
| 53 | if student_id in student_ids: |
---|
| 54 | doc = payment.getObject().getContent() |
---|
| 55 | session_id = doc.type_description[doc.type_description.find('/')-2:doc.type_description.find('/')] |
---|
| 56 | if session_id == doc.session_id: |
---|
| 57 | continue |
---|
| 58 | found += 1 |
---|
[3258] | 59 | logger.info("%d of %d: editing payment of %s, %s, %s, session_id from %s to %s" % (found,count, |
---|
[3257] | 60 | student_id, |
---|
[3258] | 61 | doc.date, |
---|
[3257] | 62 | doc.type_description, |
---|
| 63 | doc.session_id, |
---|
| 64 | session_id)) |
---|
| 65 | #doc.edit({'session_id': session_id}) |
---|
| 66 | logger.info('finished editing %d' % found) |
---|