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

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

Add fields and change field names.

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