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