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

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

Fix typo.

Add course result slip and remove grade column from course registration slip.

  • Property svn:keywords set to Id
File size: 11.8 KB
RevLine 
[8911]1## $Id: browser.py 9848 2013-01-09 09:33:01Z 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
[9210]20from zope.schema.interfaces import ConstraintNotSatisfied
[9380]21from zope.component import getUtility
[9281]22from hurry.workflow.interfaces import IWorkflowInfo
[9686]23from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
[8911]24from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
[9222]25from waeup.kofa.browser.layout import KofaEditFormPage
[9281]26from waeup.kofa.browser.layout import action, jsaction
[9205]27from waeup.kofa.students.browser import (
[9210]28    StudentClearPage, StudentRejectClearancePage,
[9686]29    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
30    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage,
31    CourseTicketDisplayFormPage,
[9281]32    msave, emit_lock_message)
[9686]33from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
[9251]34from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
[8911]35from kofacustom.nigeria.students.browser import (
36    NigeriaOnlinePaymentDisplayFormPage,
[9251]37    NigeriaStudentBaseManageFormPage,
[9380]38    NigeriaStudentClearanceEditFormPage,
[8911]39    NigeriaOnlinePaymentAddFormPage,
[9281]40    NigeriaExportPDFPaymentSlipPage,
[9551]41    NigeriaExportPDFClearanceSlipPage,
[9281]42    )
[8911]43
[9210]44from waeup.uniben.students.interfaces import (
45    ICustomStudentOnlinePayment, ICustomStudentStudyCourse)
46from waeup.uniben.interfaces import MessageFactory as _
[8911]47
[9251]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
[8911]68class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
69    """ Page to view an online payment ticket
70    """
71    grok.context(ICustomStudentOnlinePayment)
[9775]72    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
73        'provider_amt', 'gateway_amt', 'thirdparty_amt')
[8911]74    form_fields[
75        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
76    form_fields[
77        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
78
[9380]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.')
[9395]93        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
94        #    return _('No second sitting result uploaded.')
[9380]95        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
[9848]96            return _('No affidavit of non-membership of secret cults uploaded.')
[9380]97        return False
98
[8911]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)
[9775]109    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
110        'provider_amt', 'gateway_amt', 'thirdparty_amt')
[8911]111    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9205]112    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
113
114
[9551]115class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
116    """Deliver a PDF slip of the context.
117    """
118
119    def render(self):
120        studentview = StudentBasePDFFormPage(self.context.student,
121            self.request, self.omit_fields)
122        students_utils = getUtility(IStudentsUtils)
123        return students_utils.renderPDF(
124            self, 'clearance_slip.pdf',
125            self.context.student, studentview, signatures=self._signatures(),
[9558]126            sigs_in_footer=self._sigsInFooter(), show_scans=False)
[9551]127
[9210]128class StudyCourseCOEditFormPage(KofaEditFormPage):
[9281]129    """ Page to edit the student study course data by clearance officers.
[9210]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__))
[9281]158        return
159
160class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
161    """ Page to edit the student study level data by students.
162
163    """
[9686]164    grok.template('studyleveleditpage')
[9281]165
166    def _registerCourses(self, **data):
167        """ This customized version does allow 'special postgraduate'
168        students to register their courses.
169        """
170        if self.context.student.is_postgrad and \
171            not self.context.student.is_special_postgrad:
172            self.flash(_(
173                "You are a postgraduate student, "
174                "your course list can't bee registered."))
175            self.redirect(self.url(self.context))
176            return
[9831]177        students_utils = getUtility(IStudentsUtils)
178        max_credits = students_utils.maxCredits(self.context)
179        if self.context.total_credits > max_credits:
[9281]180            self.flash(_('Maximum credits of ${a} exceeded.',
[9831]181                mapping = {'a':max_credits}))
[9281]182            return
183        IWorkflowInfo(self.context.student).fireTransition(
184            'register_courses')
185        self.flash(_('Course list has been registered.'))
186        self.redirect(self.url(self.context))
[9686]187        return
188
189class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
190    """ Page to display student study levels
191    """
192    grok.template('studylevelpage')
193
194class CustomExportPDFCourseRegistrationSlipPage(
195    ExportPDFCourseRegistrationSlipPage):
196    """Deliver a PDF slip of the context.
197    """
198
199    def render(self):
200        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9848]201        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
202        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
203        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
204        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
205        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
206        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
207        Mand = translate('Requ.', 'waeup.kofa', target_language=portal_language)
[9686]208        studentview = StudentBasePDFFormPage(self.context.student,
209            self.request, self.omit_fields)
210        students_utils = getUtility(IStudentsUtils)
211        tabledata = sorted(self.context.values(),
212            key=lambda value: str(value.semester) + value.code)
213        return students_utils.renderPDF(
214            self, 'course_registration_slip.pdf',
215            self.context.student, studentview,
216            tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5),
217                         (Title,'title', 5),
218                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
219                         (Cred, 'credits', 1.5),
220                         (Mand, 'mandatory', 1.5),
[9848]221                         ],
222            tabledata=tabledata)
223
224class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
225    """Deliver a PDF slip of the context.
226    """
227
228    grok.name('course_result_slip.pdf')
229
230    @property
231    def label(self):
232        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
233        lang = self.request.cookies.get('kofa.language', portal_language)
234        level_title = translate(self.context.level_title, 'waeup.kofa',
235            target_language=lang)
236        return translate(_('Course Result Slip'),
237            'waeup.uniben', target_language=portal_language) \
238            + ' %s' % level_title
239
240    def render(self):
241        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
242        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
243        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
244        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
245        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
246        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
247        Cred = translate('Cred.', 'waeup.kofa', target_language=portal_language)
248        Mand = translate('Requ.', 'waeup.kofa', target_language=portal_language)
249        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
250        studentview = StudentBasePDFFormPage(self.context.student,
251            self.request, self.omit_fields)
252        students_utils = getUtility(IStudentsUtils)
253        tabledata = sorted(self.context.values(),
254            key=lambda value: str(value.semester) + value.code)
255        return students_utils.renderPDF(
256            self, 'course_registration_slip.pdf',
257            self.context.student, studentview,
258            tableheader=[(Sem,'semester', 1.5),(Code,'code', 2.5),
259                         (Title,'title', 5),
260                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
261                         (Cred, 'credits', 1.5),
262                         (Mand, 'mandatory', 1.5),
[9686]263                         (Grade, 'grade', 1.5),
264                         #('Auto', 'automatic', 1.5)
265                         ],
266            tabledata=tabledata)
267
268class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
269    """ Page to display course tickets
270    """
271    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.