source: main/kofacustom.unidel/trunk/src/kofacustom/unidel/students/browser.py @ 17114

Last change on this file since 17114 was 17027, checked in by Henrik Bettermann, 2 years ago

Show total score on slip.

  • Property svn:keywords set to Id
File size: 9.5 KB
Line 
1## $Id: browser.py 17027 2022-07-18 08:18:27Z 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 zope.security import checkPermission
23from hurry.workflow.interfaces import IWorkflowInfo
24from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
25from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
26from waeup.kofa.browser.layout import KofaEditFormPage
27from waeup.kofa.browser.layout import action, jsaction
28from waeup.kofa.students.browser import (
29    StudyLevelEditFormPage, StudyLevelDisplayFormPage, StudyLevelManageFormPage,
30    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
31    CourseTicketDisplayFormPage, CourseTicketManageFormPage,
32    StudentTriggerTransitionFormPage,
33    PaymentsManageFormPage, msave, emit_lock_message)
34from waeup.kofa.students.interfaces import IStudentsUtils, ICourseTicket
35from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS
36from kofacustom.nigeria.students.browser import (
37    NigeriaOnlinePaymentDisplayFormPage,
38    NigeriaStudentBaseManageFormPage,
39    NigeriaStudentClearanceEditFormPage,
40    NigeriaOnlinePaymentAddFormPage,
41    NigeriaExportPDFPaymentSlip,
42    NigeriaExportPDFClearanceSlip,
43    NigeriaBedTicketAddPage,
44    NigeriaAccommodationDisplayFormPage,
45    NigeriaAccommodationManageFormPage,
46    )
47from kofacustom.unidel.students.interfaces import (
48    ICustomStudentOnlinePayment,
49    ICustomStudentStudyCourse,
50    ICustomStudentStudyLevel,
51    ICustomUGStudentClearance,
52    ICustomPGStudentClearance,
53    ICustomCourseTicket)
54from kofacustom.unidel.interfaces import MessageFactory as _
55
56class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
57    with_ac = False
58
59class CustomAccommodationDisplayFormPage(NigeriaAccommodationDisplayFormPage):
60    """ Page to view bed tickets.
61    """
62    with_hostel_selection = True
63
64class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
65    """ Page to manage bed tickets.
66    This manage form page is for both students and students officers.
67    """
68    with_hostel_selection = True
69
70class CustomPaymentsManageFormPage(PaymentsManageFormPage):
71    """ Page to manage the student payments. This manage form page is for
72    both students and students officers. UNIDEL does not allow students
73    to remove any payment ticket.
74    """
75    @property
76    def manage_payments_allowed(self):
77        return checkPermission('waeup.manageStudent', self.context)
78
79class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
80    """ View to edit student clearance data by student
81    """
82    @property
83    def form_fields(self):
84        if self.context.is_postgrad:
85            form_fields = grok.AutoFields(ICustomPGStudentClearance).omit(
86            'clearance_locked', 'nysc_location', 'clr_code', 'officer_comment',
87            'physical_clearance_date')
88        else:
89            form_fields = grok.AutoFields(ICustomUGStudentClearance).omit(
90            'clearance_locked', 'clr_code', 'officer_comment',
91            'physical_clearance_date')
92            form_fields['date_of_birth'].for_display = True
93            form_fields['nationality'].for_display = True
94            form_fields['lga'].for_display = True
95        return form_fields
96
97class CustomOnlinePaymentDisplayFormPage(NigeriaOnlinePaymentDisplayFormPage):
98    """ Page to view an online payment ticket
99    """
100    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
101        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item','p_combi',
102        'net_amt')
103    form_fields[
104        'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
105    form_fields[
106        'payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
107
108class CustomExportPDFPaymentSlip(NigeriaExportPDFPaymentSlip):
109    """Deliver a PDF slip of the context.
110    """
111    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
112        'provider_amt', 'gateway_amt', 'thirdparty_amt', 'p_item',
113        'p_split_data','p_combi', 'net_amt')
114    form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
115    form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
116
117class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
118    """ Page to display student study levels
119    """
120    #grok.template('studylevelpage')
121    grok.context(ICustomStudentStudyLevel)
122
123    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
124        'level',)
125    form_fields[
126        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
127
128class CustomStudyLevelManageFormPage(StudyLevelManageFormPage):
129    """ Page to edit the student study level data
130    """
131    grok.context(ICustomStudentStudyLevel)
132
133    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
134        'validation_date', 'validated_by', 'total_credits', 'gpa', 'level',
135        'total_credits_s1', 'total_credits_s2')
136
137class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
138    """Deliver a PDF slip of the context.
139    """
140    grok.context(ICustomStudentStudyLevel)
141    form_fields = grok.AutoFields(ICustomStudentStudyLevel).omit(
142        'level', 'gpa', 'transcript_remark')
143    form_fields[
144        'validation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
145    #prefix = 'form'
146    omit_fields = (
147        'password', 'suspended', 'phone', 'date_of_birth',
148        'adm_code', 'sex', 'suspended_comment', 'current_level',
149        'flash_notice')
150
151    def _signatures(self):
152        return ([_('Academic Adviser\'s Signature')],
153                [_('Faculty Officer\'s Signature')],
154                [_('Student\'s Signature')])
155               
156    def render(self):
157        if not self.context.student.current_mode:
158            self.flash('No certificate assigned.', type="danger")
159            self.redirect(self.url(self.context))
160            return
161        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
162        Sem = translate(_('Term'), target_language=portal_language)
163        Code = translate(_('Code'), target_language=portal_language)
164        Title = translate(_('Title'), target_language=portal_language)
165        Cred = translate(_('Cred.'), target_language=portal_language)
166        CC = translate(_('Cat.'), target_language=portal_language)
167        TotalScore = translate(_('Total Score'), target_language=portal_language)
168        #CA = translate(_('CA'), target_language=portal_language)
169        Grade = translate(_('Grade'), target_language=portal_language)
170        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
171            target_language=portal_language)
172        studentview = StudentBasePDFFormPage(self.context.student,
173            self.request, self.omit_fields)
174        students_utils = getUtility(IStudentsUtils)
175        tabledata = []
176        tableheader = []
177        contenttitle = []
178        for i in range(1,7):
179            tabledata.append(sorted(
180                [value for value in self.context.values()
181                 if value.semester == i and not value.outstanding],
182                 key=lambda value: str(value.semester) + value.code))
183            tableheader.append([(Code,'code', 2.0),
184                               (Title,'title', 7),
185                               (Cred, 'credits', 1.4),
186                               #(CC, 'course_category', 1.2),
187                               (TotalScore, 'total_score', 1.4),
188                               #(CA, 'ca', 1.4),
189                               (Grade, 'grade', 1.4),
190                               (Signature, 'dummy', 3),
191                               ])
192        return students_utils.renderPDF(
193            self, 'course_registration_slip.pdf',
194            self.context.student, studentview,
195            tableheader=tableheader,
196            tabledata=tabledata,
197            omit_fields=self.omit_fields,
198            signatures=self._signatures(),
199            sigs_in_footer=self._sigsInFooter(),
200            )
201
202class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
203    """ Page to display course tickets
204    """
205
206    @property
207    def form_fields(self):
208        return grok.AutoFields(ICustomCourseTicket).omit('course_category',
209            'ticket_session')
210
211class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
212    """ Page to manage course tickets
213    """
214   
215    form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category')
216    form_fields['title'].for_display = True
217    form_fields['fcode'].for_display = True
218    form_fields['dcode'].for_display = True
219    form_fields['semester'].for_display = True
220    form_fields['passmark'].for_display = True
221    form_fields['credits'].for_display = True
222    form_fields['mandatory'].for_display = False
223    form_fields['automatic'].for_display = True
224    form_fields['carry_over'].for_display = True
225    form_fields['ticket_session'].for_display = True
Note: See TracBrowser for help on using the repository browser.