source: main/waeup.uniben/trunk/src/waeup/uniben/applicants/browser.py @ 8259

Last change on this file since 8259 was 8259, checked in by Henrik Bettermann, 13 years ago

Implement acceptance fee payments via Interswitch (part 2)

  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1## $Id: browser.py 8259 2012-04-23 14:06:39Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18"""UI components for basic applicants and related components.
19"""
20import grok
21from zope.component import getUtility
22from zope.i18n import translate
23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from waeup.kofa.students.interfaces import IStudentsUtils
25from waeup.kofa.applicants.interfaces import (
26    IApplicantRegisterUpdate, IApplicant, IApplicantEdit)
27from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage,
28    OnlinePaymentCallbackPage, ExportPDFPage,
29    ApplicantManageFormPage, ApplicantEditFormPage,
30    ApplicantRegistrationPage, ApplicantAddFormPage,
31    OnlinePaymentDisplayFormPage, AcceptanceFeePaymentAddPage,
32    OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage,
33    ApplicantBaseDisplayFormPage)
34from waeup.kofa.applicants.viewlets import (
35    RequestCallbackActionButton, PaymentReceiptActionButton)
36from waeup.kofa.applicants.pdf import PDFApplicationSlip
37from waeup.uniben.applicants.interfaces import (
38    IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit,
39    ICustomApplicantOnlinePayment)
40from waeup.uniben.interfaces import MessageFactory as _
41
42#class RequestCallbackActionButton(RequestCallbackActionButton):
43#    """ Display the base package callback button in custom pages.
44#    """
45#    grok.context(ICustomApplicantOnlinePayment)
46
47#class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage):
48#    """ Activate callback simulation view
49#    """
50#    grok.context(ICustomApplicantOnlinePayment)
51
52class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb):
53    """A breadcrumb for payments.
54    """
55    grok.context(ICustomApplicantOnlinePayment)
56
57class PaymentReceiptActionButton(PaymentReceiptActionButton):
58    grok.order(4)
59    grok.context(ICustomApplicantOnlinePayment)
60
61class CustomPDFApplicationSlip(PDFApplicationSlip):
62
63    @property
64    def form_fields(self):
65        target = getattr(self.context.__parent__, 'prefix', None)
66        if target is not None and target.startswith('pg'):
67            form_fields = grok.AutoFields(IPGApplicant).omit(
68                'locked', 'course_admitted')
69        else:
70            form_fields = grok.AutoFields(IUGApplicant).omit(
71                'locked', 'course_admitted')
72        return form_fields
73
74class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage):
75    """A display view for applicant data.
76    """
77
78    @property
79    def form_fields(self):
80        target = getattr(self.context.__parent__, 'prefix', None)
81        if target is not None and target.startswith('pg'):
82            form_fields = grok.AutoFields(IPGApplicant).omit(
83                'locked', 'course_admitted', 'password')
84        else:
85            form_fields = grok.AutoFields(IUGApplicant).omit(
86                'locked', 'course_admitted', 'password')
87        return form_fields
88
89class CustomApplicantManageFormPage(ApplicantManageFormPage):
90    """A full edit view for applicant data.
91    """
92   
93    @property
94    def form_fields(self):
95        target = getattr(self.context.__parent__, 'prefix', None)
96        if target is not None and target.startswith('pg'):
97            form_fields = grok.AutoFields(IPGApplicant)
98        else:
99            form_fields = grok.AutoFields(IUGApplicant)
100        form_fields['student_id'].for_display = True
101        form_fields['applicant_id'].for_display = True
102        return form_fields
103
104class CustomApplicantEditFormPage(ApplicantEditFormPage):
105    """An applicant-centered edit view for applicant data.
106    """
107
108    @property
109    def form_fields(self):
110        target = getattr(self.context.__parent__, 'prefix', None)
111        if target is not None and target.startswith('pg'):
112            form_fields = grok.AutoFields(IPGApplicantEdit).omit(
113                'locked', 'course_admitted', 'student_id',
114                'screening_score', 'screening_venue'
115                )
116        else:
117            form_fields = grok.AutoFields(IUGApplicantEdit).omit(
118                'locked', 'course_admitted', 'student_id',
119                'screening_score'
120                )
121        form_fields['applicant_id'].for_display = True
122        form_fields['reg_number'].for_display = True
123        return form_fields
124
125class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage):
126    """ Page to view an online payment ticket
127    """
128    grok.context(ICustomApplicantOnlinePayment)
129    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit(
130        'surcharge_1', 'surcharge_2', 'surcharge_3', 'ac')
131    form_fields[
132        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
133    form_fields[
134        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
135    grok.template('payment_view')
136
137    @property
138    def transaction_code(self):
139        tcode = self.context.p_id
140        return tcode[len(tcode)-8:len(tcode)]
141
142class CustomAcceptanceFeePaymentAddPage(AcceptanceFeePaymentAddPage):
143    """ Page to add an online payment ticket
144    """
145    factory = u'waeup.CustomApplicantOnlinePayment'
146
147    def _fillCustomFields(self, payment, session_config):
148        payment.surcharge_1 = session_config.surcharge_1
149        payment.surcharge_2 = session_config.surcharge_2
150        payment.surcharge_3 = session_config.surcharge_3
151        return payment
152
153class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage):
154    """Deliver a PDF slip of the context.
155    """
156    grok.context(ICustomApplicantOnlinePayment)
157    form_fields = grok.AutoFields(ICustomApplicantOnlinePayment)
158    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
159    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
160
161    @property
162    def note(self):
163        tcode = self.context.p_id
164        tcode = tcode[len(tcode)-8:len(tcode)]
165        amount = self.context.amount_auth
166        note = translate(_(
167            u"""<br /><br /><br />
168The tranzaction code for eTranzact payments is <strong>${a}</strong>.""",
169            mapping = {'a':tcode}))
170        return note
Note: See TracBrowser for help on using the repository browser.