## $Id: browser.py 9378 2012-10-22 05:16:08Z henrik $ ## ## Copyright (C) 2012 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 ## import grok from zope.formlib.textwidgets import BytesDisplayWidget from zope.component import getUtility from zope.i18n import translate from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget from waeup.kofa.interfaces import IExtFileStore from waeup.kofa.browser.layout import action from waeup.kofa.students.browser import ( StudentPersonalDisplayFormPage, StudentPersonalManageFormPage, StudentClearanceManageFormPage, StudentClearanceEditFormPage, StudentClearanceDisplayFormPage, OnlinePaymentFakeApprovePage, ExportPDFClearanceSlipPage, StudentBaseManageFormPage, StudentBaseDisplayFormPage, StudentBaseEditFormPage, StudentPersonalEditFormPage, OnlinePaymentDisplayFormPage, OnlinePaymentAddFormPage, OnlinePaymentBreadcrumb, ExportPDFPaymentSlipPage, ExportPDFCourseRegistrationSlipPage, ExportPDFBedTicketSlipPage, StudentFilesUploadPage, emit_lock_message) from waeup.kofa.students.viewlets import ( PaymentReceiptActionButton, StudentPassportActionButton) from kofacustom.nigeria.students.interfaces import ( INigeriaStudentBase, INigeriaStudent, INigeriaStudentPersonal, INigeriaUGStudentClearance,INigeriaPGStudentClearance, INigeriaStudentOnlinePayment ) from waeup.kofa.students.workflow import ADMITTED from kofacustom.nigeria.interfaces import MessageFactory as _ class NigeriaOnlinePaymentBreadcrumb(OnlinePaymentBreadcrumb): """A breadcrumb for payments. """ grok.context(INigeriaStudentOnlinePayment) class PaymentReceiptActionButton(PaymentReceiptActionButton): grok.order(4) grok.context(INigeriaStudentOnlinePayment) class NigeriaStudentBaseDisplayFormPage(StudentBaseDisplayFormPage): """ Page to display student base data """ form_fields = grok.AutoFields(INigeriaStudentBase).omit('password', 'suspended') class NigeriaStudentBaseManageFormPage(StudentBaseManageFormPage): """ View to manage student base data """ form_fields = grok.AutoFields(INigeriaStudentBase).omit( 'student_id', 'adm_code', 'suspended') class NigeriaStudentBaseEditFormPage(StudentBaseEditFormPage): """ View to edit student base data """ form_fields = grok.AutoFields(INigeriaStudentBase).select( 'email', 'phone') class NigeriaStudentPersonalDisplayFormPage(StudentPersonalDisplayFormPage): """ Page to display student personal data """ form_fields = grok.AutoFields(INigeriaStudentPersonal) form_fields['perm_address'].custom_widget = BytesDisplayWidget form_fields['next_kin_address'].custom_widget = BytesDisplayWidget class NigeriaStudentPersonalEditFormPage(StudentPersonalEditFormPage): """ Page to edit personal data """ form_fields = grok.AutoFields(INigeriaStudentPersonal) class NigeriaStudentPersonalManageFormPage(StudentPersonalManageFormPage): """ Page to edit personal data """ form_fields = grok.AutoFields(INigeriaStudentPersonal) class NigeriaStudentClearanceDisplayFormPage(StudentClearanceDisplayFormPage): """ Page to display student clearance data """ @property def form_fields(self): if self.context.is_postgrad: form_fields = grok.AutoFields( INigeriaPGStudentClearance).omit('clearance_locked') else: form_fields = grok.AutoFields( INigeriaUGStudentClearance).omit('clearance_locked') return form_fields class NigeriaExportPDFClearanceSlipPage(ExportPDFClearanceSlipPage): """Deliver a PDF slip of the context. """ omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email') @property def form_fields(self): if self.context.is_postgrad: form_fields = grok.AutoFields( INigeriaPGStudentClearance).omit('clearance_locked') else: form_fields = grok.AutoFields( INigeriaUGStudentClearance).omit('clearance_locked') return form_fields class NigeriaStudentClearanceManageFormPage(StudentClearanceManageFormPage): """ Page to edit student clearance data """ @property def form_fields(self): if self.context.is_postgrad: form_fields = grok.AutoFields( INigeriaPGStudentClearance).omit('clr_code') else: form_fields = grok.AutoFields( INigeriaUGStudentClearance).omit('clr_code') return form_fields class NigeriaStudentClearanceEditFormPage(StudentClearanceEditFormPage): """ View to edit student clearance data by student """ @property def form_fields(self): if self.context.is_postgrad: form_fields = grok.AutoFields(INigeriaPGStudentClearance).omit( 'clearance_locked', 'nysc_location', 'clr_code') else: form_fields = grok.AutoFields(INigeriaUGStudentClearance).omit( 'clearance_locked', 'clr_code') return form_fields class NigeriaExportPDFCourseRegistrationSlipPage(ExportPDFCourseRegistrationSlipPage): """Deliver a PDF slip of the context. """ omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email') class NigeriaOnlinePaymentDisplayFormPage(OnlinePaymentDisplayFormPage): """ Page to view an online payment ticket """ grok.context(INigeriaStudentOnlinePayment) form_fields = grok.AutoFields(INigeriaStudentOnlinePayment) form_fields[ 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') form_fields[ 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') class NigeriaOnlinePaymentAddFormPage(OnlinePaymentAddFormPage): """ Page to add an online payment ticket """ form_fields = grok.AutoFields(INigeriaStudentOnlinePayment).select( 'p_category') class NigeriaOnlinePaymentFakeApprovePage(OnlinePaymentFakeApprovePage): """ Disable payment approval view for students. This view is used for browser tests only and has to be neutralized here! """ grok.name('fake_approve') grok.require('waeup.managePortal') def update(self): return class NigeriaExportPDFPaymentSlipPage(ExportPDFPaymentSlipPage): """Deliver a PDF slip of the context. """ grok.context(INigeriaStudentOnlinePayment) form_fields = grok.AutoFields(INigeriaStudentOnlinePayment) form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email') class NigeriaExportPDFBedTicketSlipPage(ExportPDFBedTicketSlipPage): """Deliver a PDF slip of the context. """ omit_fields = ('password', 'suspended', 'phone', 'adm_code', 'sex', 'email') class StudentPassportActionButton(StudentPassportActionButton): @property def target_url(self): slip = getUtility(IExtFileStore).getFileByContext( self.context, 'application_slip') if self.context.state != ADMITTED or slip is not None: return '' return self.view.url(self.view.context, self.target) class NigeriaStudentFilesUploadPage(StudentFilesUploadPage): """ View to upload passport picture. Students are not allowed to change the picture if they passed the regular Kofa application. """ def update(self): slip = getUtility(IExtFileStore).getFileByContext( self.context, 'application_slip') if self.context.state != ADMITTED or slip is not None: emit_lock_message(self) return super(StudentFilesUploadPage, self).update() return