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