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