source: main/kofacustom.edopoly/trunk/src/kofacustom/edopoly/students/browser.py @ 17958

Last change on this file since 17958 was 17421, checked in by Henrik Bettermann, 18 months ago

Fix view.

  • Property svn:keywords set to Id
File size: 10.7 KB
RevLine 
[10765]1## $Id: browser.py 17421 2023-05-25 21:46:05Z 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
[17342]22from zope.security import checkPermission
[10765]23from hurry.workflow.interfaces import IWorkflowInfo
24from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[15176]26from waeup.kofa.browser.layout import (
27    KofaEditFormPage, UtilityView, action, jsaction)
[10765]28from waeup.kofa.students.browser import (
29    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
[13062]30    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
[10765]31    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
[15718]32    ExportPDFTranscriptSlip,
[17342]33    PaymentsManageFormPage,
[10765]34    msave, emit_lock_message)
[15176]35from waeup.kofa.students.interfaces import (
36    IStudentsUtils, ICourseTicket, IStudent)
[15177]37from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS, PAID
[10765]38from kofacustom.nigeria.students.browser import (
39    NigeriaOnlinePaymentDisplayFormPage,
40    NigeriaStudentBaseManageFormPage,
41    NigeriaStudentClearanceEditFormPage,
42    NigeriaOnlinePaymentAddFormPage,
[13062]43    NigeriaExportPDFPaymentSlip,
44    NigeriaExportPDFClearanceSlip,
[15718]45    NigeriaBedTicketAddPage,
[10765]46    )
[15000]47from kofacustom.edopoly.students.interfaces import (
[10765]48    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
[15176]49    ICustomStudentStudyLevel, ICustomStudent)
[15000]50from kofacustom.edopoly.interfaces import MessageFactory as _
[10765]51
[17342]52class CustomPaymentsManageFormPage(PaymentsManageFormPage):
53    @property
54    def manage_payments_allowed(self):
55        return checkPermission('waeup.manageStudent', self.context)
56
[15718]57class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
[15017]58    with_ac = False
[15088]59
60class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
61    """ Page to display student study levels
62    """
63    grok.template('studylevelpage')
64
65class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
66    """ Page to edit the student study level data by students.
67
68    """
69    grok.template('studyleveleditpage')
70
71class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
72    """ Page to display course tickets
73    """
74    form_fields = grok.AutoFields(ICourseTicket).omit('score')
75
76class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
77    """Deliver a PDF slip of the context.
78    """
79
80    def render(self):
81        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
82        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
83        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
84        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
85        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
86        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
87        #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
88        #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
89        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
90        studentview = StudentBasePDFFormPage(self.context.student,
91            self.request, self.omit_fields)
92        students_utils = getUtility(IStudentsUtils)
93
94        tabledata = []
95        tableheader = []
96        for i in range(1,7):
97            tabledata.append(sorted(
98                [value for value in self.context.values() if value.semester == i],
99                key=lambda value: str(value.semester) + value.code))
100            tableheader.append([(Code,'code', 2.5),
101                             (Title,'title', 5),
102                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
103                             (Cred, 'credits', 1.5),
104                             #(Mand, 'mandatory', 1.5),
105                             #(Score, 'score', 1.5),
106                             (Grade, 'grade', 1.5),
107                             #('Auto', 'automatic', 1.5)
108                             ])
109        return students_utils.renderPDF(
110            self, 'course_registration_slip.pdf',
111            self.context.student, studentview,
112            tableheader=tableheader,
113            tabledata=tabledata,
114            omit_fields=self.omit_fields
115            )
116
117
118class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
119    """Deliver a PDF slip of the context.
120    """
121
122    def render(self):
123        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
124        Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language)
125        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
126        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
127        Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language)
128        #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
129        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
130        studentview = StudentBasePDFFormPage(self.context.student,
131            self.request, self.omit_fields)
132        students_utils = getUtility(IStudentsUtils)
133
134        tableheader = [(Code,'code', 2.5),
135                         (Title,'title', 8.5),
136                         (Term, 'semester', 1.5),
137                         (Cred, 'credits', 1.5),
138                         #(Score, 'score', 1.5),
139                         (Grade, 'grade', 1.5),
140                         ]
141
[15167]142        pdfstream = students_utils.renderPDFTranscript(
[15088]143            self, 'transcript.pdf',
144            self.context.student, studentview,
145            omit_fields=self.omit_fields,
146            tableheader=tableheader,
147            signatures=self._signatures(),
148            sigs_in_footer=self._sigsInFooter(),
[15167]149            digital_sigs=self._digital_sigs(),
150            save_file=self._save_file(),
[15088]151            )
[15167]152        if not pdfstream:
153            self.redirect(self.url(self.context.student))
154            return
[17421]155        return pdfstream
[15176]156
157class StudentGetMatricNumberPage(UtilityView, grok.View):
158    """ Construct and set the matriculation number.
159    """
160    grok.context(IStudent)
161    grok.name('get_matric_number')
162    grok.require('waeup.viewStudent')
163
164    def update(self):
165        students_utils = getUtility(IStudentsUtils)
166        msg, mnumber = students_utils.setMatricNumber(self.context)
167        if msg:
168            self.flash(msg, type="danger")
169        else:
170            self.flash(_('Matriculation number %s assigned.' % mnumber))
171            self.context.writeLogMessage(self, '%s assigned' % mnumber)
172        self.redirect(self.url(self.context))
173        return
174
175    def render(self):
176        return
177
178class ExportPDFMatricNumberSlip(UtilityView, grok.View):
179    """Deliver a PDF notification slip.
180    """
181    grok.context(ICustomStudent)
182    grok.name('matric_number_slip.pdf')
183    grok.require('waeup.viewStudent')
184    prefix = 'form'
185
186    form_fields = grok.AutoFields(ICustomStudent).select(
187        'student_id', 'matric_number')
188    omit_fields = ('date_of_birth', 'current_level', 'flash_notice')
189
190    @property
191    def title(self):
192        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
193        return translate(_('Matriculation Number'), 'waeup.kofa',
194            target_language=portal_language)
195
196    @property
197    def label(self):
198        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
199        return translate(_('Matriculation Number Slip\n'),
200            target_language=portal_language) \
201            + ' %s' % self.context.display_fullname
202
203    def render(self):
204        if self.context.state not in (PAID,) or not self.context.is_fresh \
205            or not self.context.matric_number:
206            self.flash('Not allowed.', type="danger")
207            self.redirect(self.url(self.context))
208            return
209        students_utils = getUtility(IStudentsUtils)
210        pre_text = _('Congratulations! Your acceptance fee and school fees ' +
211                     'payments have been received and your matriculation ' +
212                     'number generated with details as follows.')
213        return students_utils.renderPDFAdmissionLetter(self,
214            self.context.student, omit_fields=self.omit_fields,
[15185]215            pre_text=pre_text, post_text='')
216
217class MedicalLaboratoryRequestForm(UtilityView, grok.View):
218    """Deliver a PDF notification slip.
219    """
220    grok.context(ICustomStudent)
221    grok.name('medical_laboratory_form.pdf')
222    grok.require('waeup.viewStudent')
223    prefix = 'form'
224
225    form_fields = grok.AutoFields(ICustomStudent).select(
226        'student_id', 'matric_number', 'sex', 'email', 'phone', 'perm_address')
227    omit_fields = ('current_mode')
228
229    label = u'Student\'s Medical Laboratory Request Form'
230    title = u'Student\'s Medical Laboratory Request Form'
231
232    post_text = """
233
234Laboratory request: Student's Medical Test
235
236Lab Results/Status:
237
238
239
240
[15187]241
242
243Medical Laboratory Scientist's Signature:
244
245
246
247
248
249
[15185]250Notice to all newly admitted students:
251
2521. Carry out your mandatory medical laboratory tests at:
253(a) the Edo State Polyechnic Health Centre
2542. Evidence of medical screening payment and the downloaded student's laboratory test request form are required for the medical tests to be conducted for students.
2553. Collect your lab tests results and upload during clearance process online.
2564. Students' admission records and clearance are incomplete without medical test result.
2575. Results of medical tests from elsewhere are not accepted.
2586. Medical tests are conducted only within admission period, and will end in matriculation week. Unnecessary delays will not be allowed.
2597. This information applies to both full- time and part-time.
260"""
261
262    def render(self):
263        if not self.context.medical_fee_paid:
264            self.flash('Not allowed.', type="danger")
265            self.redirect(self.url(self.context))
266            return
267        students_utils = getUtility(IStudentsUtils)
268        return students_utils.renderPDFAdmissionLetter(self,
269            self.context.student, omit_fields=self.omit_fields,
270            pre_text='', post_text=self.post_text)
Note: See TracBrowser for help on using the repository browser.