## $Id: browser.py 11449 2014-02-27 05:47:00Z 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.i18n import translate from zope.schema.interfaces import ConstraintNotSatisfied from zope.component import getUtility from hurry.workflow.interfaces import IWorkflowInfo from waeup.kofa.interfaces import ( REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory) from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget from waeup.kofa.browser.layout import action, KofaEditFormPage from waeup.kofa.students.browser import ( StudyLevelEditFormPage, StudyLevelDisplayFormPage, StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage, CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, msave, emit_lock_message, StudentActivatePage, StudentDeactivatePage) from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS from kofacustom.nigeria.students.browser import ( NigeriaOnlinePaymentDisplayFormPage, NigeriaStudentBaseManageFormPage, NigeriaStudentClearanceEditFormPage, NigeriaOnlinePaymentAddFormPage, NigeriaExportPDFPaymentSlipPage, NigeriaExportPDFClearanceSlipPage, ) from waeup.uniben.students.interfaces import ( ICustomStudentOnlinePayment, ICustomStudentStudyCourse, ICustomStudentStudyLevel) from waeup.uniben.interfaces import MessageFactory as _ class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): """ Page to view an online payment ticket """ grok.context(ICustomStudentOnlinePayment) form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') form_fields[ 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') form_fields[ 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): """ View to edit student clearance data by student """ def dataNotComplete(self): store = getUtility(IExtFileStore) if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): return _('No birth certificate uploaded.') if not store.getFileByContext(self.context, attr=u'ref_let.jpg'): return _('No guarantor/referee letter uploaded.') if not store.getFileByContext(self.context, attr=u'acc_let.jpg'): return _('No acceptance letter uploaded.') if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'): return _('No first sitting result uploaded.') #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'): # return _('No second sitting result uploaded.') if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'): return _('No affidavit of non-membership of secret cults uploaded.') return False class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): """ Page to add an online payment ticket """ form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( 'p_category') class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): """Deliver a PDF slip of the context. """ grok.context(ICustomStudentOnlinePayment) form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage): """Deliver a PDF slip of the context. """ def render(self): studentview = StudentBasePDFFormPage(self.context.student, self.request, self.omit_fields) students_utils = getUtility(IStudentsUtils) return students_utils.renderPDF( self, 'clearance_slip.pdf', self.context.student, studentview, signatures=self._signatures(), sigs_in_footer=self._sigsInFooter(), show_scans=False, omit_fields=self.omit_fields) class StudyCourseCOEditFormPage(KofaEditFormPage): """ Page to edit the student study course data by clearance officers. This form page is available only in Uniben. """ grok.context(ICustomStudentStudyCourse) grok.name('edit_level') grok.require('waeup.clearStudent') label = _('Edit current level') pnav = 4 form_fields = grok.AutoFields( ICustomStudentStudyCourse).select('current_level') def update(self): if not (self.context.is_current and self.context.student.state == REQUESTED): emit_lock_message(self) return super(StudyCourseCOEditFormPage, self).update() return @action(_('Save'), style='primary') def save(self, **data): try: msave(self, **data) except ConstraintNotSatisfied: # The selected level might not exist in certificate self.flash(_('Current level not available for certificate.')) return #notify(grok.ObjectModifiedEvent(self.context.__parent__)) return class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): """ Page to edit the student study level data by students. """ grok.template('studyleveleditpage') class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): """ Page to display student study levels """ grok.template('studylevelpage') class CustomExportPDFCourseRegistrationSlipPage( ExportPDFCourseRegistrationSlipPage): """Deliver a PDF slip of the context. """ form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( 'level_verdict', 'gpa') @property def tabletitle(self): portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE tabletitle = [] tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', target_language=portal_language)) return tabletitle def render(self): portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE Code = translate('Code', 'waeup.kofa', target_language=portal_language) Title = translate('Title', 'waeup.kofa', target_language=portal_language) Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) studentview = StudentBasePDFFormPage(self.context.student, self.request, self.omit_fields) students_utils = getUtility(IStudentsUtils) tabledata = [] tableheader = [] contenttitle = [] for i in range(1,7): tabledata.append(sorted( [value for value in self.context.values() if value.semester == i], key=lambda value: str(value.semester) + value.code)) tableheader.append([(Code,'code', 2.5), (Title,'title', 5), (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), (Cred, 'credits', 1.5), ]) return students_utils.renderPDF( self, 'course_registration_slip.pdf', self.context.student, studentview, tableheader=tableheader, tabledata=tabledata, omit_fields=self.omit_fields ) class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage): """Deliver a PDF slip of the context. """ grok.name('course_result_slip.pdf') @property def tabletitle(self): portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE tabletitle = [] tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('Level Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa', target_language=portal_language)) tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa', target_language=portal_language)) return tabletitle @property def label(self): portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE lang = self.request.cookies.get('kofa.language', portal_language) level_title = translate(self.context.level_title, 'waeup.kofa', target_language=lang) return translate(_('Course Result Slip'), 'waeup.uniben', target_language=portal_language) \ + ' %s' % level_title def render(self): portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE Code = translate('Code', 'waeup.kofa', target_language=portal_language) Title = translate('Title', 'waeup.kofa', target_language=portal_language) Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language) Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language) Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language) Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) studentview = StudentBasePDFFormPage(self.context.student, self.request, self.omit_fields) students_utils = getUtility(IStudentsUtils) tabledata = [] tableheader = [] contenttitle = [] for i in range(1,7): tabledata.append(sorted( [value for value in self.context.values() if value.semester == i], key=lambda value: str(value.semester) + value.code)) tableheader.append([(Code,'code', 2.5), (Title,'title', 5), (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), (Cred, 'credits', 1.5), (Grade, 'grade', 1.5), ]) return students_utils.renderPDF( self, 'course_registration_slip.pdf', self.context.student, studentview, tableheader=tableheader, tabledata=tabledata, omit_fields=self.omit_fields ) class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): """ Page to display course tickets """ form_fields = grok.AutoFields(ICourseTicket).omit('score') class CustomStudentActivatePage(StudentActivatePage): """ Activate student account """ def update(self): self.context.suspended = False self.context.writeLogMessage(self, 'account activated') history = IObjectHistory(self.context) history.addMessage('Student account activated', user='undisclosed') self.flash(_('Student account has been activated.')) self.redirect(self.url(self.context)) return class CustomStudentDeactivatePage(StudentDeactivatePage): """ Deactivate student account """ def update(self): self.context.suspended = True self.context.writeLogMessage(self, 'account deactivated') history = IObjectHistory(self.context) history.addMessage('Student account deactivated', user='undisclosed') self.flash(_('Student account has been deactivated.')) self.redirect(self.url(self.context)) return