[8911] | 1 | ## $Id: browser.py 11602 2014-04-24 08:18:37Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2012 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 | import grok |
---|
| 19 | from zope.i18n import translate |
---|
[9914] | 20 | from zope.component import getUtility |
---|
[11597] | 21 | from waeup.kofa.browser.layout import UtilityView |
---|
[8911] | 22 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
[9914] | 23 | from waeup.kofa.interfaces import IKofaUtils |
---|
[11597] | 24 | from waeup.kofa.students.interfaces import IStudentsUtils, IStudent |
---|
[9914] | 25 | from waeup.kofa.students.browser import ( |
---|
| 26 | StudentBasePDFFormPage, |
---|
| 27 | CourseTicketAddFormPage, |
---|
| 28 | StudyLevelDisplayFormPage, |
---|
[10566] | 29 | ExportPDFTranscriptPage, |
---|
[10922] | 30 | ExportPDFAdmissionSlipPage, |
---|
[10269] | 31 | ) |
---|
[8911] | 32 | from kofacustom.nigeria.students.browser import ( |
---|
| 33 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 34 | NigeriaOnlinePaymentAddFormPage, |
---|
[10269] | 35 | NigeriaExportPDFPaymentSlipPage, |
---|
| 36 | NigeriaExportPDFCourseRegistrationSlipPage |
---|
| 37 | ) |
---|
[9496] | 38 | from waeup.aaue.students.interfaces import ( |
---|
[9914] | 39 | ICustomStudentOnlinePayment, |
---|
| 40 | ICustomStudentStudyLevel) |
---|
| 41 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[8911] | 42 | |
---|
| 43 | class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage): |
---|
| 44 | """ Page to view an online payment ticket |
---|
| 45 | """ |
---|
| 46 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 47 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 48 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 49 | form_fields[ |
---|
| 50 | 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 51 | form_fields[ |
---|
| 52 | 'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 53 | |
---|
| 54 | class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage): |
---|
| 55 | """ Page to add an online payment ticket |
---|
| 56 | """ |
---|
| 57 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select( |
---|
| 58 | 'p_category') |
---|
| 59 | |
---|
| 60 | class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage): |
---|
| 61 | """Deliver a PDF slip of the context. |
---|
| 62 | """ |
---|
| 63 | grok.context(ICustomStudentOnlinePayment) |
---|
[9853] | 64 | form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( |
---|
[9990] | 65 | 'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item') |
---|
[8911] | 66 | form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9496] | 67 | form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
[9914] | 68 | |
---|
| 69 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 70 | """ Page to display student study levels |
---|
| 71 | """ |
---|
| 72 | grok.context(ICustomStudentStudyLevel) |
---|
[10480] | 73 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
| 74 | 'total_credits', 'gpa') |
---|
[9914] | 75 | form_fields[ |
---|
| 76 | 'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') |
---|
| 77 | |
---|
| 78 | class CustomExportPDFCourseRegistrationSlipPage( |
---|
[10269] | 79 | NigeriaExportPDFCourseRegistrationSlipPage): |
---|
[9914] | 80 | """Deliver a PDF slip of the context. |
---|
| 81 | """ |
---|
| 82 | grok.context(ICustomStudentStudyLevel) |
---|
| 83 | form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit( |
---|
[10102] | 84 | 'level_session', 'level_verdict', |
---|
[10480] | 85 | 'validated_by', 'validation_date', 'gpa') |
---|
[9914] | 86 | |
---|
[10269] | 87 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
[10689] | 88 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', |
---|
[11538] | 89 | 'department', 'current_mode', 'current_level') |
---|
[10269] | 90 | |
---|
[9914] | 91 | @property |
---|
| 92 | def label(self): |
---|
| 93 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 94 | lang = self.request.cookies.get('kofa.language', portal_language) |
---|
| 95 | level_title = translate(self.context.level_title, 'waeup.kofa', |
---|
| 96 | target_language=lang) |
---|
| 97 | line0 = '' |
---|
| 98 | if self.context.student.current_mode.endswith('_pt'): |
---|
| 99 | line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n' |
---|
| 100 | line1 = translate(_('Course Registration Slip'), |
---|
| 101 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 102 | + ' %s' % level_title |
---|
| 103 | line2 = translate(_('Session'), |
---|
| 104 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 105 | + ' %s' % self.context.getSessionString |
---|
| 106 | return '%s%s\n%s' % (line0, line1, line2) |
---|
| 107 | |
---|
| 108 | @property |
---|
| 109 | def title(self): |
---|
| 110 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 111 | return translate(_('Units Registered'), 'waeup.kofa', |
---|
| 112 | target_language=portal_language) |
---|
| 113 | |
---|
| 114 | def _signatures(self): |
---|
[9968] | 115 | return ( |
---|
| 116 | [('I have selected the course on the advise of my Head of ' |
---|
| 117 | 'Department. <br>', _('Student\'s Signature'), '<br>')], |
---|
| 118 | [('This student has satisfied the department\'s requirements. ' |
---|
| 119 | 'I recommend to approve the course registration. <br>', |
---|
| 120 | _('Head of Department\'s Signature'), '<br>')], |
---|
| 121 | [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')], |
---|
| 122 | [('', _('Director\'s Signature'))] |
---|
| 123 | ) |
---|
[9914] | 124 | |
---|
| 125 | def render(self): |
---|
| 126 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 127 | Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language) |
---|
| 128 | Code = translate('Code', 'waeup.kofa', target_language=portal_language) |
---|
| 129 | Title = translate('Title', 'waeup.kofa', target_language=portal_language) |
---|
| 130 | Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language) |
---|
| 131 | Score = translate('Score', 'waeup.kofa', target_language=portal_language) |
---|
| 132 | Grade = translate('Grade', 'waeup.kofa', target_language=portal_language) |
---|
[10269] | 133 | Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue', |
---|
[9914] | 134 | target_language=portal_language) |
---|
| 135 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 136 | self.request, self.omit_fields) |
---|
| 137 | students_utils = getUtility(IStudentsUtils) |
---|
[10442] | 138 | |
---|
| 139 | tabledata = [] |
---|
| 140 | tableheader = [] |
---|
| 141 | contenttitle = [] |
---|
| 142 | for i in range(1,7): |
---|
| 143 | tabledata.append(sorted( |
---|
| 144 | [value for value in self.context.values() if value.semester == i], |
---|
| 145 | key=lambda value: str(value.semester) + value.code)) |
---|
| 146 | tableheader.append([(Code,'code', 2.0), |
---|
| 147 | (Title,'title', 7), |
---|
| 148 | (Cred, 'credits', 1.5), |
---|
| 149 | (Score, 'score', 1.4), |
---|
| 150 | (Grade, 'grade', 1.4), |
---|
| 151 | (Signature, 'dummy', 3), |
---|
| 152 | ]) |
---|
[9914] | 153 | if len(self.label.split('\n')) == 3: |
---|
| 154 | topMargin = 1.9 |
---|
| 155 | elif len(self.label.split('\n')) == 2: |
---|
| 156 | topMargin = 1.7 |
---|
| 157 | else: |
---|
| 158 | topMargin = 1.5 |
---|
| 159 | return students_utils.renderPDF( |
---|
| 160 | self, 'course_registration_slip.pdf', |
---|
| 161 | self.context.student, studentview, |
---|
[10442] | 162 | tableheader=tableheader, |
---|
| 163 | tabledata=tabledata, |
---|
[9914] | 164 | signatures=self._signatures(), |
---|
[10269] | 165 | topMargin=topMargin, |
---|
| 166 | omit_fields=self.omit_fields |
---|
[9914] | 167 | ) |
---|
[10566] | 168 | |
---|
| 169 | class CustomExportPDFTranscriptPage(ExportPDFTranscriptPage): |
---|
| 170 | """Deliver a PDF slip of the context. |
---|
| 171 | """ |
---|
| 172 | |
---|
| 173 | def _sigsInFooter(self): |
---|
| 174 | return [] |
---|
| 175 | |
---|
| 176 | def _signatures(self): |
---|
| 177 | return ([( |
---|
[11555] | 178 | 'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar <br /> ' |
---|
| 179 | 'Exams, Records and Data Processing Division <br /> For: Registrar')],) |
---|
[10922] | 180 | |
---|
| 181 | class CustomExportPDFAdmissionSlipPage(ExportPDFAdmissionSlipPage): |
---|
| 182 | """Deliver a PDF Admission slip. |
---|
| 183 | """ |
---|
| 184 | |
---|
| 185 | @property |
---|
| 186 | def label(self): |
---|
| 187 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 188 | return translate(_('e-Admission Slip \n'), |
---|
| 189 | 'waeup.kofa', target_language=portal_language) \ |
---|
| 190 | + ' %s' % self.context.display_fullname |
---|
[11597] | 191 | |
---|
| 192 | class StudentGetMatricNumberPage(UtilityView, grok.View): |
---|
| 193 | """ Construct and set the matriculation number. |
---|
| 194 | """ |
---|
| 195 | grok.context(IStudent) |
---|
| 196 | grok.name('get_matric_number') |
---|
| 197 | grok.require('waeup.viewStudent') |
---|
| 198 | |
---|
| 199 | def update(self): |
---|
| 200 | students_utils = getUtility(IStudentsUtils) |
---|
| 201 | msg, mnumber = students_utils.setMatricNumber(self.context) |
---|
| 202 | if msg: |
---|
| 203 | self.flash(msg, type="danger") |
---|
| 204 | else: |
---|
| 205 | self.flash(_('Matriculation number %s assigned.' % mnumber)) |
---|
[11602] | 206 | self.context.writeLogMessage(self, '%s assigned' % mnumber) |
---|
[11597] | 207 | self.redirect(self.url(self.context)) |
---|
| 208 | return |
---|
| 209 | |
---|
| 210 | def render(self): |
---|
| 211 | return |
---|