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

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

pyflakes

  • Property svn:keywords set to Id
File size: 12.6 KB
RevLine 
[8911]1## $Id: browser.py 9971 2013-02-19 21:04:21Z 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 (
[9686]28    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
29    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage,
30    CourseTicketDisplayFormPage,
[9281]31    msave, emit_lock_message)
[9686]32from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
[9251]33from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
[8911]34from kofacustom.nigeria.students.browser import (
35    NigeriaOnlinePaymentDisplayFormPage,
[9251]36    NigeriaStudentBaseManageFormPage,
[9380]37    NigeriaStudentClearanceEditFormPage,
[8911]38    NigeriaOnlinePaymentAddFormPage,
[9281]39    NigeriaExportPDFPaymentSlipPage,
[9551]40    NigeriaExportPDFClearanceSlipPage,
[9281]41    )
[8911]42
[9210]43from waeup.uniben.students.interfaces import (
[9921]44    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
45    ICustomStudentStudyLevel)
[9210]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
[9921]199    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
200        'level_verdict', 'gpa')
201
[9686]202    def render(self):
203        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]204        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
205        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
206        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
207        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
208        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
[9686]209        studentview = StudentBasePDFFormPage(self.context.student,
210            self.request, self.omit_fields)
211        students_utils = getUtility(IStudentsUtils)
[9908]212        tabledata_1 = sorted(
213            [value for value in self.context.values() if value.semester == 1],
[9686]214            key=lambda value: str(value.semester) + value.code)
[9908]215        tabledata_2 = sorted(
216            [value for value in self.context.values() if value.semester == 2],
217            key=lambda value: str(value.semester) + value.code)
[9959]218        tabledata_3 = sorted(
219            [value for value in self.context.values() if value.semester == 3],
220            key=lambda value: str(value.semester) + value.code)
[9908]221        tableheader = [(Code,'code', 2.5),
222                         (Title,'title', 5),
223                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
224                         (Cred, 'credits', 1.5),
225                         ]
[9686]226        return students_utils.renderPDF(
227            self, 'course_registration_slip.pdf',
228            self.context.student, studentview,
[9908]229            tableheader_1=tableheader,
230            tabledata_1=tabledata_1,
231            tableheader_2=tableheader,
[9959]232            tabledata_2=tabledata_2,
233            tableheader_3=tableheader,
234            tabledata_3=tabledata_3
[9908]235            )
[9848]236
237class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
238    """Deliver a PDF slip of the context.
239    """
240
241    grok.name('course_result_slip.pdf')
242
243    @property
244    def label(self):
245        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
246        lang = self.request.cookies.get('kofa.language', portal_language)
247        level_title = translate(self.context.level_title, 'waeup.kofa',
248            target_language=lang)
249        return translate(_('Course Result Slip'),
250            'waeup.uniben', target_language=portal_language) \
251            + ' %s' % level_title
252
253    def render(self):
254        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]255        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
256        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
257        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
258        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
259        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
260        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
[9848]261        studentview = StudentBasePDFFormPage(self.context.student,
262            self.request, self.omit_fields)
263        students_utils = getUtility(IStudentsUtils)
[9908]264        tabledata_1 = sorted(
265            [value for value in self.context.values() if value.semester == 1],
[9848]266            key=lambda value: str(value.semester) + value.code)
[9908]267        tabledata_2 = sorted(
268            [value for value in self.context.values() if value.semester == 2],
269            key=lambda value: str(value.semester) + value.code)
[9958]270        tabledata_3 = sorted(
271            [value for value in self.context.values() if value.semester == 3],
272            key=lambda value: str(value.semester) + value.code)
[9908]273        tableheader = [(Code,'code', 2.5),
[9848]274                         (Title,'title', 5),
275                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
276                         (Cred, 'credits', 1.5),
[9686]277                         (Grade, 'grade', 1.5),
[9908]278                         ]
279        return students_utils.renderPDF(
280            self, 'course_registration_slip.pdf',
281            self.context.student, studentview,
282            tableheader_1=tableheader,
283            tabledata_1=tabledata_1,
284            tableheader_2=tableheader,
[9958]285            tabledata_2=tabledata_2,
286            tableheader_3=tableheader,
287            tabledata_3=tabledata_3
[9908]288            )
[9686]289
290class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
291    """ Page to display course tickets
292    """
293    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.