source: main/kofacustom.edocons/trunk/src/kofacustom/edocons/students/browser.py @ 17397

Last change on this file since 17397 was 17393, checked in by Henrik Bettermann, 19 months ago

Add carryover_score (RST) to course registration slip.

  • Property svn:keywords set to Id
File size: 9.4 KB
RevLine 
[16639]1## $Id: browser.py 17393 2023-04-27 06:31:51Z henrik $
[15614]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
[16695]19import os
[15614]20from zope.i18n import translate
21from zope.schema.interfaces import ConstraintNotSatisfied
22from zope.component import getUtility
[16715]23from zope.security import checkPermission
[15614]24from hurry.workflow.interfaces import IWorkflowInfo
25from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
26from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
27from waeup.kofa.browser.layout import KofaEditFormPage
28from waeup.kofa.browser.layout import action, jsaction
29from waeup.kofa.students.browser import (
30    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
31    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
[17345]32    CourseTicketDisplayFormPage,
33    CourseTicketManageFormPage,
34    StudyLevelDisplayFormPage,
35    StudentTriggerTransitionFormPage,
[16715]36    ExportPDFAdmissionSlip, StartClearancePage, PaymentsManageFormPage,
[16796]37    BalancePaymentAddFormPage, msave, emit_lock_message)
[15614]38from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
39from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
40from kofacustom.nigeria.students.browser import (
41    NigeriaOnlinePaymentDisplayFormPage,
42    NigeriaStudentBaseManageFormPage,
43    NigeriaStudentClearanceEditFormPage,
44    NigeriaOnlinePaymentAddFormPage,
45    NigeriaExportPDFPaymentSlip,
46    NigeriaExportPDFClearanceSlip,
[16712]47    NigeriaExportPDFPaymentSlip,
[16846]48    NigeriaBedTicketAddPage,
[17393]49    NigeriaExportPDFCourseRegistrationSlip,
[15614]50    )
51
[16615]52from kofacustom.edocons.students.interfaces import (
[15614]53    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
[17345]54    ICustomStudentStudyLevel, ICustomCourseTicket)
[16615]55from kofacustom.edocons.interfaces import MessageFactory as _
[15614]56
[17345]57def translated_values(view):
58    """Translate course ticket attribute values to be displayed on
59    studylevel pages.
60    """
61    lang = view.request.cookies.get('kofa.language')
62    for value in view.context.values():
63        # We have to unghostify (according to Tres Seaver) the __dict__
64        # by activating the object, otherwise value_dict will be empty
65        # when calling the first time.
66        value._p_activate()
67        value_dict = dict([i for i in value.__dict__.items()])
68        value_dict['url'] = view.url(value)
69        value_dict['removable_by_student'] = value.removable_by_student
70        value_dict['mandatory'] = translate(str(value.mandatory), 'zope',
71            target_language=lang)
72        value_dict['carry_over'] = translate(str(value.carry_over), 'zope',
73            target_language=lang)
74        value_dict['outstanding'] = translate(str(value.outstanding), 'zope',
75            target_language=lang)
76        value_dict['automatic'] = translate(str(value.automatic), 'zope',
77            target_language=lang)
78        value_dict['grade'] = value.grade
79        value_dict['weight'] = value.weight
80        value_dict['course_category'] = value.course_category
81        value_dict['total_score'] = value.total_score
82        semester_dict = getUtility(IKofaUtils).SEMESTER_DICT
83        value_dict['semester'] = semester_dict[
84            value.semester].replace('mester', 'm.')
85        # ECNS specific
86        value_dict['carryover_score'] = value.carryover_score
87        yield value_dict
88
[16699]89class CustomStartClearancePage(StartClearancePage):
90    with_ac = False
91
[16695]92class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
93    """Deliver a PDF Admission slip.
94    """
95
96    omit_fields = ('date_of_birth', 'current_level', 'current_mode',
97                   'certificate', 'faculty')
98    #form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number')
99
100    post_text = '''
[16791]101This admission will be confirmed upon payment of school fees.
[16695]102
[17379]103Note: All admitted students are to pay their school fees on or before 8th of May 2023.
[16791]104
[17028]105Also, hostel accommodation is available on first come first serve basis.
[16791]106
[16697]107Please visit the College Registry (Student Affairs Division) at:
[16695]108
[16696]109Edo State College of Nursing Sciences
[16697]110Godwin Abbey Way (Formerly Limit Road) off Sapele Road, Benin City
[16696]111or call 08104797237 for enquiries.
[16695]112
113Congratulations!
114'''
115
116    @property
117    def label(self):
118        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
119        return translate(_('Admission Letter of'),
120            'waeup.kofa', target_language=portal_language) \
121            + ' %s' % self.context.display_fullname
122
123    def render(self):
124        students_utils = getUtility(IStudentsUtils)
125        letterhead_path = os.path.join(
126            os.path.dirname(__file__), 'static', 'letterhead_admission.jpg')
127        if not os.path.exists(letterhead_path):
128            letterhead_path = None
129        return students_utils.renderPDFAdmissionLetter(self,
130            self.context.student, omit_fields=self.omit_fields,
131            letterhead_path=letterhead_path, post_text=self.post_text)
132
[16712]133
134class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
135    """Deliver a PDF slip of the context.
136    """
137    omit_fields = ('password', 'suspended', 'suspended_comment', 'phone',
138        'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
139        'flash_notice', 'certificate', 'faculty', 'parents_email')
140
[16715]141class CustomPaymentsManageFormPage(PaymentsManageFormPage):
142    """ Page to manage the student payments. This manage form page is for
143    both students and students officers. EDOCONS does not allow students
144    to remove any payment ticket.
145    """
146    @property
147    def manage_payments_allowed(self):
148        return checkPermission('waeup.manageStudent', self.context)
149
[17163]150class CustomBalancePaymentAddFormPage(BalancePaymentAddFormPage):
[17388]151    grok.require('waeup.manageStudent')
[16796]152
[16846]153
154class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
[17345]155    with_ac = False
156
157class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
158    """ Page to display student study levels
159    """
160    @property
161    def translated_values(self):
162        return translated_values(self)
163
[17393]164class CustomExportPDFCourseRegistrationSlip(NigeriaExportPDFCourseRegistrationSlip):
165    """Deliver a PDF slip of the context.
166    """
167    omit_fields = ('password', 'suspended', 'suspended_comment',
168        'phone', 'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
169        'flash_notice')
[17345]170       
[17393]171    def render(self):
172        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
173        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
174        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
175        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
176        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
177        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
178        #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
179        Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
180        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
181        studentview = StudentBasePDFFormPage(self.context.student,
182            self.request, self.omit_fields)
183        students_utils = getUtility(IStudentsUtils)
184
185        tabledata = []
186        tableheader = []
187        for i in range(1,7):
188            tabledata.append(sorted(
189                [value for value in self.context.values() if value.semester == i],
190                key=lambda value: str(value.semester) + value.code))
191            tableheader.append([(Code,'code', 2.5),
192                             (Title,'title', 5),
193                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
194                             (Cred, 'credits', 1.5),
195                             #(Mand, 'mandatory', 1.5),
196                             (Score, 'score', 1.5),
197                             (Grade, 'grade', 1.5),
198                             ('RST', 'carryover_score', 1.5),
199                             #('Auto', 'automatic', 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            signatures=self._signatures(),
208            sigs_in_footer=self._sigsInFooter(),
209            )
210
[17345]211class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
212    """ Page to display course tickets
213    """
214    form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category',
215        'ticket_session')
216
217    @property
218    def form_fields(self):
219        if not self.context.carry_over:
220            return grok.AutoFields(ICustomCourseTicket).omit('carryover_score')
221        return grok.AutoFields(ICustomCourseTicket)
222
223class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
224    """ Page to manage course tickets
225    """
226    form_fields = grok.AutoFields(ICustomCourseTicket)
Note: See TracBrowser for help on using the repository browser.