[1321] | 1 | ## Script (Python) "request_transfer" |
---|
[1319] | 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: request_transfer.py 1596 2007-03-19 21:45:44Z joachim $ |
---|
| 11 | """ |
---|
| 12 | pay online |
---|
| 13 | """ |
---|
| 14 | import logging |
---|
| 15 | from urllib import urlencode |
---|
[1596] | 16 | logger = logging.getLogger('Skins_request_transfer') |
---|
[1319] | 17 | import DateTime |
---|
| 18 | lt = context.portal_layouts |
---|
| 19 | request = context.REQUEST |
---|
| 20 | students = context.portal_url.getPortalObject().campus.students |
---|
| 21 | |
---|
[1340] | 22 | mtool = context.portal_membership |
---|
[1356] | 23 | if mtool.isAnonymousUser(): |
---|
| 24 | return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 25 | |
---|
[1340] | 26 | member = mtool.getAuthenticatedMember() |
---|
| 27 | member_id = str(member) |
---|
| 28 | requested_id = context.getStudentId() |
---|
| 29 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
[1596] | 30 | logger.info('%s tried to access object of %s' % (member_id,requested_id)) |
---|
[1340] | 31 | student_id = requested_id |
---|
[1596] | 32 | return None |
---|
[1340] | 33 | elif context.isStaff(): |
---|
| 34 | student_id = requested_id |
---|
| 35 | else: |
---|
| 36 | student_id = member_id |
---|
[1319] | 37 | if student_id is None: |
---|
| 38 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
| 39 | |
---|
| 40 | student = getattr(students,student_id) |
---|
| 41 | sbrain = context.students_catalog(id=student_id)[0] |
---|
[1327] | 42 | payments = getattr(student,'payments').objectIds() |
---|
[1340] | 43 | paid = False |
---|
[1327] | 44 | for payment in payments: |
---|
| 45 | if payment.startswith('transfer'): |
---|
[1340] | 46 | paid = True |
---|
[1327] | 47 | break |
---|
[1332] | 48 | |
---|
| 49 | # for testing of transfer forms |
---|
[1340] | 50 | #paid = True |
---|
[1338] | 51 | |
---|
[1340] | 52 | if paid: |
---|
[1596] | 53 | logger.info('%s opened (paid) request transfer form of %s' % (member_id,student_id)) |
---|
[1327] | 54 | return context.request_transfer_form(rendered = None, |
---|
| 55 | psm = None, |
---|
[1340] | 56 | paid = True, |
---|
[1327] | 57 | ) |
---|
[1332] | 58 | |
---|
[1319] | 59 | validate = request.has_key("cpsdocument_create_button") |
---|
| 60 | res,psm,ds = lt.renderLayout(layout_id= 'student_transfer', |
---|
| 61 | schema_id= 'epayment', |
---|
| 62 | context=context, |
---|
| 63 | mapping=validate and request, |
---|
| 64 | ob={}, |
---|
| 65 | layout_mode="create", |
---|
| 66 | formaction = "request_transfer", |
---|
| 67 | button = 'Start' |
---|
| 68 | ) |
---|
| 69 | if psm == 'invalid': |
---|
| 70 | psm = 'Please correct your errors!' |
---|
| 71 | return context.request_transfer_form(rendered = res, |
---|
| 72 | psm = psm, |
---|
| 73 | mode = 'edit', |
---|
| 74 | ds = ds, |
---|
| 75 | ) |
---|
| 76 | elif psm == '': |
---|
| 77 | return context.request_transfer_form(rendered = res, |
---|
| 78 | psm = None, |
---|
| 79 | mode = 'edit', |
---|
| 80 | ds = ds, |
---|
| 81 | ) |
---|
| 82 | elif psm == 'valid': |
---|
| 83 | pass |
---|
| 84 | if "payments" not in student.objectIds(): |
---|
| 85 | student.invokeFactory('PaymentsFolder','payments') |
---|
| 86 | payments = getattr(student,'payments') |
---|
| 87 | d = {} |
---|
| 88 | d['Title'] = 'Payments' |
---|
| 89 | payments.getContent().edit(mapping=d) |
---|
| 90 | wftool.doActionFor(payments,'open') |
---|
| 91 | else: |
---|
| 92 | payments = getattr(student,'payments') |
---|
| 93 | #from Products.zdb import set_trace; set_trace() |
---|
[1596] | 94 | |
---|
| 95 | logger.info('%s paid transfer form for %s' % (member_id,student_id)) |
---|
[1319] | 96 | info = {} |
---|
| 97 | order_id = ds.get('pin_n') |
---|
[1327] | 98 | p_id = "transfer_%s" % order_id |
---|
[1319] | 99 | now = DateTime.DateTime() |
---|
| 100 | info['date'] = now |
---|
| 101 | info['amount'] = "n/a" |
---|
| 102 | pin = info['order_id'] = ds.get('pin') |
---|
[1378] | 103 | info['type_code'] = "%s" % pin |
---|
[1371] | 104 | info['type_description'] = 'Transfer Form for Session 2006/2007' |
---|
| 105 | info['resp_code'] = "SC" |
---|
| 106 | info['resp_desc'] = "SC Payment Successful" |
---|
[1319] | 107 | payments.invokeFactory('Payment', p_id) |
---|
| 108 | payment = getattr(payments,p_id) |
---|
| 109 | wftool = context.portal_workflow |
---|
| 110 | wftool.doActionFor(payment,'open') |
---|
| 111 | payment.getContent().edit(mapping=info) |
---|
| 112 | wftool.doActionFor(payment,'close') |
---|
[1327] | 113 | return context.request_transfer_form(rendered = None, |
---|
| 114 | psm = None, |
---|
[1340] | 115 | paid = True, |
---|
[1327] | 116 | ) |
---|
[1319] | 117 | |
---|