1 | ## $Id: browser.py 15171 2018-09-24 07:48:54Z 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 time import time |
---|
22 | from zope.formlib.textwidgets import BytesDisplayWidget |
---|
23 | from zope.component import getUtility, createObject |
---|
24 | from hurry.workflow.interfaces import IWorkflowState |
---|
25 | from waeup.kofa.applicants.browser import ( |
---|
26 | ApplicantRegistrationPage, ApplicantsContainerPage, |
---|
27 | ExportPDFPageApplicationSlip) |
---|
28 | from waeup.kofa.browser.layout import action, UtilityView |
---|
29 | from kofacustom.nigeria.applicants.browser import ( |
---|
30 | NigeriaApplicantDisplayFormPage, |
---|
31 | NigeriaPDFApplicationSlip, |
---|
32 | NigeriaApplicantManageFormPage, |
---|
33 | NigeriaApplicantEditFormPage) |
---|
34 | from kofacustom.nigeria.applicants.interfaces import ( |
---|
35 | UG_OMIT_DISPLAY_FIELDS, |
---|
36 | UG_OMIT_PDF_FIELDS, |
---|
37 | UG_OMIT_MANAGE_FIELDS, |
---|
38 | UG_OMIT_EDIT_FIELDS, |
---|
39 | PG_OMIT_DISPLAY_FIELDS, |
---|
40 | PG_OMIT_PDF_FIELDS, |
---|
41 | PG_OMIT_MANAGE_FIELDS, |
---|
42 | PG_OMIT_EDIT_FIELDS, |
---|
43 | ) |
---|
44 | from waeup.kofa.applicants.workflow import ( |
---|
45 | ADMITTED, PAID, STARTED, NOT_ADMITTED, CREATED) |
---|
46 | from kofacustom.edopoly.applicants.interfaces import ( |
---|
47 | ICustomUGApplicantEdit, ICustomUGApplicant, |
---|
48 | ICustomPGApplicantEdit, ICustomPGApplicant, |
---|
49 | ICustomApplicant,) |
---|
50 | |
---|
51 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
52 | |
---|
53 | # Fields to be omitted in all display forms. course_admitted is |
---|
54 | # rendered separately. |
---|
55 | |
---|
56 | OMIT_DISPLAY_FIELDS = ('locked', 'course_admitted', |
---|
57 | 'result_uploaded', 'suspended', 'special_application', |
---|
58 | 'bank_account_number', |
---|
59 | 'bank_account_name', |
---|
60 | 'bank_name') |
---|
61 | |
---|
62 | # UG students are all undergraduate students. |
---|
63 | UG_OMIT_DISPLAY_FIELDS = OMIT_DISPLAY_FIELDS + ( |
---|
64 | #'jamb_subjects', |
---|
65 | 'programme_type',) |
---|
66 | UG_OMIT_PDF_FIELDS = UG_OMIT_DISPLAY_FIELDS + ('phone',) |
---|
67 | UG_OMIT_MANAGE_FIELDS = ( |
---|
68 | 'special_application', |
---|
69 | #'jamb_subjects', |
---|
70 | 'programme_type') |
---|
71 | UG_OMIT_EDIT_FIELDS = UG_OMIT_MANAGE_FIELDS + UG_OMIT_DISPLAY_FIELDS + ( |
---|
72 | 'student_id', |
---|
73 | 'notice', |
---|
74 | 'screening_score', |
---|
75 | 'screening_venue', |
---|
76 | 'screening_date', |
---|
77 | 'aggregate') |
---|
78 | |
---|
79 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
80 | """A display view for applicant data. |
---|
81 | """ |
---|
82 | grok.template('applicantdisplaypage') |
---|
83 | |
---|
84 | @property |
---|
85 | def form_fields(self): |
---|
86 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
87 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
88 | for field in UG_OMIT_DISPLAY_FIELDS: |
---|
89 | form_fields = form_fields.omit(field) |
---|
90 | form_fields['notice'].custom_widget = BytesDisplayWidget |
---|
91 | #form_fields['jamb_subjects'].custom_widget = BytesDisplayWidget |
---|
92 | if not getattr(self.context, 'student_id'): |
---|
93 | form_fields = form_fields.omit('student_id') |
---|
94 | if not getattr(self.context, 'screening_score'): |
---|
95 | form_fields = form_fields.omit('screening_score') |
---|
96 | if not getattr(self.context, 'screening_venue'): |
---|
97 | form_fields = form_fields.omit('screening_venue') |
---|
98 | if not getattr(self.context, 'screening_date'): |
---|
99 | form_fields = form_fields.omit('screening_date') |
---|
100 | if not self.context.admchecking_fee_paid(): |
---|
101 | form_fields = form_fields.omit( |
---|
102 | 'screening_score', 'aggregate', 'student_id') |
---|
103 | return form_fields |
---|
104 | |
---|
105 | @property |
---|
106 | def admission_checking_info(self): |
---|
107 | if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \ |
---|
108 | not self.context.admchecking_fee_paid(): |
---|
109 | return _('You must pay the admission checking fee ' |
---|
110 | 'to view your screening results and your course admitted.') |
---|
111 | |
---|
112 | @property |
---|
113 | def display_actions(self): |
---|
114 | state = IWorkflowState(self.context).getState() |
---|
115 | actions = [] |
---|
116 | if state in (ADMITTED, NOT_ADMITTED, CREATED) \ |
---|
117 | and not self.context.admchecking_fee_paid(): |
---|
118 | actions = [_('Add admission checking payment ticket')] |
---|
119 | return actions |
---|
120 | |
---|
121 | def getCourseAdmitted(self): |
---|
122 | """Return link, title and code in html format to the certificate |
---|
123 | admitted. |
---|
124 | """ |
---|
125 | if self.admission_checking_info: |
---|
126 | return '<span class="hint">%s</span>' % self.admission_checking_info |
---|
127 | return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted() |
---|
128 | |
---|
129 | @action(_('Add admission checking payment ticket'), style='primary') |
---|
130 | def addPaymentTicket(self, **data): |
---|
131 | self.redirect(self.url(self.context, '@@addacp')) |
---|
132 | return |
---|
133 | |
---|
134 | class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View): |
---|
135 | """ Page to add an admission checking online payment ticket. |
---|
136 | """ |
---|
137 | grok.context(ICustomApplicant) |
---|
138 | grok.name('addacp') |
---|
139 | grok.require('waeup.payApplicant') |
---|
140 | factory = u'waeup.ApplicantOnlinePayment' |
---|
141 | |
---|
142 | def _setPaymentDetails(self, payment): |
---|
143 | container = self.context.__parent__ |
---|
144 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
145 | session = str(container.year) |
---|
146 | try: |
---|
147 | session_config = grok.getSite()['configuration'][session] |
---|
148 | except KeyError: |
---|
149 | return _(u'Session configuration object is not available.'), None |
---|
150 | payment.p_id = "p%s" % timestamp |
---|
151 | payment.p_item = container.title |
---|
152 | payment.p_session = container.year |
---|
153 | payment.amount_auth = 0.0 |
---|
154 | payment.p_category = 'admission_checking' |
---|
155 | payment.amount_auth = session_config.admchecking_fee |
---|
156 | if payment.amount_auth in (0.0, None): |
---|
157 | return _('Amount could not be determined.'), None |
---|
158 | return |
---|
159 | |
---|
160 | def update(self): |
---|
161 | if self.context.admchecking_fee_paid(): |
---|
162 | self.flash( |
---|
163 | _('Admission checking payment has already been made.'), |
---|
164 | type='warning') |
---|
165 | self.redirect(self.url(self.context)) |
---|
166 | return |
---|
167 | payment = createObject(self.factory) |
---|
168 | failure = self._setPaymentDetails(payment) |
---|
169 | if failure is not None: |
---|
170 | self.flash(failure[0], type='danger') |
---|
171 | self.redirect(self.url(self.context)) |
---|
172 | return |
---|
173 | self.context[payment.p_id] = payment |
---|
174 | self.flash(_('Payment ticket created.')) |
---|
175 | self.redirect(self.url(payment)) |
---|
176 | return |
---|
177 | |
---|
178 | def render(self): |
---|
179 | return |
---|
180 | |
---|
181 | class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip): |
---|
182 | """Deliver a PDF slip of the context. |
---|
183 | """ |
---|
184 | |
---|
185 | def update(self): |
---|
186 | super(CustomExportPDFPageApplicationSlip, self).update() |
---|
187 | if self.context.state in (ADMITTED, NOT_ADMITTED, CREATED) and \ |
---|
188 | not self.context.admchecking_fee_paid(): |
---|
189 | self.flash( |
---|
190 | _('Please pay admission checking fee before trying to download ' |
---|
191 | 'the application slip.'), type='warning') |
---|
192 | return self.redirect(self.url(self.context)) |
---|
193 | return |
---|
194 | |
---|
195 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
196 | |
---|
197 | @property |
---|
198 | def form_fields(self): |
---|
199 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
200 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
201 | for field in UG_OMIT_PDF_FIELDS: |
---|
202 | form_fields = form_fields.omit(field) |
---|
203 | if not getattr(self.context, 'student_id'): |
---|
204 | form_fields = form_fields.omit('student_id') |
---|
205 | if not getattr(self.context, 'screening_score'): |
---|
206 | form_fields = form_fields.omit('screening_score') |
---|
207 | if not getattr(self.context, 'screening_venue'): |
---|
208 | form_fields = form_fields.omit('screening_venue') |
---|
209 | if not getattr(self.context, 'screening_date'): |
---|
210 | form_fields = form_fields.omit('screening_date') |
---|
211 | return form_fields |
---|
212 | |
---|
213 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
214 | """A full edit view for applicant data. |
---|
215 | """ |
---|
216 | |
---|
217 | @property |
---|
218 | def form_fields(self): |
---|
219 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
220 | form_fields = grok.AutoFields(ICustomUGApplicant) |
---|
221 | for field in UG_OMIT_MANAGE_FIELDS: |
---|
222 | form_fields = form_fields.omit(field) |
---|
223 | form_fields['student_id'].for_display = True |
---|
224 | form_fields['applicant_id'].for_display = True |
---|
225 | return form_fields |
---|
226 | |
---|
227 | class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): |
---|
228 | """An applicant-centered edit view for applicant data. |
---|
229 | """ |
---|
230 | |
---|
231 | @property |
---|
232 | def form_fields(self): |
---|
233 | target = getattr(self.context.__parent__, 'prefix', None) |
---|
234 | form_fields = grok.AutoFields(ICustomUGApplicantEdit) |
---|
235 | for field in UG_OMIT_EDIT_FIELDS: |
---|
236 | form_fields = form_fields.omit(field) |
---|
237 | form_fields['applicant_id'].for_display = True |
---|
238 | form_fields['reg_number'].for_display = True |
---|
239 | return form_fields |
---|