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

Last change on this file since 9958 was 9958, checked in by Henrik Bettermann, 12 years ago

Add level course table also in custom package.

  • Property svn:keywords set to Id
File size: 12.7 KB
Line 
1## $Id: browser.py 9958 2013-02-15 13:38:34Z 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 REQUESTED, IExtFileStore, IKofaUtils
24from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
25from waeup.kofa.browser.layout import KofaEditFormPage
26from waeup.kofa.browser.layout import action, jsaction
27from waeup.kofa.students.browser import (
28    StudentClearPage, StudentRejectClearancePage,
29    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
30    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage,
31    CourseTicketDisplayFormPage,
32    msave, emit_lock_message)
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 CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
50    """ View to manage student base data
51    """
52    #grok.context(ICustomStudent)
53
54    def getTransitions(self):
55        """Return a list of dicts of allowed transition ids and titles.
56
57        Each list entry provides keys ``name`` and ``title`` for
58        internal name and (human readable) title of a single
59        transition.
60        """
61        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
62            if not t[0].startswith('pay')]
63        if self.context.is_postgrad and not self.context.is_special_postgrad:
64            allowed_transitions = [t for t in allowed_transitions
65                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
66        return [dict(name='', title=_('No transition'))] +[
67            dict(name=x, title=y) for x, y in allowed_transitions]
68
69class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
70    """ Page to view an online payment ticket
71    """
72    grok.context(ICustomStudentOnlinePayment)
73    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
74        'provider_amt', 'gateway_amt', 'thirdparty_amt')
75    form_fields[
76        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
77    form_fields[
78        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
79
80class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
81    """ View to edit student clearance data by student
82    """
83
84    def dataNotComplete(self):
85        store = getUtility(IExtFileStore)
86        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
87            return _('No birth certificate uploaded.')
88        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
89            return _('No guarantor/referee letter uploaded.')
90        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
91            return _('No acceptance letter uploaded.')
92        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
93            return _('No first sitting result uploaded.')
94        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
95        #    return _('No second sitting result uploaded.')
96        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
97            return _('No affidavit of non-membership of secret cults uploaded.')
98        return False
99
100class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
101    """ Page to add an online payment ticket
102    """
103    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
104        'p_category')
105
106class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
107    """Deliver a PDF slip of the context.
108    """
109    grok.context(ICustomStudentOnlinePayment)
110    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
111        'provider_amt', 'gateway_amt', 'thirdparty_amt')
112    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
113    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
114
115
116class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
117    """Deliver a PDF slip of the context.
118    """
119
120    def render(self):
121        studentview = StudentBasePDFFormPage(self.context.student,
122            self.request, self.omit_fields)
123        students_utils = getUtility(IStudentsUtils)
124        return students_utils.renderPDF(
125            self, 'clearance_slip.pdf',
126            self.context.student, studentview, signatures=self._signatures(),
127            sigs_in_footer=self._sigsInFooter(), show_scans=False)
128
129class StudyCourseCOEditFormPage(KofaEditFormPage):
130    """ Page to edit the student study course data by clearance officers.
131
132    This form page is available only in Uniben.
133    """
134    grok.context(ICustomStudentStudyCourse)
135    grok.name('edit_level')
136    grok.require('waeup.clearStudent')
137    label = _('Edit current level')
138    pnav = 4
139    form_fields = grok.AutoFields(
140        ICustomStudentStudyCourse).select('current_level')
141
142    def update(self):
143        if not (self.context.is_current and
144            self.context.student.state == REQUESTED):
145            emit_lock_message(self)
146            return
147        super(StudyCourseCOEditFormPage, self).update()
148        return
149
150    @action(_('Save'), style='primary')
151    def save(self, **data):
152        try:
153            msave(self, **data)
154        except ConstraintNotSatisfied:
155            # The selected level might not exist in certificate
156            self.flash(_('Current level not available for certificate.'))
157            return
158        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
159        return
160
161class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
162    """ Page to edit the student study level data by students.
163
164    """
165    grok.template('studyleveleditpage')
166
167    def _registerCourses(self, **data):
168        """ This customized version does allow 'special postgraduate'
169        students to register their courses.
170        """
171        if self.context.student.is_postgrad and \
172            not self.context.student.is_special_postgrad:
173            self.flash(_(
174                "You are a postgraduate student, "
175                "your course list can't bee registered."))
176            self.redirect(self.url(self.context))
177            return
178        students_utils = getUtility(IStudentsUtils)
179        max_credits = students_utils.maxCredits(self.context)
180        if self.context.total_credits > max_credits:
181            self.flash(_('Maximum credits of ${a} exceeded.',
182                mapping = {'a':max_credits}))
183            return
184        IWorkflowInfo(self.context.student).fireTransition(
185            'register_courses')
186        self.flash(_('Course list has been registered.'))
187        self.redirect(self.url(self.context))
188        return
189
190class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
191    """ Page to display student study levels
192    """
193    grok.template('studylevelpage')
194
195class CustomExportPDFCourseRegistrationSlipPage(
196    ExportPDFCourseRegistrationSlipPage):
197    """Deliver a PDF slip of the context.
198    """
199
200    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
201        'level_verdict', 'gpa')
202
203    def render(self):
204        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
205        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
206        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
207        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
208        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
209        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
210        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
211        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
212        studentview = StudentBasePDFFormPage(self.context.student,
213            self.request, self.omit_fields)
214        students_utils = getUtility(IStudentsUtils)
215        tabledata_1 = sorted(
216            [value for value in self.context.values() if value.semester == 1],
217            key=lambda value: str(value.semester) + value.code)
218        tabledata_2 = sorted(
219            [value for value in self.context.values() if value.semester == 2],
220            key=lambda value: str(value.semester) + value.code)
221        tableheader = [(Code,'code', 2.5),
222                         (Title,'title', 5),
223                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
224                         (Cred, 'credits', 1.5),
225                         ]
226        return students_utils.renderPDF(
227            self, 'course_registration_slip.pdf',
228            self.context.student, studentview,
229            tableheader_1=tableheader,
230            tabledata_1=tabledata_1,
231            tableheader_2=tableheader,
232            tabledata_2=tabledata_2
233            )
234
235class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
236    """Deliver a PDF slip of the context.
237    """
238
239    grok.name('course_result_slip.pdf')
240
241    @property
242    def label(self):
243        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
244        lang = self.request.cookies.get('kofa.language', portal_language)
245        level_title = translate(self.context.level_title, 'waeup.kofa',
246            target_language=lang)
247        return translate(_('Course Result Slip'),
248            'waeup.uniben', target_language=portal_language) \
249            + ' %s' % level_title
250
251    def render(self):
252        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
253        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
254        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
255        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
256        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
257        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
258        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
259        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
260        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
261        studentview = StudentBasePDFFormPage(self.context.student,
262            self.request, self.omit_fields)
263        students_utils = getUtility(IStudentsUtils)
264        tabledata_1 = sorted(
265            [value for value in self.context.values() if value.semester == 1],
266            key=lambda value: str(value.semester) + value.code)
267        tabledata_2 = sorted(
268            [value for value in self.context.values() if value.semester == 2],
269            key=lambda value: str(value.semester) + value.code)
270        tabledata_3 = sorted(
271            [value for value in self.context.values() if value.semester == 3],
272            key=lambda value: str(value.semester) + value.code)
273        tableheader = [(Code,'code', 2.5),
274                         (Title,'title', 5),
275                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
276                         (Cred, 'credits', 1.5),
277                         (Grade, 'grade', 1.5),
278                         ]
279        return students_utils.renderPDF(
280            self, 'course_registration_slip.pdf',
281            self.context.student, studentview,
282            tableheader_1=tableheader,
283            tabledata_1=tabledata_1,
284            tableheader_2=tableheader,
285            tabledata_2=tabledata_2,
286            tableheader_3=tableheader,
287            tabledata_3=tabledata_3
288            )
289
290class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
291    """ Page to display course tickets
292    """
293    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.