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