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

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

Add clearance invitation slip.

  • Property svn:keywords set to Id
File size: 15.0 KB
Line 
1## $Id: browser.py 12121 2014-12-03 05:14:41Z 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)
33from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
34from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
35from kofacustom.nigeria.students.browser import (
36    NigeriaOnlinePaymentDisplayFormPage,
37    NigeriaStudentBaseManageFormPage,
38    NigeriaStudentClearanceEditFormPage,
39    NigeriaOnlinePaymentAddFormPage,
40    NigeriaExportPDFPaymentSlipPage,
41    NigeriaExportPDFClearanceSlipPage,
42    )
43
44from waeup.uniben.students.interfaces import (
45    ICustomStudent,
46    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
47    ICustomStudentStudyLevel,
48    ICustomUGStudentClearance,
49    ICustomPGStudentClearance)
50from waeup.uniben.interfaces import MessageFactory as _
51
52class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
53    """ Page to view an online payment ticket
54    """
55    grok.context(ICustomStudentOnlinePayment)
56    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
57        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
58    form_fields[
59        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
60    form_fields[
61        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
62
63class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
64    """ View to edit student clearance data by student
65    """
66
67    @property
68    def form_fields(self):
69        if self.context.is_postgrad:
70            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
71            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment')
72        else:
73            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
74            'clearance_locked', 'clr_code', 'officer_comment')
75            form_fields['date_of_birth'].for_display = True
76            form_fields['nationality'].for_display = True
77            form_fields['lga'].for_display = True
78        return form_fields
79
80    def dataNotComplete(self):
81        store = getUtility(IExtFileStore)
82        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
83            return _('No birth certificate uploaded.')
84        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
85            return _('No guarantor/referee letter uploaded.')
86        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
87            return _('No acceptance letter uploaded.')
88        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
89            return _('No first sitting result uploaded.')
90        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
91        #    return _('No second sitting result uploaded.')
92        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
93            return _('No affidavit of non-membership of secret cults uploaded.')
94        return False
95
96class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
97    """ Page to add an online payment ticket
98    """
99    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
100        'p_category')
101
102class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
103    """Deliver a PDF slip of the context.
104    """
105    grok.context(ICustomStudentOnlinePayment)
106    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
107        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
108    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
109    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
110
111
112class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
113    """Deliver a PDF slip of the context.
114    """
115
116    omit_fields = ('password', 'suspended', 'suspended_comment',
117        'phone', 'adm_code', 'email', 'date_of_birth')
118
119    def render(self):
120        studentview = StudentBasePDFFormPage(self.context.student,
121            self.request, self.omit_fields)
122        students_utils = getUtility(IStudentsUtils)
123        return students_utils.renderPDF(
124            self, 'clearance_slip.pdf',
125            self.context.student, studentview, signatures=self._signatures(),
126            sigs_in_footer=self._sigsInFooter(), show_scans=False,
127            omit_fields=self.omit_fields)
128
129
130class ExportClearanceInvitationSlipPage(UtilityView, grok.View):
131    """Deliver an invitation letter to physical clearance.
132
133    This form page is available only in Uniben.
134    """
135    grok.context(ICustomStudent)
136    grok.name('clearance_invitation_slip.pdf')
137    grok.require('waeup.viewStudent')
138    prefix = 'form'
139
140    label = u'Invitation Letter to Physical Clearance'
141
142    omit_fields = (
143        'suspended', 'phone', 'email',
144        'adm_code', 'suspended_comment',
145        'date_of_birth', 'current_level',
146        'faculty', 'department', 'current_mode',
147        'entry_session', 'matric_number', 'sex')
148
149    form_fields = []
150
151    @property
152    def note(self):
153        if self.context.physical_clearance_date:
154            return """
155<br /><br /><br /><br /><font size="12">
156You are kindly invited to physical clearance on %s
157
158<br /><br />
159Clearance Officer<br />
160</font>
161
162""" % self.context.physical_clearance_date
163        return
164
165    def render(self):
166        studentview = StudentBasePDFFormPage(self.context.student,
167            self.request, self.omit_fields)
168        students_utils = getUtility(IStudentsUtils)
169        return students_utils.renderPDF(
170            self, 'clearance_invitation_slip',
171            self.context.student, studentview,
172            omit_fields=self.omit_fields,
173            note=self.note)
174
175class StudyCourseCOEditFormPage(KofaEditFormPage):
176    """ Page to edit the student study course data by clearance officers.
177
178    This form page is available only in Uniben.
179    """
180    grok.context(ICustomStudentStudyCourse)
181    grok.name('edit_level')
182    grok.require('waeup.clearStudent')
183    label = _('Edit current level')
184    pnav = 4
185    form_fields = grok.AutoFields(
186        ICustomStudentStudyCourse).select('current_level')
187
188    def update(self):
189        if not (self.context.is_current and
190            self.context.student.state == REQUESTED):
191            emit_lock_message(self)
192            return
193        super(StudyCourseCOEditFormPage, self).update()
194        return
195
196    @action(_('Save'), style='primary')
197    def save(self, **data):
198        try:
199            msave(self, **data)
200        except ConstraintNotSatisfied:
201            # The selected level might not exist in certificate
202            self.flash(_('Current level not available for certificate.'))
203            return
204        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
205        return
206
207class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
208    """ Page to edit the student study level data by students.
209
210    """
211    grok.template('studyleveleditpage')
212
213class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
214    """ Page to display student study levels
215    """
216    grok.template('studylevelpage')
217
218class CustomExportPDFCourseRegistrationSlipPage(
219    ExportPDFCourseRegistrationSlipPage):
220    """Deliver a PDF slip of the context.
221    """
222
223    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
224        'level_verdict', 'gpa')
225
226    @property
227    def tabletitle(self):
228        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
229        tabletitle = []
230        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
231            target_language=portal_language))
232        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
233            target_language=portal_language))
234        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
235            target_language=portal_language))
236        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
237            target_language=portal_language))
238        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
239            target_language=portal_language))
240        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
241            target_language=portal_language))
242        return tabletitle
243
244    def render(self):
245        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
246        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
247        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
248        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
249        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
250        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
251        studentview = StudentBasePDFFormPage(self.context.student,
252            self.request, self.omit_fields)
253        students_utils = getUtility(IStudentsUtils)
254
255        tabledata = []
256        tableheader = []
257        contenttitle = []
258        for i in range(1,7):
259            tabledata.append(sorted(
260                [value for value in self.context.values() if value.semester == i],
261                key=lambda value: str(value.semester) + value.code))
262            tableheader.append([(Code,'code', 2.5),
263                             (Title,'title', 5),
264                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
265                             (Cred, 'credits', 1.5),
266                             ])
267        return students_utils.renderPDF(
268            self, 'course_registration_slip.pdf',
269            self.context.student, studentview,
270            tableheader=tableheader,
271            tabledata=tabledata,
272            omit_fields=self.omit_fields
273            )
274
275class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
276    """Deliver a PDF slip of the context.
277    """
278
279    grok.name('course_result_slip.pdf')
280
281    @property
282    def tabletitle(self):
283        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
284        tabletitle = []
285        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
286            target_language=portal_language))
287        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
288            target_language=portal_language))
289        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
290            target_language=portal_language))
291        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
292            target_language=portal_language))
293        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
294            target_language=portal_language))
295        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
296            target_language=portal_language))
297        return tabletitle
298
299    @property
300    def label(self):
301        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
302        lang = self.request.cookies.get('kofa.language', portal_language)
303        level_title = translate(self.context.level_title, 'waeup.kofa',
304            target_language=lang)
305        return translate(_('Course Result Slip'),
306            'waeup.uniben', target_language=portal_language) \
307            + ' %s' % level_title
308
309    def render(self):
310        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
311        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
312        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
313        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
314        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
315        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
316        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
317        studentview = StudentBasePDFFormPage(self.context.student,
318            self.request, self.omit_fields)
319        students_utils = getUtility(IStudentsUtils)
320
321        tabledata = []
322        tableheader = []
323        contenttitle = []
324        for i in range(1,7):
325            tabledata.append(sorted(
326                [value for value in self.context.values() if value.semester == i],
327                key=lambda value: str(value.semester) + value.code))
328            tableheader.append([(Code,'code', 2.5),
329                             (Title,'title', 5),
330                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
331                             (Cred, 'credits', 1.5),
332                             (Grade, 'grade', 1.5),
333                             ])
334        return students_utils.renderPDF(
335            self, 'course_registration_slip.pdf',
336            self.context.student, studentview,
337            tableheader=tableheader,
338            tabledata=tabledata,
339            omit_fields=self.omit_fields
340            )
341
342class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
343    """ Page to display course tickets
344    """
345    form_fields = grok.AutoFields(ICourseTicket).omit('score')
346
347class CustomStudentActivatePage(StudentActivatePage):
348    """ Activate student account
349    """
350
351    def update(self):
352        self.context.suspended = False
353        self.context.writeLogMessage(self, 'account activated')
354        history = IObjectHistory(self.context)
355        history.addMessage('Student account activated', user='undisclosed')
356        self.flash(_('Student account has been activated.'))
357        self.redirect(self.url(self.context))
358        return
359
360class CustomStudentDeactivatePage(StudentDeactivatePage):
361    """ Deactivate student account
362    """
363    def update(self):
364        self.context.suspended = True
365        self.context.writeLogMessage(self, 'account deactivated')
366        history = IObjectHistory(self.context)
367        history.addMessage('Student account deactivated', user='undisclosed')
368        self.flash(_('Student account has been deactivated.'))
369        self.redirect(self.url(self.context))
370        return
Note: See TracBrowser for help on using the repository browser.