source: WAeUP_SRP/branches/joachim-azax-branch/skins/waeup_student/request_transfer.py @ 9735

Last change on this file since 9735 was 1571, checked in by Henrik Bettermann, 18 years ago

new logging format Part 4 (rest)

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
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"""
12pay online
13"""
14import logging
15from urllib import urlencode
16logger = logging.getLogger('Skins_request_transfer')
17import DateTime
18lt = context.portal_layouts
19request = context.REQUEST
20students = context.portal_url.getPortalObject().campus.students
21
22mtool = context.portal_membership
23if mtool.isAnonymousUser():
24    return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
25
26member = mtool.getAuthenticatedMember()
27member_id = str(member)
28requested_id = context.getStudentId()
29if 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
33elif context.isStaff():
34    student_id = requested_id
35else:
36    student_id = member_id
37if student_id is None:
38    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
39
40student = getattr(students,student_id)
41sbrain = context.students_catalog(id=student_id)[0]
42payments = getattr(student,'payments').objectIds()
43paid = False
44for payment in payments:
45    if payment.startswith('transfer'):
46        paid = True
47        break
48
49# for testing of transfer forms
50#paid = True
51
52if 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
59validate = request.has_key("cpsdocument_create_button")
60res,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                      )
69if 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                                 )
76elif psm == '':
77    return context.request_transfer_form(rendered = res,
78                                 psm = None,
79                                 mode = 'edit',
80                                 ds = ds,
81                                 )
82elif psm == 'valid':
83    pass
84if "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')
91else:
92    payments = getattr(student,'payments')
93#from Products.zdb import set_trace; set_trace()
94
95logger.info('%s paid transfer form for %s' % (member_id,student_id))
96info = {}
97order_id = ds.get('pin_n')
98p_id = "transfer_%s" % order_id
99now = DateTime.DateTime()
100info['date'] = now
101info['amount'] = "n/a"
102pin = info['order_id'] = ds.get('pin')
103info['type_code'] = "%s" % pin
104info['type_description'] = 'Transfer Form for Session 2006/2007'
105info['resp_code'] = "SC"
106info['resp_desc'] = "SC Payment Successful"
107payments.invokeFactory('Payment', p_id)
108payment = getattr(payments,p_id)
109wftool = context.portal_workflow
110wftool.doActionFor(payment,'open')
111payment.getContent().edit(mapping=info)
112wftool.doActionFor(payment,'close')
113return context.request_transfer_form(rendered = None,
114                                 psm = None,
115                                 paid = True,
116                                 )
117
Note: See TracBrowser for help on using the repository browser.