[10765] | 1 | ## $Id: browser.py 15225 2018-11-09 08:46:19Z 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 |
---|
| 20 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
| 21 | from zope.component import getUtility |
---|
| 22 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
| 23 | from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils |
---|
| 24 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
| 25 | from waeup.kofa.browser.layout import KofaEditFormPage |
---|
| 26 | from waeup.kofa.browser.layout import action, jsaction |
---|
| 27 | from waeup.kofa.students.browser import ( |
---|
[14877] | 28 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
| 29 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip, |
---|
| 30 | CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage, |
---|
[15215] | 31 | ExportPDFTranscriptSlip, BedTicketAddPage, |
---|
[14877] | 32 | msave, emit_lock_message) |
---|
[10765] | 33 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
| 34 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
| 35 | from kofacustom.nigeria.students.browser import ( |
---|
| 36 | NigeriaOnlinePaymentDisplayFormPage, |
---|
| 37 | NigeriaStudentBaseManageFormPage, |
---|
| 38 | NigeriaStudentClearanceEditFormPage, |
---|
| 39 | NigeriaOnlinePaymentAddFormPage, |
---|
[13062] | 40 | NigeriaExportPDFPaymentSlip, |
---|
| 41 | NigeriaExportPDFClearanceSlip, |
---|
[15225] | 42 | NigeriaAccommodationManageFormPage, |
---|
[10765] | 43 | ) |
---|
| 44 | |
---|
[14716] | 45 | from kofacustom.dspg.students.interfaces import ( |
---|
[10765] | 46 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse, |
---|
| 47 | ICustomStudentStudyLevel) |
---|
[14716] | 48 | from kofacustom.dspg.interfaces import MessageFactory as _ |
---|
[10765] | 49 | |
---|
[15215] | 50 | class CustomBedTicketAddPage(BedTicketAddPage): |
---|
| 51 | with_ac = False |
---|
| 52 | |
---|
[14882] | 53 | class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage): |
---|
| 54 | """ View to edit student clearance data by student |
---|
| 55 | """ |
---|
| 56 | |
---|
| 57 | def dataNotComplete(self): |
---|
| 58 | store = getUtility(IExtFileStore) |
---|
| 59 | if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'): |
---|
| 60 | return _('No birth certificate uploaded.') |
---|
| 61 | if not store.getFileByContext(self.context, attr=u'lga_ident.jpg'): |
---|
| 62 | return _('No LGA identification letter uploaded.') |
---|
| 63 | if not store.getFileByContext(self.context, attr=u'o_level_result.jpg'): |
---|
| 64 | return _('No O Level result uploaded.') |
---|
[14883] | 65 | cm = getattr(self.context,'current_mode', None) |
---|
| 66 | if cm and cm.startswith('nd'): |
---|
[14882] | 67 | if not store.getFileByContext(self.context, attr=u'jamb_result.jpg'): |
---|
| 68 | return _('No JAMB result uploaded.') |
---|
[14883] | 69 | elif cm and cm.startswith('hnd'): |
---|
[14882] | 70 | if not store.getFileByContext(self.context, attr=u'nd_result.jpg'): |
---|
| 71 | return _('No ND result uploaded.') |
---|
| 72 | if not store.getFileByContext(self.context, attr=u'it_letter.jpg'): |
---|
| 73 | return _('No IT letter uploaded.') |
---|
[15089] | 74 | return False |
---|
| 75 | |
---|
| 76 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
| 77 | """ Page to display student study levels |
---|
| 78 | """ |
---|
| 79 | grok.template('studylevelpage') |
---|
| 80 | |
---|
| 81 | class CustomStudyLevelEditFormPage(StudyLevelEditFormPage): |
---|
| 82 | """ Page to edit the student study level data by students. |
---|
| 83 | |
---|
| 84 | """ |
---|
| 85 | grok.template('studyleveleditpage') |
---|
| 86 | |
---|
| 87 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
| 88 | """ Page to display course tickets |
---|
| 89 | """ |
---|
| 90 | form_fields = grok.AutoFields(ICourseTicket).omit('score') |
---|
| 91 | |
---|
| 92 | class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip): |
---|
| 93 | """Deliver a PDF slip of the context. |
---|
| 94 | """ |
---|
| 95 | |
---|
| 96 | def render(self): |
---|
| 97 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 98 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 99 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 100 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
---|
| 101 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
---|
| 102 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
---|
| 103 | #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language) |
---|
| 104 | #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
| 105 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
| 106 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 107 | self.request, self.omit_fields) |
---|
| 108 | students_utils = getUtility(IStudentsUtils) |
---|
| 109 | |
---|
| 110 | tabledata = [] |
---|
| 111 | tableheader = [] |
---|
| 112 | for i in range(1,7): |
---|
| 113 | tabledata.append(sorted( |
---|
| 114 | [value for value in self.context.values() if value.semester == i], |
---|
| 115 | key=lambda value: str(value.semester) + value.code)) |
---|
| 116 | tableheader.append([(Code,'code', 2.5), |
---|
| 117 | (Title,'title', 5), |
---|
| 118 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
| 119 | (Cred, 'credits', 1.5), |
---|
| 120 | #(Mand, 'mandatory', 1.5), |
---|
| 121 | #(Score, 'score', 1.5), |
---|
| 122 | (Grade, 'grade', 1.5), |
---|
| 123 | #('Auto', 'automatic', 1.5) |
---|
| 124 | ]) |
---|
| 125 | return students_utils.renderPDF( |
---|
| 126 | self, 'course_registration_slip.pdf', |
---|
| 127 | self.context.student, studentview, |
---|
| 128 | tableheader=tableheader, |
---|
| 129 | tabledata=tabledata, |
---|
| 130 | omit_fields=self.omit_fields |
---|
| 131 | ) |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip): |
---|
| 135 | """Deliver a PDF slip of the context. |
---|
| 136 | """ |
---|
| 137 | |
---|
| 138 | def render(self): |
---|
| 139 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 140 | Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language) |
---|
| 141 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
| 142 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
| 143 | Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language) |
---|
| 144 | #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
| 145 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
| 146 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
| 147 | self.request, self.omit_fields) |
---|
| 148 | students_utils = getUtility(IStudentsUtils) |
---|
| 149 | |
---|
| 150 | tableheader = [(Code,'code', 2.5), |
---|
| 151 | (Title,'title', 8.5), |
---|
| 152 | (Term, 'semester', 1.5), |
---|
| 153 | (Cred, 'credits', 1.5), |
---|
| 154 | #(Score, 'score', 1.5), |
---|
| 155 | (Grade, 'grade', 1.5), |
---|
| 156 | ] |
---|
| 157 | |
---|
[15166] | 158 | pdfstream = students_utils.renderPDFTranscript( |
---|
[15089] | 159 | self, 'transcript.pdf', |
---|
| 160 | self.context.student, studentview, |
---|
| 161 | omit_fields=self.omit_fields, |
---|
| 162 | tableheader=tableheader, |
---|
| 163 | signatures=self._signatures(), |
---|
| 164 | sigs_in_footer=self._sigsInFooter(), |
---|
[15166] | 165 | digital_sigs=self._digital_sigs(), |
---|
| 166 | save_file=self._save_file(), |
---|
[15089] | 167 | ) |
---|
[15166] | 168 | if not pdfstream: |
---|
| 169 | self.redirect(self.url(self.context.student)) |
---|
| 170 | return |
---|
| 171 | return pdfstream |
---|
[15225] | 172 | |
---|
| 173 | class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage): |
---|
| 174 | """ Page to manage bed tickets. |
---|
| 175 | This manage form page is for both students and students officers. |
---|
| 176 | """ |
---|
| 177 | with_hostel_selection = True |
---|