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

Last change on this file since 11541 was 11537, checked in by Henrik Bettermann, 11 years ago

Show current level in student base data section on clearance slip.

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