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

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

Adjust to changes in base package.

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