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

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

... in all slips

  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
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
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,
46    ICustomStudentStudyLevel)
47from waeup.uniben.interfaces import MessageFactory as _
48
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
69class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
70    """ Page to view an online payment ticket
71    """
72    grok.context(ICustomStudentOnlinePayment)
73    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
74        'provider_amt', 'gateway_amt', 'thirdparty_amt')
75    form_fields[
76        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
77    form_fields[
78        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
79
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.')
94        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
95        #    return _('No second sitting result uploaded.')
96        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
97            return _('No affidavit of non-membership of secret cults uploaded.')
98        return False
99
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)
110    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
111        'provider_amt', 'gateway_amt', 'thirdparty_amt')
112    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
113    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
114
115
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(),
127            sigs_in_footer=self._sigsInFooter(), show_scans=False)
128
129class StudyCourseCOEditFormPage(KofaEditFormPage):
130    """ Page to edit the student study course data by clearance officers.
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__))
159        return
160
161class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
162    """ Page to edit the student study level data by students.
163
164    """
165    grok.template('studyleveleditpage')
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
178        students_utils = getUtility(IStudentsUtils)
179        max_credits = students_utils.maxCredits(self.context)
180        if self.context.total_credits > max_credits:
181            self.flash(_('Maximum credits of ${a} exceeded.',
182                mapping = {'a':max_credits}))
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))
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
200    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
201        'level_verdict', 'gpa')
202
203    def render(self):
204        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
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)
212        studentview = StudentBasePDFFormPage(self.context.student,
213            self.request, self.omit_fields)
214        students_utils = getUtility(IStudentsUtils)
215        tabledata_1 = sorted(
216            [value for value in self.context.values() if value.semester == 1],
217            key=lambda value: str(value.semester) + value.code)
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)
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)
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                         ]
229        return students_utils.renderPDF(
230            self, 'course_registration_slip.pdf',
231            self.context.student, studentview,
232            tableheader_1=tableheader,
233            tabledata_1=tabledata_1,
234            tableheader_2=tableheader,
235            tabledata_2=tabledata_2,
236            tableheader_3=tableheader,
237            tabledata_3=tabledata_3
238            )
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
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)
266        studentview = StudentBasePDFFormPage(self.context.student,
267            self.request, self.omit_fields)
268        students_utils = getUtility(IStudentsUtils)
269        tabledata_1 = sorted(
270            [value for value in self.context.values() if value.semester == 1],
271            key=lambda value: str(value.semester) + value.code)
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)
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)
278        tableheader = [(Code,'code', 2.5),
279                         (Title,'title', 5),
280                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
281                         (Cred, 'credits', 1.5),
282                         (Grade, 'grade', 1.5),
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,
290            tabledata_2=tabledata_2,
291            tableheader_3=tableheader,
292            tabledata_3=tabledata_3
293            )
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.