1 | ## $Id: browser.py 8841 2012-06-27 12:47:32Z 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, PDFActionButton) |
---|
36 | from waeup.kofa.applicants.pdf import PDFApplicationSlip |
---|
37 | from waeup.futminna.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 | UG_OMIT_RESULT_SLIP_FIELDS) |
---|
45 | from waeup.futminna.interfaces import MessageFactory as _ |
---|
46 | |
---|
47 | class CustomOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): |
---|
48 | """A breadcrumb for payments. |
---|
49 | """ |
---|
50 | grok.context(ICustomApplicantOnlinePayment) |
---|
51 | |
---|
52 | class PaymentReceiptActionButton(PaymentReceiptActionButton): |
---|
53 | grok.order(4) |
---|
54 | grok.context(ICustomApplicantOnlinePayment) |
---|
55 | |
---|
56 | class PDFActionButton(PDFActionButton): |
---|
57 | |
---|
58 | @property |
---|
59 | def text(self): |
---|
60 | if getattr(self.context, 'result_uploaded', False): |
---|
61 | return _('Download result slip') |
---|
62 | return _('Download application slip') |
---|
63 | |
---|
64 | |
---|
65 | class CustomPDFApplicationSlip(PDFApplicationSlip): |
---|
66 | |
---|
67 | def _reduced_slip(self): |
---|
68 | return getattr(self.context, 'result_uploaded', False) |
---|
69 | |
---|
70 | @property |
---|
71 | def note(self): |
---|
72 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
73 | if target is not None and not target.startswith('pg') \ |
---|
74 | and not self._reduced_slip(): |
---|
75 | return _(u'<br /><br /><br />' |
---|
76 | 'Comfirm your exam venue 72 hours to the exam.') |
---|
77 | return |
---|
78 | |
---|
79 | @property |
---|
80 | def form_fields(self): |
---|
81 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
82 | if target is not None and target.startswith('pg'): |
---|
83 | form_fields = grok.AutoFields(IPGApplicant) |
---|
84 | for field in PG_OMIT_PDF_FIELDS: |
---|
85 | form_fields = form_fields.omit(field) |
---|
86 | else: |
---|
87 | form_fields = grok.AutoFields(IUGApplicant) |
---|
88 | if self._reduced_slip(): |
---|
89 | for field in UG_OMIT_RESULT_SLIP_FIELDS: |
---|
90 | form_fields = form_fields.omit(field) |
---|
91 | else: |
---|
92 | for field in UG_OMIT_PDF_FIELDS: |
---|
93 | form_fields = form_fields.omit(field) |
---|
94 | if not getattr(self.context, 'student_id'): |
---|
95 | form_fields = form_fields.omit('student_id') |
---|
96 | return form_fields |
---|
97 | |
---|
98 | class CustomApplicantDisplayFormPage(ApplicantDisplayFormPage): |
---|
99 | """A display view for applicant data. |
---|
100 | """ |
---|
101 | |
---|
102 | @property |
---|
103 | def form_fields(self): |
---|
104 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
105 | if target is not None and target.startswith('pg'): |
---|
106 | form_fields = grok.AutoFields(IPGApplicant) |
---|
107 | for field in PG_OMIT_DISPLAY_FIELDS: |
---|
108 | form_fields = form_fields.omit(field) |
---|
109 | else: |
---|
110 | form_fields = grok.AutoFields(IUGApplicant) |
---|
111 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
112 | form_fields = form_fields.omit(field) |
---|
113 | return form_fields |
---|
114 | |
---|
115 | class CustomApplicantManageFormPage(ApplicantManageFormPage): |
---|
116 | """A full 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(IPGApplicant) |
---|
124 | for field in PG_OMIT_MANAGE_FIELDS: |
---|
125 | form_fields = form_fields.omit(field) |
---|
126 | else: |
---|
127 | form_fields = grok.AutoFields(IUGApplicant) |
---|
128 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
129 | form_fields = form_fields.omit(field) |
---|
130 | form_fields['student_id'].for_display = True |
---|
131 | form_fields['applicant_id'].for_display = True |
---|
132 | return form_fields |
---|
133 | |
---|
134 | class CustomApplicantEditFormPage(ApplicantEditFormPage): |
---|
135 | """An applicant-centered edit view for applicant data. |
---|
136 | """ |
---|
137 | |
---|
138 | @property |
---|
139 | def form_fields(self): |
---|
140 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
141 | if target is not None and target.startswith('pg'): |
---|
142 | form_fields = grok.AutoFields(IPGApplicantEdit) |
---|
143 | for field in PG_OMIT_EDIT_FIELDS: |
---|
144 | form_fields = form_fields.omit(field) |
---|
145 | elif target is not None and target.startswith('putme'): |
---|
146 | form_fields = grok.AutoFields(IPUTMEApplicantEdit) |
---|
147 | for field in PUTME_OMIT_EDIT_FIELDS: |
---|
148 | form_fields = form_fields.omit(field) |
---|
149 | else: |
---|
150 | form_fields = grok.AutoFields(IUGApplicantEdit) |
---|
151 | for field in UG_OMIT_EDIT_FIELDS: |
---|
152 | form_fields = form_fields.omit(field) |
---|
153 | form_fields['applicant_id'].for_display = True |
---|
154 | form_fields['reg_number'].for_display = True |
---|
155 | return form_fields |
---|
156 | |
---|
157 | class CustomOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): |
---|
158 | """ Page to view an online payment ticket |
---|
159 | """ |
---|
160 | grok.context(ICustomApplicantOnlinePayment) |
---|
161 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
162 | form_fields[ |
---|
163 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
164 | form_fields[ |
---|
165 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
166 | |
---|
167 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
168 | """ Page to add an online payment ticket |
---|
169 | """ |
---|
170 | factory = u'waeup.CustomApplicantOnlinePayment' |
---|
171 | |
---|
172 | class CustomExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): |
---|
173 | """Deliver a PDF slip of the context. |
---|
174 | """ |
---|
175 | grok.context(ICustomApplicantOnlinePayment) |
---|
176 | form_fields = grok.AutoFields(ICustomApplicantOnlinePayment).omit('ac') |
---|
177 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
178 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|