source: main/waeup.uniben/branches/0.1/src/waeup/uniben/students/browser.py

Last change on this file was 11069, checked in by Henrik Bettermann, 11 years ago

Do not show public user name in history when activating or deactivating students.

  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
1## $Id: browser.py 11069 2014-02-11 07:49:25Z 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, jsaction, 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    def render(self):
101        studentview = StudentBasePDFFormPage(self.context.student,
102            self.request, self.omit_fields)
103        students_utils = getUtility(IStudentsUtils)
104        return students_utils.renderPDF(
105            self, 'clearance_slip.pdf',
106            self.context.student, studentview, signatures=self._signatures(),
107            sigs_in_footer=self._sigsInFooter(), show_scans=False,
108            omit_fields=self.omit_fields)
109
110class StudyCourseCOEditFormPage(KofaEditFormPage):
111    """ Page to edit the student study course data by clearance officers.
112
113    This form page is available only in Uniben.
114    """
115    grok.context(ICustomStudentStudyCourse)
116    grok.name('edit_level')
117    grok.require('waeup.clearStudent')
118    label = _('Edit current level')
119    pnav = 4
120    form_fields = grok.AutoFields(
121        ICustomStudentStudyCourse).select('current_level')
122
123    def update(self):
124        if not (self.context.is_current and
125            self.context.student.state == REQUESTED):
126            emit_lock_message(self)
127            return
128        super(StudyCourseCOEditFormPage, self).update()
129        return
130
131    @action(_('Save'), style='primary')
132    def save(self, **data):
133        try:
134            msave(self, **data)
135        except ConstraintNotSatisfied:
136            # The selected level might not exist in certificate
137            self.flash(_('Current level not available for certificate.'))
138            return
139        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
140        return
141
142class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
143    """ Page to edit the student study level data by students.
144
145    """
146    grok.template('studyleveleditpage')
147
148class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
149    """ Page to display student study levels
150    """
151    grok.template('studylevelpage')
152
153class CustomExportPDFCourseRegistrationSlipPage(
154    ExportPDFCourseRegistrationSlipPage):
155    """Deliver a PDF slip of the context.
156    """
157
158    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
159        'level_verdict', 'gpa')
160
161    @property
162    def tabletitle(self):
163        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
164        tabletitle = []
165        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
166            target_language=portal_language))
167        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
168            target_language=portal_language))
169        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
170            target_language=portal_language))
171        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
172            target_language=portal_language))
173        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
174            target_language=portal_language))
175        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
176            target_language=portal_language))
177        return tabletitle
178
179    def render(self):
180        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
181        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
182        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
183        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
184        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
185        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
186        studentview = StudentBasePDFFormPage(self.context.student,
187            self.request, self.omit_fields)
188        students_utils = getUtility(IStudentsUtils)
189
190        tabledata = []
191        tableheader = []
192        contenttitle = []
193        for i in range(1,7):
194            tabledata.append(sorted(
195                [value for value in self.context.values() if value.semester == i],
196                key=lambda value: str(value.semester) + value.code))
197            tableheader.append([(Code,'code', 2.5),
198                             (Title,'title', 5),
199                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
200                             (Cred, 'credits', 1.5),
201                             ])
202        return students_utils.renderPDF(
203            self, 'course_registration_slip.pdf',
204            self.context.student, studentview,
205            tableheader=tableheader,
206            tabledata=tabledata,
207            omit_fields=self.omit_fields
208            )
209
210class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
211    """Deliver a PDF slip of the context.
212    """
213
214    grok.name('course_result_slip.pdf')
215
216    @property
217    def tabletitle(self):
218        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
219        tabletitle = []
220        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
221            target_language=portal_language))
222        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
223            target_language=portal_language))
224        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
225            target_language=portal_language))
226        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
227            target_language=portal_language))
228        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
229            target_language=portal_language))
230        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
231            target_language=portal_language))
232        return tabletitle
233
234    @property
235    def label(self):
236        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
237        lang = self.request.cookies.get('kofa.language', portal_language)
238        level_title = translate(self.context.level_title, 'waeup.kofa',
239            target_language=lang)
240        return translate(_('Course Result Slip'),
241            'waeup.uniben', target_language=portal_language) \
242            + ' %s' % level_title
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        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
252        studentview = StudentBasePDFFormPage(self.context.student,
253            self.request, self.omit_fields)
254        students_utils = getUtility(IStudentsUtils)
255
256        tabledata = []
257        tableheader = []
258        contenttitle = []
259        for i in range(1,7):
260            tabledata.append(sorted(
261                [value for value in self.context.values() if value.semester == i],
262                key=lambda value: str(value.semester) + value.code))
263            tableheader.append([(Code,'code', 2.5),
264                             (Title,'title', 5),
265                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
266                             (Cred, 'credits', 1.5),
267                             (Grade, 'grade', 1.5),
268                             ])
269        return students_utils.renderPDF(
270            self, 'course_registration_slip.pdf',
271            self.context.student, studentview,
272            tableheader=tableheader,
273            tabledata=tabledata,
274            omit_fields=self.omit_fields
275            )
276
277class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
278    """ Page to display course tickets
279    """
280    form_fields = grok.AutoFields(ICourseTicket).omit('score')
281
282class CustomStudentActivatePage(StudentActivatePage):
283    """ Activate student account
284    """
285
286    def update(self):
287        self.context.suspended = False
288        self.context.writeLogMessage(self, 'account activated')
289        history = IObjectHistory(self.context)
290        history.addMessage('Student account activated', user='undisclosed')
291        self.flash(_('Student account has been activated.'))
292        self.redirect(self.url(self.context))
293        return
294
295class CustomStudentDeactivatePage(StudentDeactivatePage):
296    """ Deactivate student account
297    """
298    def update(self):
299        self.context.suspended = True
300        self.context.writeLogMessage(self, 'account deactivated')
301        history = IObjectHistory(self.context)
302        history.addMessage('Student account deactivated', user='undisclosed')
303        self.flash(_('Student account has been deactivated.'))
304        self.redirect(self.url(self.context))
305        return
Note: See TracBrowser for help on using the repository browser.