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