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

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

... in all slips

  • Property svn:keywords set to Id
File size: 12.9 KB
RevLine 
[8911]1## $Id: browser.py 9959 2013-02-15 13:41:39Z 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 (
[9921]45    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
46    ICustomStudentStudyLevel)
[9210]47from waeup.uniben.interfaces import MessageFactory as _
[8911]48
[9251]49class CustomStudentBaseManageFormPage(NigeriaStudentBaseManageFormPage):
50    """ View to manage student base data
51    """
52    #grok.context(ICustomStudent)
53
54    def getTransitions(self):
55        """Return a list of dicts of allowed transition ids and titles.
56
57        Each list entry provides keys ``name`` and ``title`` for
58        internal name and (human readable) title of a single
59        transition.
60        """
61        allowed_transitions = [t for t in self.wf_info.getManualTransitions()
62            if not t[0].startswith('pay')]
63        if self.context.is_postgrad and not self.context.is_special_postgrad:
64            allowed_transitions = [t for t in allowed_transitions
65                if not t[0] in FORBIDDEN_POSTGRAD_TRANS]
66        return [dict(name='', title=_('No transition'))] +[
67            dict(name=x, title=y) for x, y in allowed_transitions]
68
[8911]69class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
70    """ Page to view an online payment ticket
71    """
72    grok.context(ICustomStudentOnlinePayment)
[9775]73    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
74        'provider_amt', 'gateway_amt', 'thirdparty_amt')
[8911]75    form_fields[
76        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
77    form_fields[
78        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
79
[9380]80class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
81    """ View to edit student clearance data by student
82    """
83
84    def dataNotComplete(self):
85        store = getUtility(IExtFileStore)
86        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
87            return _('No birth certificate uploaded.')
88        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
89            return _('No guarantor/referee letter uploaded.')
90        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
91            return _('No acceptance letter uploaded.')
92        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
93            return _('No first sitting result uploaded.')
[9395]94        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
95        #    return _('No second sitting result uploaded.')
[9380]96        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
[9848]97            return _('No affidavit of non-membership of secret cults uploaded.')
[9380]98        return False
99
[8911]100class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
101    """ Page to add an online payment ticket
102    """
103    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
104        'p_category')
105
106class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
107    """Deliver a PDF slip of the context.
108    """
109    grok.context(ICustomStudentOnlinePayment)
[9775]110    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
111        'provider_amt', 'gateway_amt', 'thirdparty_amt')
[8911]112    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9205]113    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
114
115
[9551]116class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
117    """Deliver a PDF slip of the context.
118    """
119
120    def render(self):
121        studentview = StudentBasePDFFormPage(self.context.student,
122            self.request, self.omit_fields)
123        students_utils = getUtility(IStudentsUtils)
124        return students_utils.renderPDF(
125            self, 'clearance_slip.pdf',
126            self.context.student, studentview, signatures=self._signatures(),
[9558]127            sigs_in_footer=self._sigsInFooter(), show_scans=False)
[9551]128
[9210]129class StudyCourseCOEditFormPage(KofaEditFormPage):
[9281]130    """ Page to edit the student study course data by clearance officers.
[9210]131
132    This form page is available only in Uniben.
133    """
134    grok.context(ICustomStudentStudyCourse)
135    grok.name('edit_level')
136    grok.require('waeup.clearStudent')
137    label = _('Edit current level')
138    pnav = 4
139    form_fields = grok.AutoFields(
140        ICustomStudentStudyCourse).select('current_level')
141
142    def update(self):
143        if not (self.context.is_current and
144            self.context.student.state == REQUESTED):
145            emit_lock_message(self)
146            return
147        super(StudyCourseCOEditFormPage, self).update()
148        return
149
150    @action(_('Save'), style='primary')
151    def save(self, **data):
152        try:
153            msave(self, **data)
154        except ConstraintNotSatisfied:
155            # The selected level might not exist in certificate
156            self.flash(_('Current level not available for certificate.'))
157            return
158        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
[9281]159        return
160
161class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
162    """ Page to edit the student study level data by students.
163
164    """
[9686]165    grok.template('studyleveleditpage')
[9281]166
167    def _registerCourses(self, **data):
168        """ This customized version does allow 'special postgraduate'
169        students to register their courses.
170        """
171        if self.context.student.is_postgrad and \
172            not self.context.student.is_special_postgrad:
173            self.flash(_(
174                "You are a postgraduate student, "
175                "your course list can't bee registered."))
176            self.redirect(self.url(self.context))
177            return
[9831]178        students_utils = getUtility(IStudentsUtils)
179        max_credits = students_utils.maxCredits(self.context)
180        if self.context.total_credits > max_credits:
[9281]181            self.flash(_('Maximum credits of ${a} exceeded.',
[9831]182                mapping = {'a':max_credits}))
[9281]183            return
184        IWorkflowInfo(self.context.student).fireTransition(
185            'register_courses')
186        self.flash(_('Course list has been registered.'))
187        self.redirect(self.url(self.context))
[9686]188        return
189
190class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
191    """ Page to display student study levels
192    """
193    grok.template('studylevelpage')
194
195class CustomExportPDFCourseRegistrationSlipPage(
196    ExportPDFCourseRegistrationSlipPage):
197    """Deliver a PDF slip of the context.
198    """
199
[9921]200    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
201        'level_verdict', 'gpa')
202
[9686]203    def render(self):
204        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]205        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
206        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
207        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
208        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
209        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
210        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
211        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
[9686]212        studentview = StudentBasePDFFormPage(self.context.student,
213            self.request, self.omit_fields)
214        students_utils = getUtility(IStudentsUtils)
[9908]215        tabledata_1 = sorted(
216            [value for value in self.context.values() if value.semester == 1],
[9686]217            key=lambda value: str(value.semester) + value.code)
[9908]218        tabledata_2 = sorted(
219            [value for value in self.context.values() if value.semester == 2],
220            key=lambda value: str(value.semester) + value.code)
[9959]221        tabledata_3 = sorted(
222            [value for value in self.context.values() if value.semester == 3],
223            key=lambda value: str(value.semester) + value.code)
[9908]224        tableheader = [(Code,'code', 2.5),
225                         (Title,'title', 5),
226                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
227                         (Cred, 'credits', 1.5),
228                         ]
[9686]229        return students_utils.renderPDF(
230            self, 'course_registration_slip.pdf',
231            self.context.student, studentview,
[9908]232            tableheader_1=tableheader,
233            tabledata_1=tabledata_1,
234            tableheader_2=tableheader,
[9959]235            tabledata_2=tabledata_2,
236            tableheader_3=tableheader,
237            tabledata_3=tabledata_3
[9908]238            )
[9848]239
240class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
241    """Deliver a PDF slip of the context.
242    """
243
244    grok.name('course_result_slip.pdf')
245
246    @property
247    def label(self):
248        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
249        lang = self.request.cookies.get('kofa.language', portal_language)
250        level_title = translate(self.context.level_title, 'waeup.kofa',
251            target_language=lang)
252        return translate(_('Course Result Slip'),
253            'waeup.uniben', target_language=portal_language) \
254            + ' %s' % level_title
255
256    def render(self):
257        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]258        Sem = translate('Sem.', 'waeup.kofa', target_language=portal_language)
259        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
260        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
261        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
262        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
263        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
264        Score = translate('Score', 'waeup.kofa', target_language=portal_language)
265        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
[9848]266        studentview = StudentBasePDFFormPage(self.context.student,
267            self.request, self.omit_fields)
268        students_utils = getUtility(IStudentsUtils)
[9908]269        tabledata_1 = sorted(
270            [value for value in self.context.values() if value.semester == 1],
[9848]271            key=lambda value: str(value.semester) + value.code)
[9908]272        tabledata_2 = sorted(
273            [value for value in self.context.values() if value.semester == 2],
274            key=lambda value: str(value.semester) + value.code)
[9958]275        tabledata_3 = sorted(
276            [value for value in self.context.values() if value.semester == 3],
277            key=lambda value: str(value.semester) + value.code)
[9908]278        tableheader = [(Code,'code', 2.5),
[9848]279                         (Title,'title', 5),
280                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
281                         (Cred, 'credits', 1.5),
[9686]282                         (Grade, 'grade', 1.5),
[9908]283                         ]
284        return students_utils.renderPDF(
285            self, 'course_registration_slip.pdf',
286            self.context.student, studentview,
287            tableheader_1=tableheader,
288            tabledata_1=tabledata_1,
289            tableheader_2=tableheader,
[9958]290            tabledata_2=tabledata_2,
291            tableheader_3=tableheader,
292            tabledata_3=tabledata_3
[9908]293            )
[9686]294
295class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
296    """ Page to display course tickets
297    """
298    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.