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

Last change on this file since 15743 was 15718, checked in by Henrik Bettermann, 5 years ago

Adjust to base package.

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