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

Last change on this file since 10520 was 10481, checked in by Henrik Bettermann, 11 years ago

Further adjustments.

  • Property svn:keywords set to Id
File size: 12.0 KB
Line 
1## $Id: browser.py 10481 2013-08-12 09:24:10Z 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    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
29    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlipPage,
30    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
31    msave, emit_lock_message)
32from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
33from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
34from kofacustom.nigeria.students.browser import (
35    NigeriaOnlinePaymentDisplayFormPage,
36    NigeriaStudentBaseManageFormPage,
37    NigeriaStudentClearanceEditFormPage,
38    NigeriaOnlinePaymentAddFormPage,
39    NigeriaExportPDFPaymentSlipPage,
40    NigeriaExportPDFClearanceSlipPage,
41    )
42
43from waeup.uniben.students.interfaces import (
44    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
45    ICustomStudentStudyLevel)
46from waeup.uniben.interfaces import MessageFactory as _
47
48class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
49    """ Page to view an online payment ticket
50    """
51    grok.context(ICustomStudentOnlinePayment)
52    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
53        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
54    form_fields[
55        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
56    form_fields[
57        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
58
59class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
60    """ View to edit student clearance data by student
61    """
62
63    def dataNotComplete(self):
64        store = getUtility(IExtFileStore)
65        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
66            return _('No birth certificate uploaded.')
67        if not store.getFileByContext(self.context, attr=u'ref_let.jpg'):
68            return _('No guarantor/referee letter uploaded.')
69        if not store.getFileByContext(self.context, attr=u'acc_let.jpg'):
70            return _('No acceptance letter uploaded.')
71        if not store.getFileByContext(self.context, attr=u'fst_sit_scan.jpg'):
72            return _('No first sitting result uploaded.')
73        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
74        #    return _('No second sitting result uploaded.')
75        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
76            return _('No affidavit of non-membership of secret cults uploaded.')
77        return False
78
79class CustomOnlinePaymentAddFormPage(NigeriaOnlinePaymentAddFormPage):
80    """ Page to add an online payment ticket
81    """
82    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).select(
83        'p_category')
84
85class CustomExportPDFPaymentSlipPage(NigeriaExportPDFPaymentSlipPage):
86    """Deliver a PDF slip of the context.
87    """
88    grok.context(ICustomStudentOnlinePayment)
89    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
90        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
91    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
92    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
93
94
95class CustomExportPDFClearanceSlipPage(NigeriaExportPDFClearanceSlipPage):
96    """Deliver a PDF slip of the context.
97    """
98
99    def render(self):
100        studentview = StudentBasePDFFormPage(self.context.student,
101            self.request, self.omit_fields)
102        students_utils = getUtility(IStudentsUtils)
103        return students_utils.renderPDF(
104            self, 'clearance_slip.pdf',
105            self.context.student, studentview, signatures=self._signatures(),
106            sigs_in_footer=self._sigsInFooter(), show_scans=False,
107            omit_fields=self.omit_fields)
108
109class StudyCourseCOEditFormPage(KofaEditFormPage):
110    """ Page to edit the student study course data by clearance officers.
111
112    This form page is available only in Uniben.
113    """
114    grok.context(ICustomStudentStudyCourse)
115    grok.name('edit_level')
116    grok.require('waeup.clearStudent')
117    label = _('Edit current level')
118    pnav = 4
119    form_fields = grok.AutoFields(
120        ICustomStudentStudyCourse).select('current_level')
121
122    def update(self):
123        if not (self.context.is_current and
124            self.context.student.state == REQUESTED):
125            emit_lock_message(self)
126            return
127        super(StudyCourseCOEditFormPage, self).update()
128        return
129
130    @action(_('Save'), style='primary')
131    def save(self, **data):
132        try:
133            msave(self, **data)
134        except ConstraintNotSatisfied:
135            # The selected level might not exist in certificate
136            self.flash(_('Current level not available for certificate.'))
137            return
138        #notify(grok.ObjectModifiedEvent(self.context.__parent__))
139        return
140
141class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
142    """ Page to edit the student study level data by students.
143
144    """
145    grok.template('studyleveleditpage')
146
147class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
148    """ Page to display student study levels
149    """
150    grok.template('studylevelpage')
151
152class CustomExportPDFCourseRegistrationSlipPage(
153    ExportPDFCourseRegistrationSlipPage):
154    """Deliver a PDF slip of the context.
155    """
156
157    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
158        'level_verdict', 'gpa')
159
160    @property
161    def tabletitle(self):
162        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
163        tabletitle = []
164        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
165            target_language=portal_language))
166        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
167            target_language=portal_language))
168        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
169            target_language=portal_language))
170        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
171            target_language=portal_language))
172        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
173            target_language=portal_language))
174        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
175            target_language=portal_language))
176        return tabletitle
177
178    def render(self):
179        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
180        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
181        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
182        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
183        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
184        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
185        studentview = StudentBasePDFFormPage(self.context.student,
186            self.request, self.omit_fields)
187        students_utils = getUtility(IStudentsUtils)
188
189        tabledata = []
190        tableheader = []
191        contenttitle = []
192        for i in range(1,7):
193            tabledata.append(sorted(
194                [value for value in self.context.values() if value.semester == i],
195                key=lambda value: str(value.semester) + value.code))
196            tableheader.append([(Code,'code', 2.5),
197                             (Title,'title', 5),
198                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
199                             (Cred, 'credits', 1.5),
200                             ])
201        return students_utils.renderPDF(
202            self, 'course_registration_slip.pdf',
203            self.context.student, studentview,
204            tableheader=tableheader,
205            tabledata=tabledata,
206            omit_fields=self.omit_fields
207            )
208
209class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
210    """Deliver a PDF slip of the context.
211    """
212
213    grok.name('course_result_slip.pdf')
214
215    @property
216    def tabletitle(self):
217        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
218        tabletitle = []
219        tabletitle.append(translate(_('1st Semester Courses'), 'waeup.kofa',
220            target_language=portal_language))
221        tabletitle.append(translate(_('2nd Semester Courses'), 'waeup.kofa',
222            target_language=portal_language))
223        tabletitle.append(translate(_('Level Courses'), 'waeup.kofa',
224            target_language=portal_language))
225        tabletitle.append(translate(_('1st Trimester Courses'), 'waeup.kofa',
226            target_language=portal_language))
227        tabletitle.append(translate(_('2nd Trimester Courses'), 'waeup.kofa',
228            target_language=portal_language))
229        tabletitle.append(translate(_('3rd Trimester Courses'), 'waeup.kofa',
230            target_language=portal_language))
231        return tabletitle
232
233    @property
234    def label(self):
235        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
236        lang = self.request.cookies.get('kofa.language', portal_language)
237        level_title = translate(self.context.level_title, 'waeup.kofa',
238            target_language=lang)
239        return translate(_('Course Result Slip'),
240            'waeup.uniben', target_language=portal_language) \
241            + ' %s' % level_title
242
243    def render(self):
244        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
245        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
246        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
247        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
248        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
249        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
250        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
251        studentview = StudentBasePDFFormPage(self.context.student,
252            self.request, self.omit_fields)
253        students_utils = getUtility(IStudentsUtils)
254
255        tabledata = []
256        tableheader = []
257        contenttitle = []
258        for i in range(1,7):
259            tabledata.append(sorted(
260                [value for value in self.context.values() if value.semester == i],
261                key=lambda value: str(value.semester) + value.code))
262            tableheader.append([(Code,'code', 2.5),
263                             (Title,'title', 5),
264                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
265                             (Cred, 'credits', 1.5),
266                             (Grade, 'grade', 1.5),
267                             ])
268        return students_utils.renderPDF(
269            self, 'course_registration_slip.pdf',
270            self.context.student, studentview,
271            tableheader=tableheader,
272            tabledata=tabledata,
273            omit_fields=self.omit_fields
274            )
275
276class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
277    """ Page to display course tickets
278    """
279    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.