source: main/waeup.aaue/trunk/src/waeup/aaue/students/browser.py @ 13360

Last change on this file since 13360 was 13360, checked in by Henrik Bettermann, 9 years ago

Disable access code for clearance.

  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
1## $Id: browser.py 13360 2015-10-29 12:55:30Z 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.component import getUtility
21from zope.formlib.textwidgets import BytesDisplayWidget
22from waeup.kofa.browser.layout import UtilityView
23from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
24from waeup.kofa.interfaces import IKofaUtils
25from waeup.kofa.students.interfaces import IStudentsUtils, IStudent
26from waeup.kofa.students.workflow import PAID, REGISTERED
27from waeup.kofa.students.browser import (
28    StartClearancePage,
29    StudentBasePDFFormPage,
30    CourseTicketAddFormPage,
31    StudyLevelDisplayFormPage,
32    ExportPDFTranscriptSlip,
33    ExportPDFAdmissionSlip,
34    BedTicketAddPage,
35    )
36from kofacustom.nigeria.students.browser import (
37    NigeriaOnlinePaymentDisplayFormPage,
38    NigeriaOnlinePaymentAddFormPage,
39    NigeriaExportPDFPaymentSlip,
40    NigeriaExportPDFCourseRegistrationSlip,
41    NigeriaExportPDFClearanceSlip,
42    NigeriaStudentPersonalDisplayFormPage,
43    NigeriaStudentPersonalEditFormPage,
44    NigeriaStudentPersonalManageFormPage,
45    )
46from waeup.aaue.students.interfaces import (
47    ICustomStudentOnlinePayment,
48    ICustomStudentStudyLevel,
49    ICustomStudent,
50    ICustomStudentPersonal,
51    ICustomStudentPersonalEdit)
52from waeup.aaue.interfaces import MessageFactory as _
53
54class CustomStudentPersonalDisplayFormPage(NigeriaStudentPersonalDisplayFormPage):
55    """ Page to display student personal data
56    """
57    form_fields = grok.AutoFields(ICustomStudentPersonal)
58    form_fields['perm_address'].custom_widget = BytesDisplayWidget
59    form_fields['father_address'].custom_widget = BytesDisplayWidget
60    form_fields['mother_address'].custom_widget = BytesDisplayWidget
61    form_fields['next_kin_address'].custom_widget = BytesDisplayWidget
62    form_fields[
63        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
64
65class CustomStudentPersonalEditFormPage(NigeriaStudentPersonalEditFormPage):
66    """ Page to edit personal data
67    """
68    form_fields = grok.AutoFields(ICustomStudentPersonalEdit).omit('personal_updated')
69
70class CustomStudentPersonalManageFormPage(NigeriaStudentPersonalManageFormPage):
71    """ Page to edit personal data
72    """
73    form_fields = grok.AutoFields(ICustomStudentPersonal)
74    form_fields['personal_updated'].for_display = True
75    form_fields[
76        'personal_updated'].custom_widget = FriendlyDatetimeDisplayWidget('le')
77
78class CustomStartClearancePage(StartClearancePage):
79    with_ac = False
80
81    @property
82    def all_required_fields_filled(self):
83        if not self.context.email:
84            return _("Email address is missing."), 'edit_base'
85        if not self.context.phone:
86            return _("Phone number is missing."), 'edit_base'
87        if not self.context.father_name:
88            return _("Personal data form is not properly filled."), 'edit_personal'
89        return
90
91class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
92    """ Page to view an online payment ticket
93    """
94    grok.context(ICustomStudentOnlinePayment)
95    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
96        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
97    form_fields[
98        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
99    form_fields[
100        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
101
102class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
103    """ Page to add an online payment ticket
104    """
105    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
106        'p_category')
107
108class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
109    """Deliver a PDF slip of the context.
110    """
111    grok.context(ICustomStudentOnlinePayment)
112    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
113        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
114    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
115    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
116
117    @property
118    def note(self):
119        text = ''
120        if self.context.p_category == 'schoolfee' and self.context.p_level == 100:
121            text += '\n\n Amounts include Naira 250 eTranzact transaction '
122            text += 'charge and Naira 2000 cost of matriculation gown.'
123        elif self.context.p_category in ('clearance', 'schoolfee'):
124            text += '\n\n Amounts include Naira 250 eTranzact transaction charge.'
125        return text
126
127class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
128    """ Page to display student study levels
129    """
130    grok.context(ICustomStudentStudyLevel)
131    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
132        'total_credits', 'gpa', 'level')
133    form_fields[
134        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
135
136class CustomExportPDFCourseRegistrationSlip(
137    NigeriaExportPDFCourseRegistrationSlip):
138    """Deliver a PDF slip of the context.
139    """
140    grok.context(ICustomStudentStudyLevel)
141    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
142        'level_session', 'level_verdict',
143        'validated_by', 'validation_date', 'gpa', 'level')
144
145    omit_fields = ('password', 'suspended', 'suspended_comment',
146        'phone', 'adm_code', 'sex', 'email', 'date_of_birth',
147        'department', 'current_mode', 'current_level')
148
149    def update(self):
150        if self.context.student.state != REGISTERED \
151            and self.context.student.current_level == self.context.level:
152            self.flash(_('Forbidden'), type="warning")
153            self.redirect(self.url(self.context))
154
155    @property
156    def label(self):
157        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
158        lang = self.request.cookies.get('kofa.language', portal_language)
159        level_title = translate(self.context.level_title, 'waeup.kofa',
160            target_language=lang)
161        line0 = ''
162        if self.context.student.current_mode.endswith('_pt'):
163            line0 = 'DIRECTORATE OF PART-TIME DEGREE PROGRAMMES\n'
164        line1 = translate(_('Course Registration Slip'),
165            'waeup.kofa', target_language=portal_language) \
166            + ' %s' % level_title
167        line2 = translate(_('Session'),
168            'waeup.kofa', target_language=portal_language) \
169            + ' %s' % self.context.getSessionString
170        return '%s%s\n%s' % (line0, line1, line2)
171
172    @property
173    def title(self):
174        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
175        return translate(_('Units Registered'), 'waeup.kofa',
176            target_language=portal_language)
177
178    def _signatures(self):
179        return (
180            [('I have selected the course on the advise of my Head of '
181             'Department. <br>', _('Student\'s Signature'), '<br>')],
182            [('This student has satisfied the department\'s requirements. '
183             'I recommend to approve the course registration. <br>',
184             _('Head of Department\'s Signature'), '<br>')],
185            [('' , _('Principal Assistant Registrar\'s Signature'), '<br>')],
186            [('', _('Director\'s Signature'))]
187            )
188
189    def render(self):
190        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
191        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
192        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
193        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
194        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
195        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
196        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
197        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
198            target_language=portal_language)
199        studentview = StudentBasePDFFormPage(self.context.student,
200            self.request, self.omit_fields)
201        students_utils = getUtility(IStudentsUtils)
202
203        tabledata = []
204        tableheader = []
205        contenttitle = []
206        for i in range(1,7):
207            tabledata.append(sorted(
208                [value for value in self.context.values() if value.semester == i],
209                key=lambda value: str(value.semester) + value.code))
210            tableheader.append([(Code,'code', 2.0),
211                               (Title,'title', 7),
212                               (Cred, 'credits', 1.5),
213                               (Score, 'score', 1.4),
214                               (Grade, 'grade', 1.4),
215                               (Signature, 'dummy', 3),
216                               ])
217        if len(self.label.split('\n')) == 3:
218            topMargin = 1.9
219        elif len(self.label.split('\n')) == 2:
220            topMargin = 1.7
221        else:
222            topMargin = 1.5
223        return students_utils.renderPDF(
224            self, 'course_registration_slip.pdf',
225            self.context.student, studentview,
226            tableheader=tableheader,
227            tabledata=tabledata,
228            signatures=self._signatures(),
229            topMargin=topMargin,
230            omit_fields=self.omit_fields
231            )
232
233class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
234    """Deliver a PDF slip of the context.
235    """
236
237    def _sigsInFooter(self):
238        return []
239
240    def _signatures(self):
241        return ([(
242            'Akhimien Felicia O. (MANUPA) <br /> Principal Assistant Registrar  <br /> '
243            'Exams, Records and Data Processing Division <br /> For: Registrar')],)
244
245class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
246    """Deliver a PDF Admission slip.
247    """
248
249    @property
250    def label(self):
251        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
252        return translate(_('e-Admission Slip \n'),
253            'waeup.kofa', target_language=portal_language) \
254            + ' %s' % self.context.display_fullname
255
256class CustomExportPDFClearanceSlip(NigeriaExportPDFClearanceSlip):
257    """Deliver a PDF slip of the context.
258    """
259
260    @property
261    def label(self):
262        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
263        return translate(_('Clearance Slip\n'),
264            'waeup.kofa', target_language=portal_language) \
265            + ' %s' % self.context.display_fullname
266
267class StudentGetMatricNumberPage(UtilityView, grok.View):
268    """ Construct and set the matriculation number.
269    """
270    grok.context(IStudent)
271    grok.name('get_matric_number')
272    grok.require('waeup.viewStudent')
273
274    def update(self):
275        students_utils = getUtility(IStudentsUtils)
276        msg, mnumber = students_utils.setMatricNumber(self.context)
277        if msg:
278            self.flash(msg, type="danger")
279        else:
280            self.flash(_('Matriculation number %s assigned.' % mnumber))
281            self.context.writeLogMessage(self, '%s assigned' % mnumber)
282        self.redirect(self.url(self.context))
283        return
284
285    def render(self):
286        return
287
288class ExportPDFMatricNumberSlip(UtilityView, grok.View):
289    """Deliver a PDF notification slip.
290    """
291    grok.context(ICustomStudent)
292    grok.name('matric_number_slip.pdf')
293    grok.require('waeup.viewStudent')
294    prefix = 'form'
295
296    form_fields = grok.AutoFields(ICustomStudent).select(
297        'student_id', 'matric_number')
298    omit_fields = ('date_of_birth', 'current_level')
299
300    @property
301    def label(self):
302        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
303        return translate(_('Matriculation Number Slip\n'),
304            'waeup.kofa', target_language=portal_language) \
305            + ' %s' % self.context.display_fullname
306
307    def render(self):
308        if self.context.state not in (PAID,) or not self.context.is_fresh \
309            or not self.context.matric_number:
310            self.flash('Not allowed.', type="danger")
311            self.redirect(self.url(self.context))
312            return
313        students_utils = getUtility(IStudentsUtils)
314        pre_text = _('Congratulations! Your acceptance fee and school fees ' +
315                     'payments have been received and your matriculation ' +
316                     'number generated with details as follows.')
317        return students_utils.renderPDFAdmissionLetter(self,
318            self.context.student, omit_fields=self.omit_fields,
319            pre_text=pre_text, post_text='')
320
321class CustomBedTicketAddPage(BedTicketAddPage):
322    with_ac = False
Note: See TracBrowser for help on using the repository browser.