source: main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py @ 12846

Last change on this file since 12846 was 12846, checked in by Henrik Bettermann, 10 years ago

Move signatures into footer.

  • Property svn:keywords set to Id
File size: 17.8 KB
Line 
1## $Id: browser.py 12846 2015-04-02 16:06:57Z 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 (
24    REQUESTED, IExtFileStore, IKofaUtils, IObjectHistory)
25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
26from waeup.kofa.browser.layout import action, KofaEditFormPage, UtilityView
27from waeup.kofa.students.browser import (
28    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
29    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage,
30    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
31    msave, emit_lock_message,
32    StudentActivatePage, StudentDeactivatePage,
33    ExportPDFTranscriptPage)
34from waeup.kofa.students.workflow import (CREATED, ADMITTED, PAID,
35    CLEARANCE, REQUESTED, RETURNING, CLEARED, REGISTERED, VALIDATED,
36    GRADUATED, TRANSCRIPT, FORBIDDEN_POSTGRAD_TRANS)
37from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
38from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
39from kofacustom.nigeria.students.browser import (
40    NigeriaOnlinePaymentDisplayFormPage,
41    NigeriaStudentBaseManageFormPage,
42    NigeriaStudentClearanceEditFormPage,
43    NigeriaOnlinePaymentAddFormPage,
44    NigeriaExportPDFPaymentSlipPage,
45    NigeriaExportPDFClearanceSlipPage,
46    )
47
48from waeup.uniben.students.interfaces import (
49    ICustomStudent,
50    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
51    ICustomStudentStudyLevel,
52    ICustomUGStudentClearance,
53    ICustomPGStudentClearance)
54from waeup.uniben.interfaces import MessageFactory as _
55
56class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
57    """ Page to view an online payment ticket
58    """
59    grok.context(ICustomStudentOnlinePayment)
60    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
61        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
62    form_fields[
63        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
64    form_fields[
65        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
66
67class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
68    """ View to edit student clearance data by student
69    """
70
71    @property
72    def form_fields(self):
73        if self.context.is_postgrad:
74            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
75            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
76            'physical_clearance_date')
77        else:
78            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
79            'clearance_locked', 'clr_code', 'officer_comment',
80            'physical_clearance_date')
81            form_fields['date_of_birth'].for_display = True
82            form_fields['nationality'].for_display = True
83            form_fields['lga'].for_display = True
84        return form_fields
85
86    def dataNotComplete(self):
87        store = getUtility(IExtFileStore)
88        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
89            return _('No birth certificate uploaded.')
90        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
91            return _('No guarantor/referee letter uploaded.')
92        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
93            return _('No acceptance letter uploaded.')
94        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
95            return _('No first sitting result uploaded.')
96        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
97        #    return _('No second sitting result uploaded.')
98        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
99            return _('No affidavit of non-membership of secret cults uploaded.')
100        return False
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 CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
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
118class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
119    """Deliver a PDF slip of the context.
120    """
121
122    omit_fields = ('password', 'suspended', 'suspended_comment',
123        'phone', 'adm_code', 'email', 'date_of_birth')
124
125    def _sigsInFooter(self):
126        isStudent = getattr(
127            self.request.principal, 'user_type', None) == 'student'
128        if not isStudent and self.context.state in (CLEARED, RETURNING):
129            return (_('Date, Student Signature'),
130                    _('Date, Clearance Officer Signature'),
131                    )
132        return ()
133
134    def render(self):
135        studentview = StudentBasePDFFormPage(self.context.student,
136            self.request, self.omit_fields)
137        students_utils = getUtility(IStudentsUtils)
138        return students_utils.renderPDF(
139            self, 'clearance_slip.pdf',
140            self.context.student, studentview, signatures=self._signatures(),
141            sigs_in_footer=self._sigsInFooter(), show_scans=False,
142            omit_fields=self.omit_fields)
143
144
145class ExportClearanceInvitationSlipPage(UtilityView, grok.View):
146    """Deliver an invitation letter to physical clearance.
147
148    This form page is available only in Uniben.
149    """
150    grok.context(ICustomStudent)
151    grok.name('clearance_invitation_slip.pdf')
152    grok.require('waeup.viewStudent')
153    prefix = 'form'
154
155    label = u'Invitation Letter for Physical Clearance'
156
157    omit_fields = (
158        'suspended', 'phone', 'email',
159        'adm_code', 'suspended_comment',
160        'date_of_birth', 'current_level',
161        'department', 'current_mode',
162        'entry_session', 'matric_number', 'sex')
163
164    form_fields = []
165
166    @property
167    def note(self):
168        if self.context.physical_clearance_date:
169            return """
170<br /><br /><br /><br /><font size='12'>
171Dear %s,
172<br /><br /><br />
173You are invited for your physical clearance on:
174<br /><br />
175<strong>%s</strong>.
176<br /><br />
177Please bring along this letter of invitation to the University Main Auditorium
178<br /><br />
179on your clearance date.
180<br /><br /><br />
181Signed,
182<br /><br />
183The Registrar<br />
184</font>
185
186""" % (self.context.display_fullname, self.context.physical_clearance_date)
187        return
188
189
190    def update(self):
191        if self.context.student.state != REQUESTED \
192            or not  self.context.student.physical_clearance_date:
193            self.flash(_('Forbidden'), type="warning")
194            self.redirect(self.url(self.context))
195
196    def render(self):
197        studentview = StudentBasePDFFormPage(self.context.student,
198            self.request, self.omit_fields)
199        students_utils = getUtility(IStudentsUtils)
200        return students_utils.renderPDF(
201            self, 'clearance_invitation_slip',
202            self.context.student, studentview,
203            omit_fields=self.omit_fields,
204            note=self.note)
205
206class StudyCourseCOEditFormPage(KofaEditFormPage):
207    """ Page to edit the student study course data by clearance officers.
208
209    This form page is available only in Uniben.
210    """
211    grok.context(ICustomStudentStudyCourse)
212    grok.name('edit_level')
213    grok.require('waeup.clearStudent')
214    label = _('Edit current level')
215    pnav = 4
216    form_fields = grok.AutoFields(
217        ICustomStudentStudyCourse).select('current_level')
218
219    def update(self):
220        if not (self.context.is_current and
221            self.context.student.state == REQUESTED):
222            emit_lock_message(self)
223            return
224        super(StudyCourseCOEditFormPage, self).update()
225        return
226
227    @action(_('Save'), style='primary')
228    def save(self, **data):
229        try:
230            msave(self, **data)
231        except ConstraintNotSatisfied:
232            # The selected level might not exist in certificate
233            self.flash(_('Current level not available for certificate.'))
234            return
235        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
236        return
237
238class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
239    """ Page to edit the student study level data by students.
240
241    """
242    grok.template('studyleveleditpage')
243
244class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
245    """ Page to display student study levels
246    """
247    grok.template('studylevelpage')
248
249class CustomExportPDFCourseRegistrationSlipPage(
250    ExportPDFCourseRegistrationSlipPage):
251    """Deliver a PDF slip of the context.
252    """
253
254    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
255        'level_verdict', 'gpa')
256
257    @property
258    def tabletitle(self):
259        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
260        tabletitle = []
261        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
262            target_language=portal_language))
263        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
264            target_language=portal_language))
265        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
266            target_language=portal_language))
267        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
268            target_language=portal_language))
269        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
270            target_language=portal_language))
271        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
272            target_language=portal_language))
273        return tabletitle
274
275    def render(self):
276        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
277        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
278        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
279        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
280        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
281        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
282        studentview = StudentBasePDFFormPage(self.context.student,
283            self.request, self.omit_fields)
284        students_utils = getUtility(IStudentsUtils)
285
286        tabledata = []
287        tableheader = []
288        contenttitle = []
289        for i in range(1,7):
290            tabledata.append(sorted(
291                [value for value in self.context.values() if value.semester == i],
292                key=lambda value: str(value.semester) + value.code))
293            tableheader.append([(Code,'code', 2.5),
294                             (Title,'title', 5),
295                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
296                             (Cred, 'credits', 1.5),
297                             ])
298        return students_utils.renderPDF(
299            self, 'course_registration_slip.pdf',
300            self.context.student, studentview,
301            tableheader=tableheader,
302            tabledata=tabledata,
303            omit_fields=self.omit_fields
304            )
305
306class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
307    """Deliver a PDF slip of the context.
308    """
309
310    grok.name('course_result_slip.pdf')
311
312    @property
313    def tabletitle(self):
314        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
315        tabletitle = []
316        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
317            target_language=portal_language))
318        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
319            target_language=portal_language))
320        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
321            target_language=portal_language))
322        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
323            target_language=portal_language))
324        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
325            target_language=portal_language))
326        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
327            target_language=portal_language))
328        return tabletitle
329
330    @property
331    def label(self):
332        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
333        lang = self.request.cookies.get('kofa.language', portal_language)
334        level_title = translate(self.context.level_title, 'waeup.kofa',
335            target_language=lang)
336        return translate(_('Course Result Slip'),
337            'waeup.uniben', target_language=portal_language) \
338            + ' %s' % level_title
339
340    def render(self):
341        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
342        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
343        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
344        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
345        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
346        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
347        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
348        studentview = StudentBasePDFFormPage(self.context.student,
349            self.request, self.omit_fields)
350        students_utils = getUtility(IStudentsUtils)
351
352        tabledata = []
353        tableheader = []
354        contenttitle = []
355        for i in range(1,7):
356            tabledata.append(sorted(
357                [value for value in self.context.values() if value.semester == i],
358                key=lambda value: str(value.semester) + value.code))
359            tableheader.append([(Code,'code', 2.5),
360                             (Title,'title', 5),
361                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
362                             (Cred, 'credits', 1.5),
363                             (Grade, 'grade', 1.5),
364                             ])
365        return students_utils.renderPDF(
366            self, 'course_registration_slip.pdf',
367            self.context.student, studentview,
368            tableheader=tableheader,
369            tabledata=tabledata,
370            omit_fields=self.omit_fields
371            )
372
373class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
374    """ Page to display course tickets
375    """
376    form_fields = grok.AutoFields(ICourseTicket).omit('score')
377
378class CustomStudentActivatePage(StudentActivatePage):
379    """ Activate student account
380    """
381
382    def update(self):
383        self.context.suspended = False
384        self.context.writeLogMessage(self, 'account activated')
385        history = IObjectHistory(self.context)
386        history.addMessage('Student account activated', user='undisclosed')
387        self.flash(_('Student account has been activated.'))
388        self.redirect(self.url(self.context))
389        return
390
391class CustomStudentDeactivatePage(StudentDeactivatePage):
392    """ Deactivate student account
393    """
394    def update(self):
395        self.context.suspended = True
396        self.context.writeLogMessage(self, 'account deactivated')
397        history = IObjectHistory(self.context)
398        history.addMessage('Student account deactivated', user='undisclosed')
399        self.flash(_('Student account has been deactivated.'))
400        self.redirect(self.url(self.context))
401        return
402
403class CustomExportPDFTranscriptPage(ExportPDFTranscriptPage):
404    """Deliver a PDF slip of the context.
405    """
406
407    def _sigsInFooter(self):
408        return []
409        #return (_('CERTIFIED TRUE COPY'),)
410
411    def _signatures(self):
412        return ([(
413            'Current HD<br /> D. R. (Exams & Records)<br /> '
414            'For: Registrar')],)
415
416    def render(self):
417        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
418        Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language)
419        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
420        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
421        Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language)
422        #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
423        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
424        studentview = StudentBasePDFFormPage(self.context.student,
425            self.request, self.omit_fields)
426        students_utils = getUtility(IStudentsUtils)
427
428        tableheader = [(Code,'code', 2.5),
429                         (Title,'title', 8.5),
430                         (Term, 'semester', 1.5),
431                         (Cred, 'credits', 1.5),
432                         #(Score, 'score', 1.5),
433                         (Grade, 'grade', 1.5),
434                         ]
435
436        return students_utils.renderPDFTranscript(
437            self, 'transcript.pdf',
438            self.context.student, studentview,
439            omit_fields=self.omit_fields,
440            tableheader=tableheader,
441            signatures=self._signatures(),
442            sigs_in_footer=self._sigsInFooter(),
443            )
Note: See TracBrowser for help on using the repository browser.