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

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

Adjust customizations to changes made in waeup.kofa.

  • Property svn:keywords set to Id
File size: 12.4 KB
Line 
1## $Id: browser.py 9908 2013-01-23 09:40:02Z 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, IKofaUtils
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, StudyLevelDisplayFormPage,
30    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage,
31    CourseTicketDisplayFormPage,
32    msave, emit_lock_message)
33from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
34from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
35from kofacustom.nigeria.students.browser import (
36    NigeriaOnlinePaymentDisplayFormPage,
37    NigeriaStudentBaseManageFormPage,
38    NigeriaStudentClearanceEditFormPage,
39    NigeriaOnlinePaymentAddFormPage,
40    NigeriaExportPDFPaymentSlipPage,
41    NigeriaExportPDFClearanceSlipPage,
42    )
43
44from waeup.uniben.students.interfaces import (
45    ICustomStudentOnlinePayment, ICustomStudentStudyCourse)
46from waeup.uniben.interfaces import MessageFactory as _
47
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
68class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
69    """ Page to view an online payment ticket
70    """
71    grok.context(ICustomStudentOnlinePayment)
72    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
73        'provider_amt', 'gateway_amt', 'thirdparty_amt')
74    form_fields[
75        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
76    form_fields[
77        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
78
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.')
93        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
94        #    return _('No second sitting result uploaded.')
95        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
96            return _('No affidavit of non-membership of secret cults uploaded.')
97        return False
98
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)
109    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
110        'provider_amt', 'gateway_amt', 'thirdparty_amt')
111    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
112    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
113
114
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(),
126            sigs_in_footer=self._sigsInFooter(), show_scans=False)
127
128class StudyCourseCOEditFormPage(KofaEditFormPage):
129    """ Page to edit the student study course data by clearance officers.
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__))
158        return
159
160class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
161    """ Page to edit the student study level data by students.
162
163    """
164    grok.template('studyleveleditpage')
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
177        students_utils = getUtility(IStudentsUtils)
178        max_credits = students_utils.maxCredits(self.context)
179        if self.context.total_credits > max_credits:
180            self.flash(_('Maximum credits of ${a} exceeded.',
181                mapping = {'a':max_credits}))
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))
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
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        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
208        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
209        studentview = StudentBasePDFFormPage(self.context.student,
210            self.request, self.omit_fields)
211        students_utils = getUtility(IStudentsUtils)
212        tabledata_1 = sorted(
213            [value for value in self.context.values() if value.semester == 1],
214            key=lambda value: str(value.semester) + value.code)
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)
218        tableheader = [(Code,'code', 2.5),
219                         (Title,'title', 5),
220                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
221                         (Cred, 'credits', 1.5),
222                         ]
223        return students_utils.renderPDF(
224            self, 'course_registration_slip.pdf',
225            self.context.student, studentview,
226            tableheader_1=tableheader,
227            tabledata_1=tabledata_1,
228            tableheader_2=tableheader,
229            tabledata_2=tabledata_2
230            )
231
232class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
233    """Deliver a PDF slip of the context.
234    """
235
236    grok.name('course_result_slip.pdf')
237
238    @property
239    def label(self):
240        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
241        lang = self.request.cookies.get('kofa.language', portal_language)
242        level_title = translate(self.context.level_title, 'waeup.kofa',
243            target_language=lang)
244        return translate(_('Course Result Slip'),
245            'waeup.uniben', target_language=portal_language) \
246            + ' %s' % level_title
247
248    def render(self):
249        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
250        Sem = translate(_('Sem.'), 'waeup.kofa', target_language=portal_language)
251        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
252        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
253        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
254        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
255        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
256        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
257        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
258        studentview = StudentBasePDFFormPage(self.context.student,
259            self.request, self.omit_fields)
260        students_utils = getUtility(IStudentsUtils)
261        tabledata_1 = sorted(
262            [value for value in self.context.values() if value.semester == 1],
263            key=lambda value: str(value.semester) + value.code)
264        tabledata_2 = sorted(
265            [value for value in self.context.values() if value.semester == 2],
266            key=lambda value: str(value.semester) + value.code)
267        tableheader = [(Code,'code', 2.5),
268                         (Title,'title', 5),
269                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
270                         (Cred, 'credits', 1.5),
271                         (Grade, 'grade', 1.5),
272                         ]
273        return students_utils.renderPDF(
274            self, 'course_registration_slip.pdf',
275            self.context.student, studentview,
276            tableheader_1=tableheader,
277            tabledata_1=tabledata_1,
278            tableheader_2=tableheader,
279            tabledata_2=tabledata_2
280            )
281
282class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
283    """ Page to display course tickets
284    """
285    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.