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

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

In Uniben fresh and returning students must not register courses with more than 50 credits. For final year students maximum credits is 51.

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