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

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

Remove duplicate payment category.

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