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

Last change on this file since 17808 was 17709, checked in by Henrik Bettermann, 7 months ago

Allow students to download exam clearance slip.

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