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

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

Do not require second sitting scan.

  • Property svn:keywords set to Id
File size: 7.9 KB
Line 
1## $Id: browser.py 9395 2012-10-23 14:22:17Z 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.viewlets import ManageActionButton
27from waeup.kofa.browser.layout import action, jsaction
28from waeup.kofa.students.browser import (
29    StudentClearPage, StudentRejectClearancePage,
30    StudyCourseDisplayFormPage,
31    StudyLevelEditFormPage,
32    msave, emit_lock_message)
33from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
34from kofacustom.nigeria.students.browser import (
35    NigeriaOnlinePaymentDisplayFormPage,
36    NigeriaStudentBaseManageFormPage,
37    NigeriaStudentClearanceEditFormPage,
38    NigeriaOnlinePaymentAddFormPage,
39    NigeriaExportPDFPaymentSlipPage,
40    )
41#from waeup.uniben.students.interfaces import ICustomStudent
42
43from waeup.uniben.students.interfaces import (
44    ICustomStudentOnlinePayment, ICustomStudentStudyCourse)
45from waeup.uniben.interfaces import MessageFactory as _
46
47class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
48    """ View to manage student base data
49    """
50    #grok.context(ICustomStudent)
51
52    def getTransitions(self):
53        """Return a list of dicts of allowed transition ids and titles.
54
55        Each list entry provides keys ``name`` and ``title`` for
56        internal name and (human readable) title of a single
57        transition.
58        """
59        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
60            if not t[0].startswith('pay')]
61        if self.context.is_postgrad and not self.context.is_special_postgrad:
62            allowed_transitions = [t for t in allowed_transitions
63                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
64        return [dict(name='', title=_('No transition'))] +[
65            dict(name=x, title=y) for x, y in allowed_transitions]
66
67class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
68    """ Page to view an online payment ticket
69    """
70    grok.context(ICustomStudentOnlinePayment)
71    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
72    form_fields[
73        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
74    form_fields[
75        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
76
77class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
78    """ View to edit student clearance data by student
79    """
80
81    def dataNotComplete(self):
82        store = getUtility(IExtFileStore)
83        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
84            return _('No birth certificate uploaded.')
85        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
86            return _('No guarantor/referee letter uploaded.')
87        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
88            return _('No acceptance letter uploaded.')
89        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
90            return _('No first sitting result uploaded.')
91        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
92        #    return _('No second sitting result uploaded.')
93        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
94            return _('No affidavit of non-menbership of secret cults uploaded.')
95        return False
96
97class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
98    """ Page to add an online payment ticket
99    """
100    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
101        'p_category')
102
103class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
104    """Deliver a PDF slip of the context.
105    """
106    grok.context(ICustomStudentOnlinePayment)
107    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
108    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
109    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
110
111
112## In case we need to deactivate clearance
113#class CustomStudentClearPage(StudentClearPage):
114#    """ Clear student by clearance officer
115#    """
116#    def update(self):
117#        self.flash('Clearance temporarily disabled!')
118#        self.redirect(self.url(self.context,'view_clearance'))
119#        return
120
121#class CustomStudentRejectClearancePage(StudentRejectClearancePage):
122#    """ Reject clearance by clearance officers
123#    """
124
125#    def update(self):
126#        self.flash('Clearance temporarily disabled!')
127#        self.redirect(self.url(self.context,'view_clearance'))
128#        return
129
130class StudyCourseEditActionButton(ManageActionButton):
131    grok.order(1)
132    grok.context(ICustomStudentStudyCourse)
133    grok.view(StudyCourseDisplayFormPage)
134    grok.require('waeup.clearStudent')
135    text = _('Edit level')
136    target = 'edit_level'
137
138    @property
139    def target_url(self):
140        if self.context.is_current and self.context.student.state == REQUESTED:
141            return self.view.url(self.view.context, self.target)
142        return 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
181    def _registerCourses(self, **data):
182        """ This customized version does allow 'special postgraduate'
183        students to register their courses.
184        """
185        if self.context.student.is_postgrad and \
186            not self.context.student.is_special_postgrad:
187            self.flash(_(
188                "You are a postgraduate student, "
189                "your course list can't bee registered."))
190            self.redirect(self.url(self.context))
191            return
192        if self.total_credits > self.max_credits:
193            self.flash(_('Maximum credits of ${a} exceeded.',
194                mapping = {'a':self.max_credits}))
195            return
196        IWorkflowInfo(self.context.student).fireTransition(
197            'register_courses')
198        self.flash(_('Course list has been registered.'))
199        self.redirect(self.url(self.context))
200        return
Note: See TracBrowser for help on using the repository browser.