## $Id: browser.py 15125 2018-09-05 11:10:00Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """UI components for basic applicants and related components. """ import grok from time import time from zope.component import getUtility, createObject from zope.formlib.textwidgets import BytesDisplayWidget from zope.security import checkPermission from zope.i18n import translate from hurry.workflow.interfaces import IWorkflowState from waeup.kofa.browser.layout import action, UtilityView from waeup.kofa.interfaces import IExtFileStore, IKofaUtils from waeup.kofa.applicants.browser import ( ApplicantRegistrationPage, ApplicantsContainerPage, ApplicationFeePaymentAddPage, OnlinePaymentApprovePage, ExportPDFPageApplicationSlip, ApplicantBaseDisplayFormPage) from waeup.kofa.students.interfaces import IStudentsUtils from waeup.kofa.applicants.interfaces import ( ISpecialApplicant, IApplicantsUtils) from waeup.kofa.browser.interfaces import IPDFCreator from kofacustom.nigeria.applicants.browser import ( NigeriaApplicantDisplayFormPage, NigeriaApplicantManageFormPage, NigeriaApplicantEditFormPage, NigeriaPDFApplicationSlip) from waeup.uniben.applicants.interfaces import ( ICustomApplicant, IUnibenRegistration, ICustomUGApplicant, ICustomPGApplicant, ICustomPGApplicantEdit, ICustomUGApplicantEdit, IPUTMEApplicantEdit) from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED from kofacustom.nigeria.applicants.interfaces import ( UG_OMIT_DISPLAY_FIELDS, UG_OMIT_PDF_FIELDS, UG_OMIT_MANAGE_FIELDS, UG_OMIT_EDIT_FIELDS, CBT_OMIT_DISPLAY_FIELDS, CBT_OMIT_PDF_FIELDS, CBT_OMIT_MANAGE_FIELDS, CBT_OMIT_EDIT_FIELDS, AFFIL_OMIT_DISPLAY_FIELDS, AFFIL_OMIT_PDF_FIELDS, AFFIL_OMIT_MANAGE_FIELDS, AFFIL_OMIT_EDIT_FIELDS, PG_OMIT_DISPLAY_FIELDS, PG_OMIT_PDF_FIELDS, PG_OMIT_MANAGE_FIELDS, PG_OMIT_EDIT_FIELDS, PUTME_OMIT_DISPLAY_FIELDS, PUTME_OMIT_PDF_FIELDS, PUTME_OMIT_MANAGE_FIELDS, PUTME_OMIT_EDIT_FIELDS, PUTME_OMIT_RESULT_SLIP_FIELDS, PUDE_OMIT_DISPLAY_FIELDS, PUDE_OMIT_PDF_FIELDS, PUDE_OMIT_MANAGE_FIELDS, PUDE_OMIT_EDIT_FIELDS, PUDE_OMIT_RESULT_SLIP_FIELDS, PRE_OMIT_DISPLAY_FIELDS, PRE_OMIT_PDF_FIELDS, PRE_OMIT_MANAGE_FIELDS, PRE_OMIT_EDIT_FIELDS, ) from waeup.uniben.interfaces import MessageFactory as _ PASTQ_ALL = ['ADT','CIT','DEF','DEM','EPCS','ESM','HEK','HSE','VTE'] PASTQ_AL = ['ENL','FAA','FOL','HIS','LAL', 'PHL','THR','BUL','JIL', 'LAW','PPL','PUL'] + PASTQ_ALL PASTQ_BS = ['ANT','ANY','CHH','COH','HAE','MED','MEH','PHS','SUR', 'PCG','PCH','PCO', 'PCT','PHA','PHM','PMB','ANA','MBC', 'MLS','NSC','PSY','DPV','ODR','OSP','PER', 'RES','AEB', 'BCH','BOT','CED','EVL','MCB','OPT','PBB','SLT','ZOO', 'AEE','ANS', 'CRS','FIS','FOW','SOS'] + PASTQ_ALL PASTQ_EPS = ['ARC','CHE','CVE','DMIC','EEE','GEM','MCH','PEE','PRE','CHM', 'CSC','GLY','MTH','QSV','PHY','CPE','STR'] + PASTQ_ALL PASTQ_MSS = ['ACC','BNK','BUS','ECO','ESM','GEO','POL','SAA','SWK', 'ACT','ENT','HRM','INS','MKT'] + PASTQ_ALL REGISTRATION_OMIT_DISPLAY_FIELDS = ( 'locked', 'suspended', ) REGISTRATION_OMIT_EDIT_FIELDS = ( 'locked', 'suspended', 'applicant_id', ) REGISTRATION_OMIT_MANAGE_FIELDS = ( 'applicant_id', ) REGISTRATION_OMIT_PDF_FIELDS = ( 'locked', 'suspended', ) PUTME_OMIT_PDF_FIELDS = PUTME_OMIT_PDF_FIELDS + ( 'fst_sit_results', 'scd_sit_results') class CustomApplicantsContainerPage(ApplicantsContainerPage): """The standard view for regular applicant containers. """ @property def form_fields(self): form_fields = super(CustomApplicantsContainerPage, self).form_fields usertype = getattr(self.request.principal, 'user_type', None) if self.request.principal.id == 'zope.anybody' or \ usertype in ('applicant', 'student'): return form_fields.omit('application_fee') return form_fields class CustomApplicantRegistrationPage(ApplicantRegistrationPage): """Captcha'd registration page for applicants. """ def _redirect(self, email, password, applicant_id): # Forward email and credentials to landing page. self.redirect(self.url(self.context, 'registration_complete', data = dict(email=email, password=password, applicant_id=applicant_id))) return class CustomApplicantDisplayFormPage(NigeriaApplicantDisplayFormPage): """A display view for applicant data. """ grok.template('applicantdisplaypage') @property def display_payments(self): if self.context.special or self.target == 'ictwk': return True return getattr(self.context.__parent__, 'application_fee', None) def _show_pastq_putme(self): return self.target.startswith('ase') \ and self.context.state in ('paid', 'submitted') \ and getattr(self.context, 'course1') is not None # return False @property def depcode(self): try: code = self.context.course1.__parent__.__parent__.code return code except: return @property def show_pastq_al(self): return self._show_pastq_putme() and self.depcode in PASTQ_AL @property def show_pastq_bs(self): return self._show_pastq_putme() and self.depcode in PASTQ_BS @property def show_pastq_eps(self): return self._show_pastq_putme() and self.depcode in PASTQ_EPS @property def show_pastq_mss(self): return self._show_pastq_putme() and self.depcode in PASTQ_MSS @property def show_pastq_pude(self): return self.target.startswith('pude') \ and self.context.state in ('paid', 'submitted') @property def label(self): if self.target == 'ictwk': container_title = self.context.__parent__.title return _('${a}
Registration Record ${b}', mapping = { 'a':container_title, 'b':self.context.application_number}) return super(CustomApplicantDisplayFormPage, self).label @property def form_fields(self): if self.target == 'ictwk': form_fields = grok.AutoFields(IUnibenRegistration) for field in REGISTRATION_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) return form_fields elif self.target is not None and self.target.startswith('pg'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PG_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pre'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('cbt'): form_fields = grok.AutoFields(ICustomUGApplicant) for field in CBT_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('akj'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ak'): form_fields = grok.AutoFields(ICustomUGApplicant) for field in AFFIL_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ase'): # was putme form_fields = grok.AutoFields(ICustomUGApplicant) for field in PUTME_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pude'): form_fields = grok.AutoFields(ICustomUGApplicant) for field in PUDE_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) else: form_fields = grok.AutoFields(ICustomUGApplicant) for field in UG_OMIT_DISPLAY_FIELDS: form_fields = form_fields.omit(field) #form_fields['perm_address'].custom_widget = BytesDisplayWidget form_fields['notice'].custom_widget = BytesDisplayWidget if not getattr(self.context, 'student_id'): form_fields = form_fields.omit('student_id') if not getattr(self.context, 'screening_score'): form_fields = form_fields.omit('screening_score') if not getattr(self.context, 'screening_venue') or self._not_paid(): form_fields = form_fields.omit('screening_venue') if not getattr(self.context, 'screening_date') or self._not_paid(): form_fields = form_fields.omit('screening_date') if not self.context.admchecking_fee_paid(): form_fields = form_fields.omit( 'screening_score', 'aggregate', 'student_id') return form_fields @property def display_actions(self): state = IWorkflowState(self.context).getState() actions = [] if state == ADMITTED and not self.context.admchecking_fee_paid(): actions = [_('Add admission checking payment ticket')] return actions def getCourseAdmitted(self): """Return link, title and code in html format to the certificate admitted. """ if self.admission_checking_info: return '%s' % self.admission_checking_info return super(CustomApplicantDisplayFormPage, self).getCourseAdmitted() @property def admission_checking_info(self): if self.context.state == ADMITTED and \ not self.context.admchecking_fee_paid(): return _('You must pay the admission checking fee ' 'to view your screening results and your course admitted.') return @action(_('Add admission checking payment ticket'), style='primary') def addPaymentTicket(self, **data): self.redirect(self.url(self.context, '@@addacp')) return class CustomApplicationFeePaymentAddPage(ApplicationFeePaymentAddPage): """ Page to add an online payment ticket """ @property def custom_requirements(self): store = getUtility(IExtFileStore) if not store.getFileByContext(self.context, attr=u'passport.jpg'): return _('Upload your 1"x1" Red background passport photo before making payment.') return '' class AdmissionCheckingFeePaymentAddPage(UtilityView, grok.View): """ Page to add an admission checking online payment ticket. """ grok.context(ICustomApplicant) grok.name('addacp') grok.require('waeup.payApplicant') factory = u'waeup.ApplicantOnlinePayment' def _setPaymentDetails(self, payment): container = self.context.__parent__ timestamp = ("%d" % int(time()*10000))[1:] session = str(container.year) try: session_config = grok.getSite()['configuration'][session] except KeyError: return _(u'Session configuration object is not available.'), None payment.p_id = "p%s" % timestamp payment.p_item = container.title payment.p_session = container.year payment.amount_auth = 0.0 payment.p_category = 'admission_checking' payment.amount_auth = session_config.admchecking_fee if payment.amount_auth in (0.0, None): return _('Amount could not be determined.'), None return def update(self): if self.context.admchecking_fee_paid(): self.flash( _('Admission checking payment has already been made.'), type='warning') self.redirect(self.url(self.context)) return payment = createObject(self.factory) failure = self._setPaymentDetails(payment) if failure is not None: self.flash(failure[0], type='danger') self.redirect(self.url(self.context)) return self.context[payment.p_id] = payment self.flash(_('Payment ticket created.')) self.redirect(self.url(payment)) return def render(self): return class CustomApplicantManageFormPage(NigeriaApplicantManageFormPage): @property def display_payments(self): if self.context.special or self.target == 'ictwk': return True return getattr(self.context.__parent__, 'application_fee', None) @property def custom_upload_requirements(self): if not checkPermission('waeup.uploadPassportPictures', self.context): return _('You are not entitled to upload passport pictures.') @property def label(self): if self.target == 'ictwk': container_title = self.context.__parent__.title return _('${a}
Registration Record ${b}', mapping = { 'a':container_title, 'b':self.context.application_number}) return super(CustomApplicantManageFormPage, self).label @property def form_fields(self): if self.target == 'ictwk': form_fields = grok.AutoFields(IUnibenRegistration) for field in REGISTRATION_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) state = IWorkflowState(self.context).getState() if state != STARTED: form_fields['registration_cats'].for_display = True return form_fields if self.target is not None and self.target.startswith('pg'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PG_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pre'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('cbt'): form_fields = grok.AutoFields(ICustomUGApplicant) for field in CBT_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('akj'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ak'): form_fields = grok.AutoFields(ICustomUGApplicant) for field in AFFIL_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ase'): # was putme form_fields = grok.AutoFields(ICustomUGApplicant) for field in PUTME_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pude'): form_fields = grok.AutoFields(ICustomUGApplicant) for field in PUDE_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) else: form_fields = grok.AutoFields(ICustomUGApplicant) for field in UG_OMIT_MANAGE_FIELDS: form_fields = form_fields.omit(field) form_fields['student_id'].for_display = True form_fields['applicant_id'].for_display = True return form_fields class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): """An applicant-centered edit view for applicant data. """ def unremovable(self, ticket): return True @property def display_payments(self): if self.context.special or self.target == 'ictwk': return True return getattr(self.context.__parent__, 'application_fee', None) @property def form_fields(self): if self.target == 'ictwk': form_fields = grok.AutoFields(IUnibenRegistration) for field in REGISTRATION_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) state = IWorkflowState(self.context).getState() if state != STARTED: form_fields['registration_cats'].for_display = True return form_fields if self.target is not None and self.target.startswith('pg'): form_fields = grok.AutoFields(ICustomPGApplicantEdit) for field in PG_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pre'): form_fields = grok.AutoFields(ICustomPGApplicantEdit) for field in PRE_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('cbt'): form_fields = grok.AutoFields(ICustomUGApplicantEdit) for field in CBT_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('akj'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ak'): form_fields = grok.AutoFields(ICustomUGApplicantEdit) for field in AFFIL_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ase'): # was putme form_fields = grok.AutoFields(IPUTMEApplicantEdit) for field in PUTME_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pude'): form_fields = grok.AutoFields(ICustomUGApplicantEdit) for field in PUDE_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) else: form_fields = grok.AutoFields(ICustomUGApplicantEdit) for field in UG_OMIT_EDIT_FIELDS: form_fields = form_fields.omit(field) form_fields['applicant_id'].for_display = True form_fields['reg_number'].for_display = True return form_fields @property def label(self): if self.target == 'ictwk': container_title = self.context.__parent__.title return _('${a}
Registration Record ${b}', mapping = { 'a':container_title, 'b':self.context.application_number}) return super(CustomApplicantEditFormPage, self).label class CustomOnlinePaymentApprovePage(OnlinePaymentApprovePage): """ Approval view """ def update(self): if self.context.p_category == 'admission_checking': if self.context.p_state == 'paid': flashtype = 'warning' msg = _('This ticket has already been paid.') log = None else: self.context.approve() log = 'payment approved: %s' % self.context.p_id msg = _('Payment approved') flashtype = 'success' else: flashtype, msg, log = self.context.approveApplicantPayment() if log is not None: applicant = self.context.__parent__ # Add log message to applicants.log applicant.writeLogMessage(self, log) # Add log message to payments.log self.context.logger.info( '%s,%s,%s,%s,%s,,,,,,' % ( applicant.applicant_id, self.context.p_id, self.context.p_category, self.context.amount_auth, self.context.r_code)) self.flash(msg, type=flashtype) return class CustomExportPDFPageApplicationSlip(ExportPDFPageApplicationSlip): """Deliver a PDF slip of the context. """ def update(self): super(CustomExportPDFPageApplicationSlip, self).update() if self.context.state == ADMITTED and \ not self.context.admchecking_fee_paid(): self.flash( _('Please pay admission checking fee before trying to download ' 'the application slip.'), type='warning') return self.redirect(self.url(self.context)) return class CustomPDFApplicationSlip(NigeriaPDFApplicationSlip): def _getPDFCreator(self): if self.target.startswith('ak'): return getUtility(IPDFCreator, name='akoka_pdfcreator') return getUtility(IPDFCreator) @property def form_fields(self): if self.target == 'ictwk': form_fields = grok.AutoFields(IUnibenRegistration) for field in REGISTRATION_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) return form_fields if self.target is not None and self.target.startswith('pg'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PG_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pre'): form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('cbt'): # uniben form_fields = grok.AutoFields(ICustomUGApplicant) for field in CBT_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('akj'): # uniben form_fields = grok.AutoFields(ICustomPGApplicant) for field in PRE_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ak'): # uniben form_fields = grok.AutoFields(ICustomUGApplicant) for field in AFFIL_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('ase'): # was putme form_fields = grok.AutoFields(ICustomUGApplicant) if self._reduced_slip(): for field in PUTME_OMIT_RESULT_SLIP_FIELDS: form_fields = form_fields.omit(field) else: for field in PUTME_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) elif self.target is not None and self.target.startswith('pude'): form_fields = grok.AutoFields(ICustomUGApplicant) if self._reduced_slip(): for field in PUDE_OMIT_RESULT_SLIP_FIELDS: form_fields = form_fields.omit(field) else: for field in PUDE_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) else: form_fields = grok.AutoFields(ICustomUGApplicant) for field in UG_OMIT_PDF_FIELDS: form_fields = form_fields.omit(field) if not getattr(self.context, 'student_id'): form_fields = form_fields.omit('student_id') if not getattr(self.context, 'screening_score'): form_fields = form_fields.omit('screening_score') if not getattr(self.context, 'screening_venue'): form_fields = form_fields.omit('screening_venue') if not getattr(self.context, 'screening_date'): form_fields = form_fields.omit('screening_date') return form_fields @property def title(self): container_title = self.context.__parent__.title portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE ar_translation = translate(_('Application Record'), 'waeup.kofa', target_language=portal_language) if self.target == 'ictwk': return '%s - Registration Record %s' % (container_title, self.context.application_number) elif self.target.startswith('ab'): return 'Federal College of Education (Technical) Asaba - %s %s %s' % ( container_title, ar_translation, self.context.application_number) elif self.target.startswith('ak'): return 'Federal College of Education (Technical) Akoka - %s - %s %s' % ( container_title, ar_translation, self.context.application_number) elif self.target == 'pgn': return 'National Institute for Legislative Studies (NILS) - %s %s %s' % ( container_title, ar_translation, self.context.application_number) return '%s - %s %s' % (container_title, ar_translation, self.context.application_number) class ExportScreeningInvitationSlip(UtilityView, grok.View): """Deliver a PDF slip of the context. """ grok.context(ICustomApplicant) grok.name('screening_invitation_slip.pdf') grok.require('waeup.viewApplication') form_fields = None label = u'Invitation Letter for Pre-Admission Screening' @property def note(self): notice = getattr(self.context.__parent__, 'application_slip_notice', None) if self.context.screening_date: return """



Dear %s,


You are invited for your Uniben Admission Screening Exercise on:

%s.

Please bring along this letter of invitation to the

%s

on your screening date.


Signed,

The Registrar




%s
""" % (self.context.display_fullname, self.context.screening_date, self.context.screening_venue, notice) return def update(self): if not self.context.screening_date: self.flash(_('Forbidden'), type="warning") self.redirect(self.url(self.context)) def render(self): applicantview = ApplicantBaseDisplayFormPage(self.context, self.request) students_utils = getUtility(IStudentsUtils) return students_utils.renderPDF(self,'screening_invitation_slip.pdf', self.context, applicantview, note=self.note)