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 1571 2007-03-17 15:25:56Z henrik $ |
---|
11 | """ |
---|
12 | pay online |
---|
13 | """ |
---|
14 | import logging |
---|
15 | from urllib import urlencode |
---|
16 | logger = logging.getLogger('Skins_request_transfer') |
---|
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 tried to access object of %s' % (member_id,requested_id)) |
---|
31 | student_id = requested_id |
---|
32 | return None |
---|
33 | elif context.isStaff(): |
---|
34 | student_id = requested_id |
---|
35 | else: |
---|
36 | student_id = member_id |
---|
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] |
---|
42 | payments = getattr(student,'payments').objectIds() |
---|
43 | paid = False |
---|
44 | for payment in payments: |
---|
45 | if payment.startswith('transfer'): |
---|
46 | paid = True |
---|
47 | break |
---|
48 | |
---|
49 | # for testing of transfer forms |
---|
50 | #paid = True |
---|
51 | |
---|
52 | if paid: |
---|
53 | logger.info('%s opened (paid) request transfer form of %s' % (member_id,student_id)) |
---|
54 | return context.request_transfer_form(rendered = None, |
---|
55 | psm = None, |
---|
56 | paid = True, |
---|
57 | ) |
---|
58 | |
---|
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() |
---|
94 | |
---|
95 | logger.info('%s paid transfer form for %s' % (member_id,student_id)) |
---|
96 | info = {} |
---|
97 | order_id = ds.get('pin_n') |
---|
98 | p_id = "transfer_%s" % order_id |
---|
99 | now = DateTime.DateTime() |
---|
100 | info['date'] = now |
---|
101 | info['amount'] = "n/a" |
---|
102 | pin = info['order_id'] = ds.get('pin') |
---|
103 | info['type_code'] = "%s" % pin |
---|
104 | info['type_description'] = 'Transfer Form for Session 2006/2007' |
---|
105 | info['resp_code'] = "SC" |
---|
106 | info['resp_desc'] = "SC Payment Successful" |
---|
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') |
---|
113 | return context.request_transfer_form(rendered = None, |
---|
114 | psm = None, |
---|
115 | paid = True, |
---|
116 | ) |
---|
117 | |
---|