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

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

Show GPA.

  • Property svn:keywords set to Id
File size: 10.2 KB
Line 
1## $Id: browser.py 9688 2012-11-19 18:19:35Z 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)
46from waeup.uniben.interfaces import MessageFactory as _
47
48class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
49    """ View to manage student base data
50    """
51    #grok.context(ICustomStudent)
52
53    def getTransitions(self):
54        """Return a list of dicts of allowed transition ids and titles.
55
56        Each list entry provides keys ``name`` and ``title`` for
57        internal name and (human readable) title of a single
58        transition.
59        """
60        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
61            if not t[0].startswith('pay')]
62        if self.context.is_postgrad and not self.context.is_special_postgrad:
63            allowed_transitions = [t for t in allowed_transitions
64                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
65        return [dict(name='', title=_('No transition'))] +[
66            dict(name=x, title=y) for x, y in allowed_transitions]
67
68class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
69    """ Page to view an online payment ticket
70    """
71    grok.context(ICustomStudentOnlinePayment)
72    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
73    form_fields[
74        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
75    form_fields[
76        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
77
78class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
79    """ View to edit student clearance data by student
80    """
81
82    def dataNotComplete(self):
83        store = getUtility(IExtFileStore)
84        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
85            return _('No birth certificate uploaded.')
86        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
87            return _('No guarantor/referee letter uploaded.')
88        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
89            return _('No acceptance letter uploaded.')
90        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
91            return _('No first sitting result uploaded.')
92        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
93        #    return _('No second sitting result uploaded.')
94        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
95            return _('No affidavit of non-menbership of secret cults uploaded.')
96        return False
97
98class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
99    """ Page to add an online payment ticket
100    """
101    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
102        'p_category')
103
104class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
105    """Deliver a PDF slip of the context.
106    """
107    grok.context(ICustomStudentOnlinePayment)
108    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
109    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
110    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
111
112
113## In case we need to deactivate clearance
114#class CustomStudentClearPage(StudentClearPage):
115#    """ Clear student by clearance officer
116#    """
117#    def update(self):
118#        self.flash('Clearance temporarily disabled!')
119#        self.redirect(self.url(self.context,'view_clearance'))
120#        return
121
122#class CustomStudentRejectClearancePage(StudentRejectClearancePage):
123#    """ Reject clearance by clearance officers
124#    """
125
126#    def update(self):
127#        self.flash('Clearance temporarily disabled!')
128#        self.redirect(self.url(self.context,'view_clearance'))
129#        return
130
131class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
132    """Deliver a PDF slip of the context.
133    """
134
135    def render(self):
136        studentview = StudentBasePDFFormPage(self.context.student,
137            self.request, self.omit_fields)
138        students_utils = getUtility(IStudentsUtils)
139        return students_utils.renderPDF(
140            self, 'clearance_slip.pdf',
141            self.context.student, studentview, signatures=self._signatures(),
142            sigs_in_footer=self._sigsInFooter(), show_scans=False)
143
144class StudyCourseCOEditFormPage(KofaEditFormPage):
145    """ Page to edit the student study course data by clearance officers.
146
147    This form page is available only in Uniben.
148    """
149    grok.context(ICustomStudentStudyCourse)
150    grok.name('edit_level')
151    grok.require('waeup.clearStudent')
152    label = _('Edit current level')
153    pnav = 4
154    form_fields = grok.AutoFields(
155        ICustomStudentStudyCourse).select('current_level')
156
157    def update(self):
158        if not (self.context.is_current and
159            self.context.student.state == REQUESTED):
160            emit_lock_message(self)
161            return
162        super(StudyCourseCOEditFormPage, self).update()
163        return
164
165    @action(_('Save'), style='primary')
166    def save(self, **data):
167        try:
168            msave(self, **data)
169        except ConstraintNotSatisfied:
170            # The selected level might not exist in certificate
171            self.flash(_('Current level not available for certificate.'))
172            return
173        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
174        return
175
176class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
177    """ Page to edit the student study level data by students.
178
179    """
180    grok.template('studyleveleditpage')
181
182    def _registerCourses(self, **data):
183        """ This customized version does allow 'special postgraduate'
184        students to register their courses.
185        """
186        if self.context.student.is_postgrad and \
187            not self.context.student.is_special_postgrad:
188            self.flash(_(
189                "You are a postgraduate student, "
190                "your course list can't bee registered."))
191            self.redirect(self.url(self.context))
192            return
193        if self.context.total_credits > self.max_credits:
194            self.flash(_('Maximum credits of ${a} exceeded.',
195                mapping = {'a':self.max_credits}))
196            return
197        IWorkflowInfo(self.context.student).fireTransition(
198            'register_courses')
199        self.flash(_('Course list has been registered.'))
200        self.redirect(self.url(self.context))
201        return
202
203class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
204    """ Page to display student study levels
205    """
206    grok.template('studylevelpage')
207
208class CustomExportPDFCourseRegistrationSlipPage(
209    ExportPDFCourseRegistrationSlipPage):
210    """Deliver a PDF slip of the context.
211    """
212
213    def render(self):
214        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
215        Sem = translate(_('Sem.'), 'waeup.kofa', target_language=portal_language)
216        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
217        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
218        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
219        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
220        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
221        Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
222        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
223        studentview = StudentBasePDFFormPage(self.context.student,
224            self.request, self.omit_fields)
225        students_utils = getUtility(IStudentsUtils)
226        tabledata = sorted(self.context.values(),
227            key=lambda value: str(value.semester) + value.code)
228        return students_utils.renderPDF(
229            self, 'course_registration_slip.pdf',
230            self.context.student, studentview,
231            tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5),
232                         (Title,'title', 5),
233                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
234                         (Cred, 'credits', 1.5),
235                         (Mand, 'mandatory', 1.5),
236                         (Grade, 'grade', 1.5),
237                         #('Auto', 'automatic', 1.5)
238                         ],
239            tabledata=tabledata)
240
241class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
242    """ Page to display course tickets
243    """
244    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.