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

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

University Main Auditorium

  • Property svn:keywords set to Id
File size: 15.5 KB
Line 
1## $Id: browser.py 12265 2014-12-19 13:31:59Z 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 for Physical Clearance'
141
142    omit_fields = (
143        'suspended', 'phone', 'email',
144        'adm_code', 'suspended_comment',
145        'date_of_birth', 'current_level',
146        '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'>
156Dear %s,
157<br /><br /><br />
158You are invited for your physical clearance on:
159<br /><br />
160<strong>%s</strong>.
161<br /><br />
162Please bring along this letter of invitation to the University Main Auditorium
163<br /><br />
164on your clearance date.
165<br /><br /><br />
166Signed,
167<br /><br />
168The Registrar<br />
169</font>
170
171""" % (self.context.display_fullname, self.context.physical_clearance_date)
172        return
173
174
175    def update(self):
176        if self.context.student.state != REQUESTED \
177            or not  self.context.student.physical_clearance_date:
178            self.flash(_('Forbidden'), type="warning")
179            self.redirect(self.url(self.context))
180
181    def render(self):
182        studentview = StudentBasePDFFormPage(self.context.student,
183            self.request, self.omit_fields)
184        students_utils = getUtility(IStudentsUtils)
185        return students_utils.renderPDF(
186            self, 'clearance_invitation_slip',
187            self.context.student, studentview,
188            omit_fields=self.omit_fields,
189            note=self.note)
190
191class StudyCourseCOEditFormPage(KofaEditFormPage):
192    """ Page to edit the student study course data by clearance officers.
193
194    This form page is available only in Uniben.
195    """
196    grok.context(ICustomStudentStudyCourse)
197    grok.name('edit_level')
198    grok.require('waeup.clearStudent')
199    label = _('Edit current level')
200    pnav = 4
201    form_fields = grok.AutoFields(
202        ICustomStudentStudyCourse).select('current_level')
203
204    def update(self):
205        if not (self.context.is_current and
206            self.context.student.state == REQUESTED):
207            emit_lock_message(self)
208            return
209        super(StudyCourseCOEditFormPage, self).update()
210        return
211
212    @action(_('Save'), style='primary')
213    def save(self, **data):
214        try:
215            msave(self, **data)
216        except ConstraintNotSatisfied:
217            # The selected level might not exist in certificate
218            self.flash(_('Current level not available for certificate.'))
219            return
220        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
221        return
222
223class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
224    """ Page to edit the student study level data by students.
225
226    """
227    grok.template('studyleveleditpage')
228
229class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
230    """ Page to display student study levels
231    """
232    grok.template('studylevelpage')
233
234class CustomExportPDFCourseRegistrationSlipPage(
235    ExportPDFCourseRegistrationSlipPage):
236    """Deliver a PDF slip of the context.
237    """
238
239    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
240        'level_verdict', 'gpa')
241
242    @property
243    def tabletitle(self):
244        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
245        tabletitle = []
246        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
247            target_language=portal_language))
248        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
249            target_language=portal_language))
250        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
251            target_language=portal_language))
252        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
253            target_language=portal_language))
254        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
255            target_language=portal_language))
256        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
257            target_language=portal_language))
258        return tabletitle
259
260    def render(self):
261        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
262        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
263        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
264        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
265        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
266        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
267        studentview = StudentBasePDFFormPage(self.context.student,
268            self.request, self.omit_fields)
269        students_utils = getUtility(IStudentsUtils)
270
271        tabledata = []
272        tableheader = []
273        contenttitle = []
274        for i in range(1,7):
275            tabledata.append(sorted(
276                [value for value in self.context.values() if value.semester == i],
277                key=lambda value: str(value.semester) + value.code))
278            tableheader.append([(Code,'code', 2.5),
279                             (Title,'title', 5),
280                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
281                             (Cred, 'credits', 1.5),
282                             ])
283        return students_utils.renderPDF(
284            self, 'course_registration_slip.pdf',
285            self.context.student, studentview,
286            tableheader=tableheader,
287            tabledata=tabledata,
288            omit_fields=self.omit_fields
289            )
290
291class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
292    """Deliver a PDF slip of the context.
293    """
294
295    grok.name('course_result_slip.pdf')
296
297    @property
298    def tabletitle(self):
299        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
300        tabletitle = []
301        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
302            target_language=portal_language))
303        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
304            target_language=portal_language))
305        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
306            target_language=portal_language))
307        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
308            target_language=portal_language))
309        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
310            target_language=portal_language))
311        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
312            target_language=portal_language))
313        return tabletitle
314
315    @property
316    def label(self):
317        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
318        lang = self.request.cookies.get('kofa.language', portal_language)
319        level_title = translate(self.context.level_title, 'waeup.kofa',
320            target_language=lang)
321        return translate(_('Course Result Slip'),
322            'waeup.uniben', target_language=portal_language) \
323            + ' %s' % level_title
324
325    def render(self):
326        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
327        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
328        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
329        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
330        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
331        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
332        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
333        studentview = StudentBasePDFFormPage(self.context.student,
334            self.request, self.omit_fields)
335        students_utils = getUtility(IStudentsUtils)
336
337        tabledata = []
338        tableheader = []
339        contenttitle = []
340        for i in range(1,7):
341            tabledata.append(sorted(
342                [value for value in self.context.values() if value.semester == i],
343                key=lambda value: str(value.semester) + value.code))
344            tableheader.append([(Code,'code', 2.5),
345                             (Title,'title', 5),
346                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
347                             (Cred, 'credits', 1.5),
348                             (Grade, 'grade', 1.5),
349                             ])
350        return students_utils.renderPDF(
351            self, 'course_registration_slip.pdf',
352            self.context.student, studentview,
353            tableheader=tableheader,
354            tabledata=tabledata,
355            omit_fields=self.omit_fields
356            )
357
358class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
359    """ Page to display course tickets
360    """
361    form_fields = grok.AutoFields(ICourseTicket).omit('score')
362
363class CustomStudentActivatePage(StudentActivatePage):
364    """ Activate student account
365    """
366
367    def update(self):
368        self.context.suspended = False
369        self.context.writeLogMessage(self, 'account activated')
370        history = IObjectHistory(self.context)
371        history.addMessage('Student account activated', user='undisclosed')
372        self.flash(_('Student account has been activated.'))
373        self.redirect(self.url(self.context))
374        return
375
376class CustomStudentDeactivatePage(StudentDeactivatePage):
377    """ Deactivate student account
378    """
379    def update(self):
380        self.context.suspended = True
381        self.context.writeLogMessage(self, 'account deactivated')
382        history = IObjectHistory(self.context)
383        history.addMessage('Student account deactivated', user='undisclosed')
384        self.flash(_('Student account has been deactivated.'))
385        self.redirect(self.url(self.context))
386        return
Note: See TracBrowser for help on using the repository browser.