1 | ## $Id: browser.py 17393 2023-04-27 06:31:51Z 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 | import os |
---|
20 | from zope.i18n import translate |
---|
21 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
22 | from zope.component import getUtility |
---|
23 | from zope.security import checkPermission |
---|
24 | from hurry.workflow.interfaces import IWorkflowInfo |
---|
25 | from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils |
---|
26 | from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget |
---|
27 | from waeup.kofa.browser.layout import KofaEditFormPage |
---|
28 | from waeup.kofa.browser.layout import action, jsaction |
---|
29 | from waeup.kofa.students.browser import ( |
---|
30 | StudyLevelEditFormPage, StudyLevelDisplayFormPage, |
---|
31 | StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip, |
---|
32 | CourseTicketDisplayFormPage, |
---|
33 | CourseTicketManageFormPage, |
---|
34 | StudyLevelDisplayFormPage, |
---|
35 | StudentTriggerTransitionFormPage, |
---|
36 | ExportPDFAdmissionSlip, StartClearancePage, PaymentsManageFormPage, |
---|
37 | BalancePaymentAddFormPage, msave, emit_lock_message) |
---|
38 | from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket |
---|
39 | from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS |
---|
40 | from kofacustom.nigeria.students.browser import ( |
---|
41 | NigeriaOnlinePaymentDisplayFormPage, |
---|
42 | NigeriaStudentBaseManageFormPage, |
---|
43 | NigeriaStudentClearanceEditFormPage, |
---|
44 | NigeriaOnlinePaymentAddFormPage, |
---|
45 | NigeriaExportPDFPaymentSlip, |
---|
46 | NigeriaExportPDFClearanceSlip, |
---|
47 | NigeriaExportPDFPaymentSlip, |
---|
48 | NigeriaBedTicketAddPage, |
---|
49 | NigeriaExportPDFCourseRegistrationSlip, |
---|
50 | ) |
---|
51 | |
---|
52 | from kofacustom.edocons.students.interfaces import ( |
---|
53 | ICustomStudentOnlinePayment, ICustomStudentStudyCourse, |
---|
54 | ICustomStudentStudyLevel, ICustomCourseTicket) |
---|
55 | from kofacustom.edocons.interfaces import MessageFactory as _ |
---|
56 | |
---|
57 | def translated_values(view): |
---|
58 | """Translate course ticket attribute values to be displayed on |
---|
59 | studylevel pages. |
---|
60 | """ |
---|
61 | lang = view.request.cookies.get('kofa.language') |
---|
62 | for value in view.context.values(): |
---|
63 | # We have to unghostify (according to Tres Seaver) the __dict__ |
---|
64 | # by activating the object, otherwise value_dict will be empty |
---|
65 | # when calling the first time. |
---|
66 | value._p_activate() |
---|
67 | value_dict = dict([i for i in value.__dict__.items()]) |
---|
68 | value_dict['url'] = view.url(value) |
---|
69 | value_dict['removable_by_student'] = value.removable_by_student |
---|
70 | value_dict['mandatory'] = translate(str(value.mandatory), 'zope', |
---|
71 | target_language=lang) |
---|
72 | value_dict['carry_over'] = translate(str(value.carry_over), 'zope', |
---|
73 | target_language=lang) |
---|
74 | value_dict['outstanding'] = translate(str(value.outstanding), 'zope', |
---|
75 | target_language=lang) |
---|
76 | value_dict['automatic'] = translate(str(value.automatic), 'zope', |
---|
77 | target_language=lang) |
---|
78 | value_dict['grade'] = value.grade |
---|
79 | value_dict['weight'] = value.weight |
---|
80 | value_dict['course_category'] = value.course_category |
---|
81 | value_dict['total_score'] = value.total_score |
---|
82 | semester_dict = getUtility(IKofaUtils).SEMESTER_DICT |
---|
83 | value_dict['semester'] = semester_dict[ |
---|
84 | value.semester].replace('mester', 'm.') |
---|
85 | # ECNS specific |
---|
86 | value_dict['carryover_score'] = value.carryover_score |
---|
87 | yield value_dict |
---|
88 | |
---|
89 | class CustomStartClearancePage(StartClearancePage): |
---|
90 | with_ac = False |
---|
91 | |
---|
92 | class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip): |
---|
93 | """Deliver a PDF Admission slip. |
---|
94 | """ |
---|
95 | |
---|
96 | omit_fields = ('date_of_birth', 'current_level', 'current_mode', |
---|
97 | 'certificate', 'faculty') |
---|
98 | #form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number') |
---|
99 | |
---|
100 | post_text = ''' |
---|
101 | This admission will be confirmed upon payment of school fees. |
---|
102 | |
---|
103 | Note: All admitted students are to pay their school fees on or before 8th of May 2023. |
---|
104 | |
---|
105 | Also, hostel accommodation is available on first come first serve basis. |
---|
106 | |
---|
107 | Please visit the College Registry (Student Affairs Division) at: |
---|
108 | |
---|
109 | Edo State College of Nursing Sciences |
---|
110 | Godwin Abbey Way (Formerly Limit Road) off Sapele Road, Benin City |
---|
111 | or call 08104797237 for enquiries. |
---|
112 | |
---|
113 | Congratulations! |
---|
114 | ''' |
---|
115 | |
---|
116 | @property |
---|
117 | def label(self): |
---|
118 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
119 | return translate(_('Admission Letter of'), |
---|
120 | 'waeup.kofa', target_language=portal_language) \ |
---|
121 | + ' %s' % self.context.display_fullname |
---|
122 | |
---|
123 | def render(self): |
---|
124 | students_utils = getUtility(IStudentsUtils) |
---|
125 | letterhead_path = os.path.join( |
---|
126 | os.path.dirname(__file__), 'static', 'letterhead_admission.jpg') |
---|
127 | if not os.path.exists(letterhead_path): |
---|
128 | letterhead_path = None |
---|
129 | return students_utils.renderPDFAdmissionLetter(self, |
---|
130 | self.context.student, omit_fields=self.omit_fields, |
---|
131 | letterhead_path=letterhead_path, post_text=self.post_text) |
---|
132 | |
---|
133 | |
---|
134 | class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip): |
---|
135 | """Deliver a PDF slip of the context. |
---|
136 | """ |
---|
137 | omit_fields = ('password', 'suspended', 'suspended_comment', 'phone', |
---|
138 | 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level', |
---|
139 | 'flash_notice', 'certificate', 'faculty', 'parents_email') |
---|
140 | |
---|
141 | class CustomPaymentsManageFormPage(PaymentsManageFormPage): |
---|
142 | """ Page to manage the student payments. This manage form page is for |
---|
143 | both students and students officers. EDOCONS does not allow students |
---|
144 | to remove any payment ticket. |
---|
145 | """ |
---|
146 | @property |
---|
147 | def manage_payments_allowed(self): |
---|
148 | return checkPermission('waeup.manageStudent', self.context) |
---|
149 | |
---|
150 | class CustomBalancePaymentAddFormPage(BalancePaymentAddFormPage): |
---|
151 | grok.require('waeup.manageStudent') |
---|
152 | |
---|
153 | |
---|
154 | class CustomBedTicketAddPage(NigeriaBedTicketAddPage): |
---|
155 | with_ac = False |
---|
156 | |
---|
157 | class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage): |
---|
158 | """ Page to display student study levels |
---|
159 | """ |
---|
160 | @property |
---|
161 | def translated_values(self): |
---|
162 | return translated_values(self) |
---|
163 | |
---|
164 | class CustomExportPDFCourseRegistrationSlip(NigeriaExportPDFCourseRegistrationSlip): |
---|
165 | """Deliver a PDF slip of the context. |
---|
166 | """ |
---|
167 | omit_fields = ('password', 'suspended', 'suspended_comment', |
---|
168 | 'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level', |
---|
169 | 'flash_notice') |
---|
170 | |
---|
171 | def render(self): |
---|
172 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
173 | Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language) |
---|
174 | Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language) |
---|
175 | Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language) |
---|
176 | Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language) |
---|
177 | Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language) |
---|
178 | #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language) |
---|
179 | Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language) |
---|
180 | Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language) |
---|
181 | studentview = StudentBasePDFFormPage(self.context.student, |
---|
182 | self.request, self.omit_fields) |
---|
183 | students_utils = getUtility(IStudentsUtils) |
---|
184 | |
---|
185 | tabledata = [] |
---|
186 | tableheader = [] |
---|
187 | for i in range(1,7): |
---|
188 | tabledata.append(sorted( |
---|
189 | [value for value in self.context.values() if value.semester == i], |
---|
190 | key=lambda value: str(value.semester) + value.code)) |
---|
191 | tableheader.append([(Code,'code', 2.5), |
---|
192 | (Title,'title', 5), |
---|
193 | (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5), |
---|
194 | (Cred, 'credits', 1.5), |
---|
195 | #(Mand, 'mandatory', 1.5), |
---|
196 | (Score, 'score', 1.5), |
---|
197 | (Grade, 'grade', 1.5), |
---|
198 | ('RST', 'carryover_score', 1.5), |
---|
199 | #('Auto', 'automatic', 1.5) |
---|
200 | ]) |
---|
201 | return students_utils.renderPDF( |
---|
202 | self, 'course_registration_slip.pdf', |
---|
203 | self.context.student, studentview, |
---|
204 | tableheader=tableheader, |
---|
205 | tabledata=tabledata, |
---|
206 | omit_fields=self.omit_fields, |
---|
207 | signatures=self._signatures(), |
---|
208 | sigs_in_footer=self._sigsInFooter(), |
---|
209 | ) |
---|
210 | |
---|
211 | class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage): |
---|
212 | """ Page to display course tickets |
---|
213 | """ |
---|
214 | form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category', |
---|
215 | 'ticket_session') |
---|
216 | |
---|
217 | @property |
---|
218 | def form_fields(self): |
---|
219 | if not self.context.carry_over: |
---|
220 | return grok.AutoFields(ICustomCourseTicket).omit('carryover_score') |
---|
221 | return grok.AutoFields(ICustomCourseTicket) |
---|
222 | |
---|
223 | class CustomCourseTicketManageFormPage(CourseTicketManageFormPage): |
---|
224 | """ Page to manage course tickets |
---|
225 | """ |
---|
226 | form_fields = grok.AutoFields(ICustomCourseTicket) |
---|