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