1 | ## $Id: browser.py 13615 2016-01-14 14:41:20Z 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.component import getUtility, createObject |
---|
23 | from zope.security import checkPermission |
---|
24 | from zope.i18n import translate |
---|
25 | from hurry.workflow.interfaces import IWorkflowState |
---|
26 | from waeup.kofa.browser.layout import action, UtilityView |
---|
27 | from waeup.kofa.interfaces import IExtFileStore, IKofaUtils |
---|
28 | from waeup.kofa.applicants.browser import ( |
---|
29 | ApplicantRegistrationPage, ApplicantsContainerPage, |
---|
30 | ApplicationFeePaymentAddPage, |
---|
31 | OnlinePaymentApprovePage, |
---|
32 | ExportPDFPageApplicationSlip) |
---|
33 | from waeup.kofa.applicants.interfaces import ( |
---|
34 | ISpecialApplicant, IApplicantsUtils) |
---|
35 | from waeup.kofa.browser.interfaces import IPDFCreator |
---|
36 | from kofacustom.nigeria.applicants.browser import ( |
---|
37 | NigeriaApplicantDisplayFormPage, |
---|
38 | NigeriaApplicantManageFormPage, |
---|
39 | NigeriaPDFApplicationSlip) |
---|
40 | from waeup.uniben.applicants.interfaces import ( |
---|
41 | ICustomApplicant) |
---|
42 | from waeup.kofa.applicants.workflow import ADMITTED, PAID |
---|
43 | |
---|
44 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
45 | |
---|
46 | PASTQ_ALL = ['ADT','EPCS','ESM','HEK','VTE'] |
---|
47 | |
---|
48 | PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL', |
---|
49 | 'PHL','THR','BUL','JIL','LAW','PPL','PUL'] + PASTQ_ALL |
---|
50 | |
---|
51 | PASTQ_BS = ['ANT','ANY','CHH','COH','HAE','MED','MEH','PHS','SUR', |
---|
52 | 'PCG','PCH','PCO', 'PCT','PHA','PHM','PMB','ANA','MBC', |
---|
53 | 'MLS','NSC','PSY','DPV','ODR','OSP','PER', 'RES','AEB', |
---|
54 | 'BCH','BOT','CED','EVL','MCB','OPT','PBB','SLT','ZOO', |
---|
55 | 'AEE','ANS', 'CRS','FIS','FOW','SOS'] + PASTQ_ALL |
---|
56 | |
---|
57 | PASTQ_EPS = ['CHE','CVE','DMIC','EEE','MCH','PEE','PRE','CHM', |
---|
58 | 'CSC','GLY','MTH','PHY'] + PASTQ_ALL |
---|
59 | |
---|
60 | PASTQ_MSS = ['ACC','BNK','BUS','ECO','GEO','POL','SAA','SWK'] + PASTQ_ALL |
---|
61 | |
---|
62 | class CustomApplicantsContainerPage(ApplicantsContainerPage): |
---|
63 | """The standard view for regular applicant containers. |
---|
64 | """ |
---|
65 | |
---|
66 | @property |
---|
67 | def form_fields(self): |
---|
68 | form_fields = super(CustomApplicantsContainerPage, self).form_fields |
---|
69 | usertype = getattr(self.request.principal, 'user_type', None) |
---|
70 | if self.request.principal.id == 'zope.anybody' or \ |
---|
71 | usertype in ('applicant', 'student'): |
---|
72 | return form_fields.omit('application_fee') |
---|
73 | return form_fields |
---|
74 | |
---|
75 | class CustomApplicantRegistrationPage(ApplicantRegistrationPage): |
---|
76 | """Captcha'd registration page for applicants. |
---|
77 | """ |
---|
78 | |
---|
79 | def _redirect(self, email, password, applicant_id): |
---|
80 | # Forward email and credentials to landing page. |
---|
81 | self.redirect(self.url(self.context, 'registration_complete', |
---|
82 | data = dict(email=email, password=password, |
---|
83 | applicant_id=applicant_id))) |
---|
84 | return |
---|
85 | |
---|
86 | class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): |
---|
87 | """A display view for applicant data. |
---|
88 | """ |
---|
89 | grok.template('applicantdisplaypage') |
---|
90 | |
---|
91 | def _show_pastq_putme(self): |
---|
92 | return self.target.startswith('putme') \ |
---|
93 | and self.context.state in ('paid', 'submitted') \ |
---|
94 | and getattr(self.context, 'course1') is not None |
---|
95 | |
---|
96 | @property |
---|
97 | def show_pastq_al(self): |
---|
98 | return self._show_pastq_putme() \ |
---|
99 | and self.context.course1.__parent__.__parent__.code in PASTQ_AL |
---|
100 | |
---|
101 | @property |
---|
102 | def show_pastq_bs(self): |
---|
103 | return self._show_pastq_putme() \ |
---|
104 | and self.context.course1.__parent__.__parent__.code in PASTQ_BS |
---|
105 | |
---|
106 | @property |
---|
107 | def show_pastq_eps(self): |
---|
108 | return self._show_pastq_putme() \ |
---|
109 | and self.context.course1.__parent__.__parent__.code in PASTQ_EPS |
---|
110 | |
---|
111 | @property |
---|
112 | def show_pastq_mss(self): |
---|
113 | return self._show_pastq_putme() \ |
---|
114 | and self.context.course1.__parent__.__parent__.code in PASTQ_MSS |
---|
115 | |
---|
116 | @property |
---|
117 | def show_pastq_pude(self): |
---|
118 | return self.target.startswith('pude') \ |
---|
119 | and self.context.state in ('paid', 'submitted') |
---|
120 | |
---|
121 | # Customizations for admission checking payments |
---|
122 | |
---|
123 | @property |
---|
124 | def form_fields(self): |
---|
125 | form_fields = super(CustomApplicantDisplayFormPage, self).form_fields |
---|
126 | if not self.context.admchecking_fee_paid(): |
---|
127 | form_fields = form_fields.omit( |
---|
128 | 'screening_score', 'aggregate', 'student_id') |
---|
129 | return form_fields |
---|
130 | |
---|
131 | @property |
---|
132 | def display_actions(self): |
---|
133 | state = IWorkflowState(self.context).getState() |
---|
134 | actions = [] |
---|
135 | if state == ADMITTED and not self.context.admchecking_fee_paid(): |
---|
136 | actions = [_('Add admission checking payment ticket')] |
---|
137 | return actions |
---|
138 | |
---|
139 | |
---|
140 | def getCourseAdmitted(self): |
---|
141 | """Return link, title and code in html format to the certificate |
---|
142 | admitted. |
---|
143 | """ |
---|
144 | course_admitted = self.context.course_admitted |
---|
145 | if getattr(course_admitted, '__parent__',None) and \ |
---|
146 | self.context.admchecking_fee_paid(): |
---|
147 | url = self.url(course_admitted) |
---|
148 | title = course_admitted.title |
---|
149 | code = course_admitted.code |
---|
150 | return '<a href="%s">%s - %s</a>' %(url,code,title) |
---|
151 | return '' |
---|
152 | |
---|
153 | @property |
---|
154 | def admission_checking_info(self): |
---|
155 | if self.context.state == ADMITTED and \ |
---|
156 | not self.context.admchecking_fee_paid(): |
---|
157 | return _('You must pay the admission checking fee ' |
---|
158 | 'to view your screening results and course admitted.') |
---|
159 | return |
---|
160 | |
---|
161 | @action(_('Add admission checking payment ticket'), style='primary') |
---|
162 | def addPaymentTicket(self, **data): |
---|
163 | self.redirect(self.url(self.context, '@@addacp')) |
---|
164 | return |
---|
165 | |
---|
166 | class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): |
---|
167 | """ Page to add an online payment ticket |
---|
168 | """ |
---|
169 | |
---|
170 | @property |
---|
171 | def custom_requirements(self): |
---|
172 | store = getUtility(IExtFileStore) |
---|
173 | if not store.getFileByContext(self.context, attr=u'passport.jpg'): |
---|
174 | return _('Upload your 1"x1" Red background passport photo before making payment.') |
---|
175 | return '' |
---|
176 | |
---|
177 | class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View): |
---|
178 | """ Page to add an admission checking online payment ticket. |
---|
179 | """ |
---|
180 | grok.context(ICustomApplicant) |
---|
181 | grok.name('addacp') |
---|
182 | grok.require('waeup.payApplicant') |
---|
183 | factory = u'waeup.ApplicantOnlinePayment' |
---|
184 | |
---|
185 | def _setPaymentDetails(self, payment): |
---|
186 | container = self.context.__parent__ |
---|
187 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
188 | session = str(container.year) |
---|
189 | try: |
---|
190 | session_config = grok.getSite()['configuration'][session] |
---|
191 | except KeyError: |
---|
192 | return _(u'Session configuration object is not available.'), None |
---|
193 | payment.p_id = "p%s" % timestamp |
---|
194 | payment.p_item = container.title |
---|
195 | payment.p_session = container.year |
---|
196 | payment.amount_auth = 0.0 |
---|
197 | payment.p_category = 'admission_checking' |
---|
198 | payment.amount_auth = session_config.admchecking_fee |
---|
199 | if payment.amount_auth in (0.0, None): |
---|
200 | return _('Amount could not be determined.'), None |
---|
201 | return |
---|
202 | |
---|
203 | def update(self): |
---|
204 | if self.context.admchecking_fee_paid(): |
---|
205 | self.flash( |
---|
206 | _('Admission checking payment has already been made.'), |
---|
207 | type='warning') |
---|
208 | self.redirect(self.url(self.context)) |
---|
209 | return |
---|
210 | payment = createObject(self.factory) |
---|
211 | failure = self._setPaymentDetails(payment) |
---|
212 | if failure is not None: |
---|
213 | self.flash(failure[0], type='danger') |
---|
214 | self.redirect(self.url(self.context)) |
---|
215 | return |
---|
216 | self.context[payment.p_id] = payment |
---|
217 | self.flash(_('Payment ticket created.')) |
---|
218 | self.redirect(self.url(payment)) |
---|
219 | return |
---|
220 | |
---|
221 | def render(self): |
---|
222 | return |
---|
223 | |
---|
224 | |
---|
225 | class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): |
---|
226 | |
---|
227 | @property |
---|
228 | def custom_upload_requirements(self): |
---|
229 | if not checkPermission('waeup.uploadPassportPictures', self.context): |
---|
230 | return _('You are not entitled to upload passport pictures.') |
---|
231 | |
---|
232 | class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage): |
---|
233 | """ Approval view |
---|
234 | """ |
---|
235 | |
---|
236 | def update(self): |
---|
237 | if self.context.p_category == 'admission_checking': |
---|
238 | if self.context.p_state == 'paid': |
---|
239 | flashtype = 'warning' |
---|
240 | msg = _('This ticket has already been paid.') |
---|
241 | log = None |
---|
242 | else: |
---|
243 | self.context.approve() |
---|
244 | log = 'payment approved: %s' % self.context.p_id |
---|
245 | msg = _('Payment approved') |
---|
246 | flashtype = 'success' |
---|
247 | else: |
---|
248 | flashtype, msg, log = self.context.approveApplicantPayment() |
---|
249 | if log is not None: |
---|
250 | applicant = self.context.__parent__ |
---|
251 | # Add log message to applicants.log |
---|
252 | applicant.writeLogMessage(self, log) |
---|
253 | # Add log message to payments.log |
---|
254 | self.context.logger.info( |
---|
255 | '%s,%s,%s,%s,%s,,,,,,' % ( |
---|
256 | applicant.applicant_id, |
---|
257 | self.context.p_id, self.context.p_category, |
---|
258 | self.context.amount_auth, self.context.r_code)) |
---|
259 | self.flash(msg, type=flashtype) |
---|
260 | return |
---|
261 | |
---|
262 | class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip): |
---|
263 | """Deliver a PDF slip of the context. |
---|
264 | """ |
---|
265 | |
---|
266 | def update(self): |
---|
267 | super(CustomExportPDFPageApplicationSlip, self).update() |
---|
268 | if self.context.state == ADMITTED and \ |
---|
269 | not self.context.admchecking_fee_paid(): |
---|
270 | self.flash( |
---|
271 | _('Please pay admission checking fee before trying to download ' |
---|
272 | 'the application slip.'), type='warning') |
---|
273 | return self.redirect(self.url(self.context)) |
---|
274 | return |
---|
275 | |
---|
276 | class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): |
---|
277 | |
---|
278 | def _getPDFCreator(self): |
---|
279 | if 'afak' in self.target: |
---|
280 | return getUtility(IPDFCreator, name='akoka_pdfcreator') |
---|
281 | return getUtility(IPDFCreator) |
---|
282 | |
---|
283 | @property |
---|
284 | def title(self): |
---|
285 | container_title = self.context.__parent__.title |
---|
286 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
287 | ar_translation = translate(_('Application Record'), |
---|
288 | 'waeup.kofa', target_language=portal_language) |
---|
289 | if 'afas' in self.target: |
---|
290 | return 'Federal College of Education (Technical) Asaba - %s %s %s' % ( |
---|
291 | container_title, ar_translation, |
---|
292 | self.context.application_number) |
---|
293 | elif 'afak' in self.target: |
---|
294 | return 'Federal College of Education (Technical) Akoka - %s %s %s' % ( |
---|
295 | container_title, ar_translation, |
---|
296 | self.context.application_number) |
---|
297 | elif self.target == 'pgn': |
---|
298 | return 'National Institute for Legislative Studies (NILS) - %s %s %s' % ( |
---|
299 | container_title, ar_translation, |
---|
300 | self.context.application_number) |
---|
301 | return '%s - %s %s' % (container_title, |
---|
302 | ar_translation, self.context.application_number) |
---|