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

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

Viewlets should be in viewlets.py.

  • Property svn:keywords set to Id
File size: 7.4 KB
Line 
1## $Id: browser.py 9439 2012-10-27 06:18:08Z 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
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,
30    msave, emit_lock_message)
31from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
32from kofacustom.nigeria.students.browser import (
33    NigeriaOnlinePaymentDisplayFormPage,
34    NigeriaStudentBaseManageFormPage,
35    NigeriaStudentClearanceEditFormPage,
36    NigeriaOnlinePaymentAddFormPage,
37    NigeriaExportPDFPaymentSlipPage,
38    )
39#from waeup.uniben.students.interfaces import ICustomStudent
40
41from waeup.uniben.students.interfaces import (
42    ICustomStudentOnlinePayment, ICustomStudentStudyCourse)
43from waeup.uniben.interfaces import MessageFactory as _
44
45class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
46    """ View to manage student base data
47    """
48    #grok.context(ICustomStudent)
49
50    def getTransitions(self):
51        """Return a list of dicts of allowed transition ids and titles.
52
53        Each list entry provides keys ``name`` and ``title`` for
54        internal name and (human readable) title of a single
55        transition.
56        """
57        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
58            if not t[0].startswith('pay')]
59        if self.context.is_postgrad and not self.context.is_special_postgrad:
60            allowed_transitions = [t for t in allowed_transitions
61                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
62        return [dict(name='', title=_('No transition'))] +[
63            dict(name=x, title=y) for x, y in allowed_transitions]
64
65class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
66    """ Page to view an online payment ticket
67    """
68    grok.context(ICustomStudentOnlinePayment)
69    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
70    form_fields[
71        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
72    form_fields[
73        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
74
75class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
76    """ View to edit student clearance data by student
77    """
78
79    def dataNotComplete(self):
80        store = getUtility(IExtFileStore)
81        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
82            return _('No birth certificate uploaded.')
83        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
84            return _('No guarantor/referee letter uploaded.')
85        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
86            return _('No acceptance letter uploaded.')
87        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
88            return _('No first sitting result uploaded.')
89        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
90        #    return _('No second sitting result uploaded.')
91        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
92            return _('No affidavit of non-menbership of secret cults uploaded.')
93        return False
94
95class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
96    """ Page to add an online payment ticket
97    """
98    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
99        'p_category')
100
101class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
102    """Deliver a PDF slip of the context.
103    """
104    grok.context(ICustomStudentOnlinePayment)
105    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
106    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
107    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
108
109
110## In case we need to deactivate clearance
111#class CustomStudentClearPage(StudentClearPage):
112#    """ Clear student by clearance officer
113#    """
114#    def update(self):
115#        self.flash('Clearance temporarily disabled!')
116#        self.redirect(self.url(self.context,'view_clearance'))
117#        return
118
119#class CustomStudentRejectClearancePage(StudentRejectClearancePage):
120#    """ Reject clearance by clearance officers
121#    """
122
123#    def update(self):
124#        self.flash('Clearance temporarily disabled!')
125#        self.redirect(self.url(self.context,'view_clearance'))
126#        return
127
128class StudyCourseCOEditFormPage(KofaEditFormPage):
129    """ Page to edit the student study course data by clearance officers.
130
131    This form page is available only in Uniben.
132    """
133    grok.context(ICustomStudentStudyCourse)
134    grok.name('edit_level')
135    grok.require('waeup.clearStudent')
136    label = _('Edit current level')
137    pnav = 4
138    form_fields = grok.AutoFields(
139        ICustomStudentStudyCourse).select('current_level')
140
141    def update(self):
142        if not (self.context.is_current and
143            self.context.student.state == REQUESTED):
144            emit_lock_message(self)
145            return
146        super(StudyCourseCOEditFormPage, self).update()
147        return
148
149    @action(_('Save'), style='primary')
150    def save(self, **data):
151        try:
152            msave(self, **data)
153        except ConstraintNotSatisfied:
154            # The selected level might not exist in certificate
155            self.flash(_('Current level not available for certificate.'))
156            return
157        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
158        return
159
160class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
161    """ Page to edit the student study level data by students.
162
163    """
164
165    def _registerCourses(self, **data):
166        """ This customized version does allow 'special postgraduate'
167        students to register their courses.
168        """
169        if self.context.student.is_postgrad and \
170            not self.context.student.is_special_postgrad:
171            self.flash(_(
172                "You are a postgraduate student, "
173                "your course list can't bee registered."))
174            self.redirect(self.url(self.context))
175            return
176        if self.total_credits > self.max_credits:
177            self.flash(_('Maximum credits of ${a} exceeded.',
178                mapping = {'a':self.max_credits}))
179            return
180        IWorkflowInfo(self.context.student).fireTransition(
181            'register_courses')
182        self.flash(_('Course list has been registered.'))
183        self.redirect(self.url(self.context))
184        return
Note: See TracBrowser for help on using the repository browser.