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

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

Adjust to recent revisions.

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