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

Last change on this file since 17341 was 17325, checked in by Henrik Bettermann, 22 months ago

Update signatures.

  • Property svn:keywords set to Id
File size: 9.6 KB
Line 
1## $Id: browser.py 17325 2023-01-27 16:30:55Z 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 (
153            [_('Student\'s Signature')],
154            [_('Academic Adviser\'s Signature')],
155            [_('Head of Department\'s Signature')],
156            [_('Dean of Faculty\'s Signature')],
157            )
158
159               
160    def render(self):
161        if not self.context.student.current_mode:
162            self.flash('No certificate assigned.', type="danger")
163            self.redirect(self.url(self.context))
164            return
165        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
166        Sem = translate(_('Term'), target_language=portal_language)
167        Code = translate(_('Code'), target_language=portal_language)
168        Title = translate(_('Title'), target_language=portal_language)
169        Cred = translate(_('Cred.'), target_language=portal_language)
170        CC = translate(_('Cat.'), target_language=portal_language)
171        TotalScore = translate(_('Total Score'), target_language=portal_language)
172        #CA = translate(_('CA'), target_language=portal_language)
173        Grade = translate(_('Grade'), target_language=portal_language)
174        Signature = translate(_('Lecturer\'s Signature'), 'waeup.aaue',
175            target_language=portal_language)
176        studentview = StudentBasePDFFormPage(self.context.student,
177            self.request, self.omit_fields)
178        students_utils = getUtility(IStudentsUtils)
179        tabledata = []
180        tableheader = []
181        contenttitle = []
182        for i in range(1,7):
183            tabledata.append(sorted(
184                [value for value in self.context.values()
185                 if value.semester == i and not value.outstanding],
186                 key=lambda value: str(value.semester) + value.code))
187            tableheader.append([(Code,'code', 2.0),
188                               (Title,'title', 7),
189                               (Cred, 'credits', 1.4),
190                               #(CC, 'course_category', 1.2),
191                               (TotalScore, 'total_score', 1.4),
192                               #(CA, 'ca', 1.4),
193                               (Grade, 'grade', 1.4),
194                               (Signature, 'dummy', 3),
195                               ])
196        return students_utils.renderPDF(
197            self, 'course_registration_slip.pdf',
198            self.context.student, studentview,
199            tableheader=tableheader,
200            tabledata=tabledata,
201            omit_fields=self.omit_fields,
202            signatures=self._signatures(),
203            sigs_in_footer=self._sigsInFooter(),
204            )
205
206class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
207    """ Page to display course tickets
208    """
209
210    @property
211    def form_fields(self):
212        return grok.AutoFields(ICustomCourseTicket).omit('course_category',
213            'ticket_session')
214
215class CustomCourseTicketManageFormPage(CourseTicketManageFormPage):
216    """ Page to manage course tickets
217    """
218   
219    form_fields = grok.AutoFields(ICustomCourseTicket).omit('course_category')
220    form_fields['title'].for_display = True
221    form_fields['fcode'].for_display = True
222    form_fields['dcode'].for_display = True
223    form_fields['semester'].for_display = True
224    form_fields['passmark'].for_display = True
225    form_fields['credits'].for_display = True
226    form_fields['mandatory'].for_display = False
227    form_fields['automatic'].for_display = True
228    form_fields['carry_over'].for_display = True
229    form_fields['ticket_session'].for_display = True
Note: See TracBrowser for help on using the repository browser.