1 | ## $Id: browser.py 8531 2012-05-27 16:47:35Z 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 | """ |
---|
20 | import grok |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.i18n import translate |
---|
23 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
24 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
25 | from waeup.kofa.applicants.interfaces import ( |
---|
26 | IApplicantRegisterUpdate, IApplicant, IApplicantEdit) |
---|
27 | from waeup.kofa.applicants.browser import (ApplicantDisplayFormPage, |
---|
28 | ExportPDFPage, |
---|
29 | ApplicantManageFormPage, ApplicantEditFormPage, |
---|
30 | ApplicantRegistrationPage, ApplicantAddFormPage, |
---|
31 | OnlinePaymentDisplayFormPage, ApplicationFeePaymentAddPage, |
---|
32 | OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, |
---|
33 | ApplicantBaseDisplayFormPage) |
---|
34 | from waeup.kofa.applicants.viewlets import ( |
---|
35 | PaymentReceiptActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from waeup.fceokene.applicants.interfaces import ( |
---|
38 | IPGApplicant, IUGApplicant, IPGApplicantEdit, IUGApplicantEdit, |
---|
39 | ICustomApplicantOnlinePayment, IPUTMEApplicantEdit, |
---|
40 | UG_OMIT_DISPLAY_FIELDS, PG_OMIT_DISPLAY_FIELDS, |
---|
41 | UG_OMIT_MANAGE_FIELDS, PG_OMIT_MANAGE_FIELDS, |
---|
42 | UG_OMIT_EDIT_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_EDIT_FIELDS) |
---|
43 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
44 | |
---|
45 | #class RequestCallbackActionButton(RequestCallbackActionButton): |
---|
46 | # """ Display the base package callback button in custom pages. |
---|
47 | # """ |
---|
48 | # grok.context(ICustomApplicantOnlinePayment) |
---|
49 | |
---|
50 | #class CustomOnlinePaymentCallbackPage(OnlinePaymentCallbackPage): |
---|
51 | # """ Activate callback simulation view |
---|
52 | # """ |
---|
53 | # grok.context(ICustomApplicantOnlinePayment) |
---|
54 | |
---|
55 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
56 | """A breadcrumb for payments. |
---|
57 | """ |
---|
58 | grok.context(ICustomApplicantOnlinePayment) |
---|
59 | |
---|
60 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
61 | grok.order(4) |
---|
62 | grok.context(ICustomApplicantOnlinePayment) |
---|
63 | |
---|
64 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
65 | |
---|
66 | @property |
---|
67 | def form_fields(self): |
---|
68 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
69 | if target is not None and target.startswith('pg'): |
---|
70 | form_fields = grok.AutoFields(IPGApplicant) |
---|
71 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
72 | form_fields = form_fields.omit(field) |
---|
73 | else: |
---|
74 | form_fields = grok.AutoFields(IUGApplicant) |
---|
75 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
76 | form_fields = form_fields.omit(field) |
---|
77 | return form_fields |
---|
78 | |
---|
79 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
80 | """A display view for applicant data. |
---|
81 | """ |
---|
82 | |
---|
83 | @property |
---|
84 | def form_fields(self): |
---|
85 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
86 | if target is not None and target.startswith('pg'): |
---|
87 | form_fields = grok.AutoFields(IPGApplicant) |
---|
88 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
89 | form_fields = form_fields.omit(field) |
---|
90 | else: |
---|
91 | form_fields = grok.AutoFields(IUGApplicant) |
---|
92 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
93 | form_fields = form_fields.omit(field) |
---|
94 | return form_fields |
---|
95 | |
---|
96 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
97 | """A full edit view for applicant data. |
---|
98 | """ |
---|
99 | |
---|
100 | @property |
---|
101 | def form_fields(self): |
---|
102 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
103 | if target is not None and target.startswith('pg'): |
---|
104 | form_fields = grok.AutoFields(IPGApplicant) |
---|
105 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
106 | form_fields = form_fields.omit(field) |
---|
107 | else: |
---|
108 | form_fields = grok.AutoFields(IUGApplicant) |
---|
109 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
110 | form_fields = form_fields.omit(field) |
---|
111 | form_fields['student_id'].for_display = True |
---|
112 | form_fields['applicant_id'].for_display = True |
---|
113 | return form_fields |
---|
114 | |
---|
115 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
116 | """An applicant-centered edit view for applicant data. |
---|
117 | """ |
---|
118 | |
---|
119 | @property |
---|
120 | def form_fields(self): |
---|
121 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
122 | if target is not None and target.startswith('pg'): |
---|
123 | form_fields = grok.AutoFields(IPGApplicantEdit) |
---|
124 | for field in PG_OMIT_EDIT_FIELDS: |
---|
125 | form_fields = form_fields.omit(field) |
---|
126 | elif target is not None and target.startswith('putme'): |
---|
127 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
128 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
129 | form_fields = form_fields.omit(field) |
---|
130 | else: |
---|
131 | form_fields = grok.AutoFields(IUGApplicantEdit) |
---|
132 | for field in UG_OMIT_EDIT_FIELDS: |
---|
133 | form_fields = form_fields.omit(field) |
---|
134 | form_fields['applicant_id'].for_display = True |
---|
135 | form_fields['reg_number'].for_display = True |
---|
136 | return form_fields |
---|
137 | |
---|
138 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
139 | """ Page to view an online payment ticket |
---|
140 | """ |
---|
141 | grok.context(ICustomApplicantOnlinePayment) |
---|
142 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
143 | form_fields[ |
---|
144 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
145 | form_fields[ |
---|
146 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
147 | grok.template('payment_view') |
---|
148 | |
---|
149 | @property |
---|
150 | def transaction_code(self): |
---|
151 | tcode = self.context.p_id |
---|
152 | return tcode[len(tcode)-8:len(tcode)] |
---|
153 | |
---|
154 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
155 | """ Page to add an online payment ticket |
---|
156 | """ |
---|
157 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
158 | |
---|
159 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
160 | """Deliver a PDF slip of the context. |
---|
161 | """ |
---|
162 | grok.context(ICustomApplicantOnlinePayment) |
---|
163 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
164 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
165 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
166 | |
---|
167 | @property |
---|
168 | def note(self): |
---|
169 | if self.context.p_state == 'paid': |
---|
170 | return None |
---|
171 | tcode = self.context.p_id |
---|
172 | tcode = tcode[len(tcode)-8:len(tcode)] |
---|
173 | amount = self.context.amount_auth |
---|
174 | note = translate(_( |
---|
175 | u"""<br /><br /><br /> |
---|
176 | The tranzaction code is <strong>${a}</strong>.""", |
---|
177 | mapping = {'a':tcode})) |
---|
178 | return note |
---|