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