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

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

Extend personal data form and force student to fill the form.

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