## Script (Python) "request_transfer" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $Id: request_transfer.py 2661 2007-11-14 22:19:25Z henrik $ """ pay online """ import logging from urllib import urlencode logger = logging.getLogger('Skins_request_transfer') import DateTime lt = context.portal_layouts request = context.REQUEST students = context.portal_url.getPortalObject().campus.students mtool = context.portal_membership if mtool.isAnonymousUser(): return context.REQUEST.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) member = mtool.getAuthenticatedMember() member_id = str(member) requested_id = context.getStudentId() if requested_id and not context.isStaff() and member_id != requested_id: logger.info('%s tried to access object of %s' % (member_id,requested_id)) student_id = requested_id return None elif context.isStaff(): student_id = requested_id else: student_id = member_id if student_id is None: return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) student = getattr(students,student_id) sbrain = context.students_catalog(id=student_id)[0] payments = getattr(student,'payments').objectIds() paid = False for payment in payments: if payment.startswith('transfer'): paid = True break # for testing of transfer forms #paid = True if paid: logger.info('%s opened (paid) request transfer form of %s' % (member_id,student_id)) return context.request_transfer_form(rendered = None, psm = None, paid = True, ) validate = request.has_key("cpsdocument_create_button") res,psm,ds = lt.renderLayout(layout_id= 'student_transfer', schema_id= 'epayment', context=context, mapping=validate and request, ob={}, layout_mode="create", formaction = "request_transfer", button = 'Start' ) if psm == 'invalid': psm = 'Please correct your errors!' return context.request_transfer_form(rendered = res, psm = psm, mode = 'edit', ds = ds, ) elif psm == '': return context.request_transfer_form(rendered = res, psm = None, mode = 'edit', ds = ds, ) elif psm == 'valid': pass if "payments" not in student.objectIds(): student.invokeFactory('PaymentsFolder','payments') payments = getattr(student,'payments') d = {} d['Title'] = 'Payments' payments.getContent().edit(mapping=d) wftool.doActionFor(payments,'open') else: payments = getattr(student,'payments') #from Products.zdb import set_trace; set_trace() logger.info('%s paid transfer form for %s' % (member_id,student_id)) info = {} order_id = ds.get('pin_n') p_id = "transfer_%s" % order_id now = DateTime.DateTime() info['date'] = now info['amount'] = "n/a" pin = info['order_id'] = ds.get('pin') info['type_code'] = "%s" % pin info['type_description'] = 'Transfer Form' info['resp_code'] = "SC" info['resp_desc'] = "SC Payment Successful" payments.invokeFactory('Payment', p_id) payment = getattr(payments,p_id) wftool = context.portal_workflow wftool.doActionFor(payment,'open') payment.getContent().edit(mapping=info) wftool.doActionFor(payment,'close') return context.request_transfer_form(rendered = None, psm = None, paid = True, )