source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/browser.py @ 17921

Last change on this file since 17921 was 17843, checked in by Henrik Bettermann, 4 months ago

Add note to attendance sheet.

  • Property svn:keywords set to Id
File size: 13.3 KB
Line 
1## $Id: browser.py 17843 2024-07-13 06:40:06Z 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##
18import grok
19from zope.i18n import translate
20from zope.schema.interfaces import ConstraintNotSatisfied
21from zope.component import getUtility
22from zope.security import checkPermission
23from hurry.workflow.interfaces import IWorkflowInfo
24from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
26from waeup.kofa.browser.layout import KofaEditFormPage
27from waeup.kofa.browser.layout import action, jsaction
28from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID,
29    CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED,
30    GRADUATED, TRANSREQ, TRANSVAL, TRANSREL, FORBIDDEN_POSTGRAD_TRANS)
31from waeup.kofa.students.browser import (
32    StudyLevelEditFormPage, StudyLevelDisplayFormPage, StudyLevelManageFormPage,
33    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
34    CourseTicketDisplayFormPage, CourseTicketManageFormPage,
35    StudentTriggerTransitionFormPage,
36    ExportPDFAdmissionSlip,
37    ExportAttendanceSlip,
38    PaymentsManageFormPage, msave, emit_lock_message)
39from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket, IStudentBase
40from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
41from kofacustom.nigeria.students.browser import (
42    NigeriaOnlinePaymentDisplayFormPage,
43    NigeriaStudentBaseManageFormPage,
44    NigeriaStudentClearanceEditFormPage,
45    NigeriaOnlinePaymentAddFormPage,
46    NigeriaExportPDFPaymentSlip,
47    NigeriaExportPDFClearanceSlip,
48    NigeriaBedTicketAddPage,
49    NigeriaAccommodationDisplayFormPage,
50    NigeriaAccommodationManageFormPage,
51    )
52from kofacustom.unidel.students.interfaces import (
53    ICustomStudent,
54    ICustomStudentOnlinePayment,
55    ICustomStudentStudyCourse,
56    ICustomStudentStudyLevel,
57    ICustomUGStudentClearance,
58    ICustomPGStudentClearance,
59    ICustomCourseTicket)
60from kofacustom.unidel.interfaces import MessageFactory as _
61
62class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
63    with_ac = False
64
65class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
66    """ Page to view bed tickets.
67    """
68    with_hostel_selection = True
69
70class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
71    """ Page to manage bed tickets.
72    This manage form page is for both students and students officers.
73    """
74    with_hostel_selection = True
75
76class CustomPaymentsManageFormPage(PaymentsManageFormPage):
77    """ Page to manage the student payments. This manage form page is for
78    both students and students officers. UNIDEL does not allow students
79    to remove any payment ticket.
80    """
81    @property
82    def manage_payments_allowed(self):
83        return checkPermission('waeup.manageStudent', self.context)
84
85class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
86    """ View to edit student clearance data by student
87    """
88    @property
89    def form_fields(self):
90        if self.context.is_postgrad:
91            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
92            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
93            'physical_clearance_date')
94        else:
95            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
96            'clearance_locked', 'clr_code', 'officer_comment',
97            'physical_clearance_date')
98            form_fields['date_of_birth'].for_display = True
99            form_fields['nationality'].for_display = True
100            form_fields['lga'].for_display = True
101        return form_fields
102
103class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
104    """ Page to view an online payment ticket
105    """
106    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
107        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item','p_combi',
108        'net_amt')
109    form_fields[
110        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
111    form_fields[
112        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
113
114class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
115    """Deliver a PDF slip of the context.
116    """
117    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
118        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
119        'p_split_data','p_combi', 'net_amt')
120    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
121    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
122
123class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
124    """ Page to display student study levels
125    """
126    #grok.template('studylevelpage')
127    grok.context(ICustomStudentStudyLevel)
128
129    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
130        'level',)
131    form_fields[
132        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
133
134class CustomStudyLevelManageFormPage(StudyLevelManageFormPage):
135    """ Page to edit the student study level data
136    """
137    grok.context(ICustomStudentStudyLevel)
138
139    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
140        'validation_date', 'validated_by', 'total_credits', 'gpa', 'level',
141        'total_credits_s1', 'total_credits_s2')
142
143class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
144    """Deliver a PDF slip of the context.
145    """
146    grok.context(ICustomStudentStudyLevel)
147    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
148        'level', 'gpa', 'transcript_remark')
149    form_fields[
150        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
151    #prefix = 'form'
152    omit_fields = (
153        'password', 'suspended', 'phone', 'date_of_birth',
154        'adm_code', 'sex', 'suspended_comment', 'current_level',
155        'flash_notice')
156
157    def _signatures(self):
158        return (
159            [_('Student\'s Signature')],
160            [_('Academic Adviser\'s Signature')],
161            [_('Head of Department\'s Signature')],
162            [_('Dean of Faculty\'s Signature')],
163            )
164
165               
166    def render(self):
167        if not self.context.student.current_mode:
168            self.flash('No certificate assigned.', type="danger")
169            self.redirect(self.url(self.context))
170            return
171        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
172        Sem = translate(_('Term'), target_language=portal_language)
173        Code = translate(_('Code'), target_language=portal_language)
174        Title = translate(_('Title'), target_language=portal_language)
175        Cred = translate(_('Cred.'), target_language=portal_language)
176        CC = translate(_('Cat.'), target_language=portal_language)
177        TotalScore = translate(_('Total Score'), target_language=portal_language)
178        #CA = translate(_('CA'), target_language=portal_language)
179        Grade = translate(_('Grade'), target_language=portal_language)
180        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
181            target_language=portal_language)
182        studentview = StudentBasePDFFormPage(self.context.student,
183            self.request, self.omit_fields)
184        students_utils = getUtility(IStudentsUtils)
185        tabledata = []
186        tableheader = []
187        contenttitle = []
188        for i in range(1,7):
189            tabledata.append(sorted(
190                [value for value in self.context.values()
191                 if value.semester == i and not value.outstanding],
192                 key=lambda value: str(value.semester) + value.code))
193            tableheader.append([(Code,'code', 2.0),
194                               (Title,'title', 7),
195                               (Cred, 'credits', 1.4),
196                               #(CC, 'course_category', 1.2),
197                               (TotalScore, 'total_score', 1.4),
198                               #(CA, 'ca', 1.4),
199                               (Grade, 'grade', 1.4),
200                               (Signature, 'dummy', 3),
201                               ])
202        return students_utils.renderPDF(
203            self, 'course_registration_slip.pdf',
204            self.context.student, studentview,
205            tableheader=tableheader,
206            tabledata=tabledata,
207            omit_fields=self.omit_fields,
208            signatures=self._signatures(),
209            sigs_in_footer=self._sigsInFooter(),
210            )
211
212class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
213    """ Page to display course tickets
214    """
215
216    @property
217    def form_fields(self):
218        return grok.AutoFields(ICustomCourseTicket).omit('course_category',
219            'ticket_session')
220
221class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
222    """ Page to manage course tickets
223    """
224   
225    form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category')
226    form_fields['title'].for_display = True
227    form_fields['fcode'].for_display = True
228    form_fields['dcode'].for_display = True
229    form_fields['semester'].for_display = True
230    form_fields['passmark'].for_display = True
231    form_fields['credits'].for_display = True
232    form_fields['mandatory'].for_display = False
233    form_fields['automatic'].for_display = True
234    form_fields['carry_over'].for_display = True
235    form_fields['ticket_session'].for_display = True
236
237
238class ExaminationClearanceSlip(NigeriaExportPDFClearanceSlip):
239    """Deliver a PDF slip of the context.
240    """
241
242    grok.name('examclearance_slip.pdf')
243    grok.require('waeup.handleStudent')
244    omit_fields = (
245        'suspended',
246        #'phone',
247        'email',
248        'adm_code', 'suspended_comment',
249        'date_of_birth',
250        #'current_level',
251        #'current_mode',
252        #'entry_session',
253        'flash_notice',
254        'parents_email',
255        'certificate',
256        #'faculty',
257        #'department',
258        'reg_number')
259    form_fields = None
260
261    @property
262    def note(self):
263        return '''
264
265
266   
267You have been cleared to write second semester examination for %s/%s session.
268''' % (self.context.current_session, self.context.current_session + 1)
269
270    def update(self):
271            # disabled 05/07/24
272            return
273        #if not  self.context.state in (VALIDATED, REGISTERED, PAID):
274        #    self.flash(_('Your course list has not yet been registered.'),
275        #        type="warning")
276        #    self.redirect(self.url(self.context))
277        #    return
278
279    @property
280    def label(self):
281        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
282        return translate(_('Examination Clearance Slip of'),
283            'waeup.kofa', target_language=portal_language) \
284            + ' %s' % self.context.display_fullname
285
286    def _sigsInFooter(self):
287        #isStudent = getattr(
288        #    self.request.principal, 'user_type', None) == 'student'
289        #if not isStudent and self.context.state in (CLEARED, RETURNING):
290
291        return (_('Date, DICT Signature'),
292                _('Date, Dean\'s Signature'),
293                    )
294    def render(self):
295        studentview = StudentBasePDFFormPage(self.context.student,
296            self.request, self.omit_fields)
297        students_utils = getUtility(IStudentsUtils)
298        return students_utils.renderPDF(
299            self, 'examclearance_slip.pdf',
300            self.context.student, studentview, signatures=None,
301            sigs_in_footer=self._sigsInFooter(), show_scans=False,
302            omit_fields=self.omit_fields,
303            note=self.note)
304
305
306class CustomExportAttendanceSlip(ExportAttendanceSlip):
307    """
308    """
309
310    #def _signatures(self):
311    #    return ([_('Student Signature')],
312    #            [_('Clearance Officer Signature')])
313
314    @property
315    def note(self):
316        return """
317
318       
319Faculty: __________________________________________________________
320
321Department: ______________________________________________________
322
323Date of Examination: _______________________________________________
324
325Time of Examination: _______________________________________________
326
327Venue of Examination: ______________________________________________
328
329Names of Supervisors:
330
331______________________________________________
332
333______________________________________________
334
335______________________________________________
336
337______________________________________________
338
339______________________________________________
340        """
341
342    def render(self):
343        lecturers = [i['user_title'] for i in self.getUsersWithLocalRoles()
344                     if i['local_role'] == 'waeup.local.Lecturer']
345        lecturers =  ', '.join(lecturers)
346        students_utils = getUtility(IStudentsUtils)
347        return students_utils.renderPDFCourseticketsOverview(
348            self, 'attendance', self.current_academic_session,
349            self.data(self.current_academic_session),
350            lecturers, '', 65, self.note)
Note: See TracBrowser for help on using the repository browser.