## $Id: browser.py 13947 2016-06-15 14:45:38Z 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.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) 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) from waeup.kofa.applicants.workflow import ADMITTED, PAID, STARTED from waeup.uniben.interfaces import MessageFactory as _ PASTQ_ALL = ['ADT','EPCS','ESM','HEK','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 = ['CHE','CVE','DMIC','EEE','MCH','PEE','PRE','CHM', 'CSC','GLY','MTH','PHY'] + PASTQ_ALL PASTQ_MSS = ['ACC','BNK','BUS','ECO','GEO','POL','SAA','SWK'] + 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', ) 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 @property def show_pastq_al(self): return self._show_pastq_putme() \ and self.context.course1.__parent__.__parent__.code in PASTQ_AL @property def show_pastq_bs(self): return self._show_pastq_putme() \ and self.context.course1.__parent__.__parent__.code in PASTQ_BS @property def show_pastq_eps(self): return self._show_pastq_putme() \ and self.context.course1.__parent__.__parent__.code in PASTQ_EPS @property def show_pastq_mss(self): return self._show_pastq_putme() \ and self.context.course1.__parent__.__parent__.code 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 form_fields = super(CustomApplicantDisplayFormPage, self).form_fields 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. """ course_admitted = self.context.course_admitted if getattr(course_admitted, '__parent__',None) and \ self.context.admchecking_fee_paid(): url = self.url(course_admitted) title = course_admitted.title code = course_admitted.code return '%s - %s' %(url,code,title) return '' @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 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 form_fields = super(CustomApplicantManageFormPage, self).form_fields return form_fields class CustomApplicantEditFormPage(NigeriaApplicantEditFormPage): """An applicant-centered edit view for applicant data. """ @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 form_fields = super(CustomApplicantEditFormPage, self).form_fields 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 'afak' in self.target: 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 form_fields = super(CustomPDFApplicationSlip, self).form_fields 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 'afas' in self.target: return 'Federal College of Education (Technical) Asaba - %s %s %s' % ( container_title, ar_translation, self.context.application_number) elif 'afak' in self.target: 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)