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

Last change on this file since 17931 was 17924, checked in by Henrik Bettermann, 2 months ago

Use correct interface.

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