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

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

gpa is no longer a field attribute of CustomStudentStudyLevel?.

  • Property svn:keywords set to Id
File size: 10.9 KB
RevLine 
[8911]1## $Id: browser.py 10284 2013-06-06 10:41:40Z 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,
[10025]30    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
[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
48class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
49    """ Page to view an online payment ticket
50    """
51    grok.context(ICustomStudentOnlinePayment)
[9775]52    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9993]53        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]54    form_fields[
55        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
56    form_fields[
57        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
58
[9380]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.')
[9395]73        #if not store.getFileByContext(self.context, attr=u'scd_sit_scan.jpg'):
74        #    return _('No second sitting result uploaded.')
[9380]75        if not store.getFileByContext(self.context, attr=u'secr_cults.jpg'):
[9848]76            return _('No affidavit of non-membership of secret cults uploaded.')
[9380]77        return False
78
[8911]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)
[9775]89    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
[9993]90        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item')
[8911]91    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
[9205]92    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
93
94
[9551]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(),
[10271]106            sigs_in_footer=self._sigsInFooter(), show_scans=False,
107            omit_fields=self.omit_fields)
[9551]108
[9210]109class StudyCourseCOEditFormPage(KofaEditFormPage):
[9281]110    """ Page to edit the student study course data by clearance officers.
[9210]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__))
[9281]139        return
140
141class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
142    """ Page to edit the student study level data by students.
143
144    """
[9686]145    grok.template('studyleveleditpage')
[9281]146
[9686]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
[9921]157    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
[10284]158        'level_verdict')
[9921]159
[9686]160    def render(self):
161        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]162        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
163        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
164        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
165        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
166        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
[9686]167        studentview = StudentBasePDFFormPage(self.context.student,
168            self.request, self.omit_fields)
169        students_utils = getUtility(IStudentsUtils)
[9908]170        tabledata_1 = sorted(
171            [value for value in self.context.values() if value.semester == 1],
[9686]172            key=lambda value: str(value.semester) + value.code)
[9908]173        tabledata_2 = sorted(
174            [value for value in self.context.values() if value.semester == 2],
175            key=lambda value: str(value.semester) + value.code)
[9959]176        tabledata_3 = sorted(
177            [value for value in self.context.values() if value.semester == 3],
178            key=lambda value: str(value.semester) + value.code)
[9908]179        tableheader = [(Code,'code', 2.5),
180                         (Title,'title', 5),
181                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
182                         (Cred, 'credits', 1.5),
183                         ]
[9686]184        return students_utils.renderPDF(
185            self, 'course_registration_slip.pdf',
186            self.context.student, studentview,
[9908]187            tableheader_1=tableheader,
188            tabledata_1=tabledata_1,
189            tableheader_2=tableheader,
[9959]190            tabledata_2=tabledata_2,
191            tableheader_3=tableheader,
[10271]192            tabledata_3=tabledata_3,
193            omit_fields=self.omit_fields
[9908]194            )
[9848]195
196class UnibenExportPDFCourseResultSlipPage(ExportPDFCourseRegistrationSlipPage):
197    """Deliver a PDF slip of the context.
198    """
199
200    grok.name('course_result_slip.pdf')
201
202    @property
203    def label(self):
204        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
205        lang = self.request.cookies.get('kofa.language', portal_language)
206        level_title = translate(self.context.level_title, 'waeup.kofa',
207            target_language=lang)
208        return translate(_('Course Result Slip'),
209            'waeup.uniben', target_language=portal_language) \
210            + ' %s' % level_title
211
212    def render(self):
213        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
[9909]214        Code = translate('Code', 'waeup.kofa', target_language=portal_language)
215        Title = translate('Title', 'waeup.kofa', target_language=portal_language)
216        Dept = translate('Dept.', 'waeup.kofa', target_language=portal_language)
217        Faculty = translate('Faculty', 'waeup.kofa', target_language=portal_language)
218        Cred = translate(_('Credits'), 'waeup.uniben', target_language=portal_language)
219        Grade = translate('Grade', 'waeup.kofa', target_language=portal_language)
[9848]220        studentview = StudentBasePDFFormPage(self.context.student,
221            self.request, self.omit_fields)
222        students_utils = getUtility(IStudentsUtils)
[9908]223        tabledata_1 = sorted(
224            [value for value in self.context.values() if value.semester == 1],
[9848]225            key=lambda value: str(value.semester) + value.code)
[9908]226        tabledata_2 = sorted(
227            [value for value in self.context.values() if value.semester == 2],
228            key=lambda value: str(value.semester) + value.code)
[9958]229        tabledata_3 = sorted(
230            [value for value in self.context.values() if value.semester == 3],
231            key=lambda value: str(value.semester) + value.code)
[9908]232        tableheader = [(Code,'code', 2.5),
[9848]233                         (Title,'title', 5),
234                         (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
235                         (Cred, 'credits', 1.5),
[9686]236                         (Grade, 'grade', 1.5),
[9908]237                         ]
238        return students_utils.renderPDF(
239            self, 'course_registration_slip.pdf',
240            self.context.student, studentview,
241            tableheader_1=tableheader,
242            tabledata_1=tabledata_1,
243            tableheader_2=tableheader,
[9958]244            tabledata_2=tabledata_2,
245            tableheader_3=tableheader,
[10271]246            tabledata_3=tabledata_3,
247            omit_fields=self.omit_fields
[9908]248            )
[9686]249
250class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
251    """ Page to display course tickets
252    """
253    form_fields = grok.AutoFields(ICourseTicket).omit('score')
Note: See TracBrowser for help on using the repository browser.