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

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

Change date.

  • Property svn:keywords set to Id
File size: 7.0 KB
Line 
1## $Id: browser.py 17379 2023-04-14 11:57:48Z 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
19import os
20from zope.i18n import translate
21from zope.schema.interfaces import ConstraintNotSatisfied
22from zope.component import getUtility
23from zope.security import checkPermission
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,
32    CourseTicketDisplayFormPage,
33    CourseTicketManageFormPage,
34    StudyLevelDisplayFormPage,
35    StudentTriggerTransitionFormPage,
36    ExportPDFAdmissionSlip, StartClearancePage, PaymentsManageFormPage,
37    BalancePaymentAddFormPage, msave, emit_lock_message)
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,
47    NigeriaExportPDFPaymentSlip,
48    NigeriaBedTicketAddPage,
49    )
50
51from kofacustom.edocons.students.interfaces import (
52    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
53    ICustomStudentStudyLevel, ICustomCourseTicket)
54from kofacustom.edocons.interfaces import MessageFactory as _
55
56def translated_values(view):
57    """Translate course ticket attribute values to be displayed on
58    studylevel pages.
59    """
60    lang = view.request.cookies.get('kofa.language')
61    for value in view.context.values():
62        # We have to unghostify (according to Tres Seaver) the __dict__
63        # by activating the object, otherwise value_dict will be empty
64        # when calling the first time.
65        value._p_activate()
66        value_dict = dict([i for i in value.__dict__.items()])
67        value_dict['url'] = view.url(value)
68        value_dict['removable_by_student'] = value.removable_by_student
69        value_dict['mandatory'] = translate(str(value.mandatory), 'zope',
70            target_language=lang)
71        value_dict['carry_over'] = translate(str(value.carry_over), 'zope',
72            target_language=lang)
73        value_dict['outstanding'] = translate(str(value.outstanding), 'zope',
74            target_language=lang)
75        value_dict['automatic'] = translate(str(value.automatic), 'zope',
76            target_language=lang)
77        value_dict['grade'] = value.grade
78        value_dict['weight'] = value.weight
79        value_dict['course_category'] = value.course_category
80        value_dict['total_score'] = value.total_score
81        semester_dict = getUtility(IKofaUtils).SEMESTER_DICT
82        value_dict['semester'] = semester_dict[
83            value.semester].replace('mester', 'm.')
84        # ECNS specific
85        value_dict['carryover_score'] = value.carryover_score
86        yield value_dict
87
88class CustomStartClearancePage(StartClearancePage):
89    with_ac = False
90
91class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
92    """Deliver a PDF Admission slip.
93    """
94
95    omit_fields = ('date_of_birth', 'current_level', 'current_mode',
96                   'certificate', 'faculty')
97    #form_fields = grok.AutoFields(IStudentBase).select('student_id', 'reg_number')
98
99    post_text = '''
100This admission will be confirmed upon payment of school fees.
101
102Note: All admitted students are to pay their school fees on or before 8th of May 2023.
103
104Also, hostel accommodation is available on first come first serve basis.
105
106Please visit the College Registry (Student Affairs Division) at:
107
108Edo State College of Nursing Sciences
109Godwin Abbey Way (Formerly Limit Road) off Sapele Road, Benin City
110or call 08104797237 for enquiries.
111
112Congratulations!
113'''
114
115    @property
116    def label(self):
117        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
118        return translate(_('Admission Letter of'),
119            'waeup.kofa', target_language=portal_language) \
120            + ' %s' % self.context.display_fullname
121
122    def render(self):
123        students_utils = getUtility(IStudentsUtils)
124        letterhead_path = os.path.join(
125            os.path.dirname(__file__), 'static', 'letterhead_admission.jpg')
126        if not os.path.exists(letterhead_path):
127            letterhead_path = None
128        return students_utils.renderPDFAdmissionLetter(self,
129            self.context.student, omit_fields=self.omit_fields,
130            letterhead_path=letterhead_path, post_text=self.post_text)
131
132
133class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
134    """Deliver a PDF slip of the context.
135    """
136    omit_fields = ('password', 'suspended', 'suspended_comment', 'phone',
137        'adm_code', 'sex', 'email', 'date_of_birth', 'current_level',
138        'flash_notice', 'certificate', 'faculty', 'parents_email')
139
140class CustomPaymentsManageFormPage(PaymentsManageFormPage):
141    """ Page to manage the student payments. This manage form page is for
142    both students and students officers. EDOCONS does not allow students
143    to remove any payment ticket.
144    """
145    @property
146    def manage_payments_allowed(self):
147        return checkPermission('waeup.manageStudent', self.context)
148
149class CustomBalancePaymentAddFormPage(BalancePaymentAddFormPage):
150    grok.require('waeup.payStudent')
151
152
153class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
154    with_ac = False
155
156class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
157    """ Page to display student study levels
158    """
159    @property
160    def translated_values(self):
161        return translated_values(self)
162
163       
164class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
165    """ Page to display course tickets
166    """
167    form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category',
168        'ticket_session')
169
170    @property
171    def form_fields(self):
172        if not self.context.carry_over:
173            return grok.AutoFields(ICustomCourseTicket).omit('carryover_score')
174        return grok.AutoFields(ICustomCourseTicket)
175
176class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
177    """ Page to manage course tickets
178    """
179    form_fields = grok.AutoFields(ICustomCourseTicket)
Note: See TracBrowser for help on using the repository browser.