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

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

Make lga and date_of_birth fields required.

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