source: main/kofacustom.dspg/trunk/src/kofacustom/dspg/students/browser.py @ 16013

Last change on this file since 16013 was 15774, checked in by Henrik Bettermann, 5 years ago

Disable bed selection.

  • Property svn:keywords set to Id
File size: 12.9 KB
Line 
1## $Id: browser.py 15774 2019-11-07 18:52:16Z 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 hurry.workflow.interfaces import IWorkflowInfo
23from waeup.kofa.interfaces import REQUESTED, IExtFileStore, IKofaUtils
24from waeup.kofa.widgets.datewidget import FriendlyDatetimeDisplayWidget
25from waeup.kofa.browser.layout import (
26    KofaEditFormPage, UtilityView, action, jsaction)
27from waeup.kofa.students.browser import (
28    StudyLevelEditFormPage, StudyLevelDisplayFormPage,
29    StudentBasePDFFormPage, ExportPDFCourseRegistrationSlip,
30    CourseTicketDisplayFormPage, StudentTriggerTransitionFormPage,
31    ExportPDFTranscriptSlip, BedTicketAddPage, ExportPDFAdmissionSlip,
32    msave, emit_lock_message)
33from waeup.kofa.students.interfaces import (
34    IStudentsUtils, ICourseTicket, IStudent)
35from waeup.kofa.students.workflow import FORBIDDEN_POSTGRAD_TRANS, PAID
36from kofacustom.nigeria.students.browser import (
37    NigeriaOnlinePaymentDisplayFormPage,
38    NigeriaStudentBaseManageFormPage,
39    NigeriaStudentClearanceEditFormPage,
40    NigeriaOnlinePaymentAddFormPage,
41    NigeriaExportPDFPaymentSlip,
42    NigeriaExportPDFClearanceSlip,
43    NigeriaAccommodationManageFormPage,
44    NigeriaBedTicketAddPage,
45    )
46from kofacustom.dspg.students.interfaces import (
47    ICustomStudentOnlinePayment, ICustomStudentStudyCourse,
48    ICustomStudentStudyLevel, ICustomStudent)
49from kofacustom.dspg.interfaces import MessageFactory as _
50
51class CustomBedTicketAddPage(NigeriaBedTicketAddPage):
52    with_ac = False
53
54class CustomStudentClearanceEditFormPage(NigeriaStudentClearanceEditFormPage):
55    """ View to edit student clearance data by student
56    """
57
58    def dataNotComplete(self):
59        store = getUtility(IExtFileStore)
60        if not store.getFileByContext(self.context, attr=u'birth_certificate.jpg'):
61            return _('No birth certificate uploaded.')
62        if not store.getFileByContext(self.context, attr=u'lga_ident.jpg'):
63            return _('No LGA identification letter uploaded.')
64        if not store.getFileByContext(self.context, attr=u'o_level_result.jpg'):
65            return _('No O Level result uploaded.')
66        cm = getattr(self.context,'current_mode', None)
67        if cm and cm.startswith('nd'):
68            if not store.getFileByContext(self.context, attr=u'jamb_result.jpg'):
69                return _('No JAMB result uploaded.')
70        elif cm and cm.startswith('hnd'):
71            if not store.getFileByContext(self.context, attr=u'nd_result.jpg'):
72                return _('No ND result uploaded.')
73            if not store.getFileByContext(self.context, attr=u'it_letter.jpg'):
74                return _('No IT letter uploaded.')
75        return False
76
77class CustomStudyLevelDisplayFormPage(StudyLevelDisplayFormPage):
78    """ Page to display student study levels
79    """
80    grok.template('studylevelpage')
81
82class CustomStudyLevelEditFormPage(StudyLevelEditFormPage):
83    """ Page to edit the student study level data by students.
84
85    """
86    grok.template('studyleveleditpage')
87
88class CustomCourseTicketDisplayFormPage(CourseTicketDisplayFormPage):
89    """ Page to display course tickets
90    """
91    form_fields = grok.AutoFields(ICourseTicket).omit('score')
92
93class CustomExportPDFCourseRegistrationSlip(ExportPDFCourseRegistrationSlip):
94    """Deliver a PDF slip of the context.
95    """
96
97    def render(self):
98        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
99        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
100        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
101        Dept = translate(_('Dept.'), 'waeup.kofa', target_language=portal_language)
102        Faculty = translate(_('Faculty'), 'waeup.kofa', target_language=portal_language)
103        Cred = translate(_('Cred.'), 'waeup.kofa', target_language=portal_language)
104        #Mand = translate(_('Requ.'), 'waeup.kofa', target_language=portal_language)
105        #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
106        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
107        studentview = StudentBasePDFFormPage(self.context.student,
108            self.request, self.omit_fields)
109        students_utils = getUtility(IStudentsUtils)
110
111        tabledata = []
112        tableheader = []
113        for i in range(1,7):
114            tabledata.append(sorted(
115                [value for value in self.context.values() if value.semester == i],
116                key=lambda value: str(value.semester) + value.code))
117            tableheader.append([(Code,'code', 2.5),
118                             (Title,'title', 5),
119                             (Dept,'dcode', 1.5), (Faculty,'fcode', 1.5),
120                             (Cred, 'credits', 1.5),
121                             #(Mand, 'mandatory', 1.5),
122                             #(Score, 'score', 1.5),
123                             (Grade, 'grade', 1.5),
124                             #('Auto', 'automatic', 1.5)
125                             ])
126        return students_utils.renderPDF(
127            self, 'course_registration_slip.pdf',
128            self.context.student, studentview,
129            tableheader=tableheader,
130            tabledata=tabledata,
131            omit_fields=self.omit_fields
132            )
133
134
135class CustomExportPDFTranscriptSlip(ExportPDFTranscriptSlip):
136    """Deliver a PDF slip of the context.
137    """
138
139    def render(self):
140        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
141        Term = translate(_('Term'), 'waeup.kofa', target_language=portal_language)
142        Code = translate(_('Code'), 'waeup.kofa', target_language=portal_language)
143        Title = translate(_('Title'), 'waeup.kofa', target_language=portal_language)
144        Cred = translate(_('Credits'), 'waeup.kofa', target_language=portal_language)
145        #Score = translate(_('Score'), 'waeup.kofa', target_language=portal_language)
146        Grade = translate(_('Grade'), 'waeup.kofa', target_language=portal_language)
147        studentview = StudentBasePDFFormPage(self.context.student,
148            self.request, self.omit_fields)
149        students_utils = getUtility(IStudentsUtils)
150
151        tableheader = [(Code,'code', 2.5),
152                         (Title,'title', 8.5),
153                         (Term, 'semester', 1.5),
154                         (Cred, 'credits', 1.5),
155                         #(Score, 'score', 1.5),
156                         (Grade, 'grade', 1.5),
157                         ]
158
159        pdfstream = students_utils.renderPDFTranscript(
160            self, 'transcript.pdf',
161            self.context.student, studentview,
162            omit_fields=self.omit_fields,
163            tableheader=tableheader,
164            signatures=self._signatures(),
165            sigs_in_footer=self._sigsInFooter(),
166            digital_sigs=self._digital_sigs(),
167            save_file=self._save_file(),
168            )
169        if not pdfstream:
170            self.redirect(self.url(self.context.student))
171            return
172        return pdfstream
173
174class CustomAccommodationManageFormPage(NigeriaAccommodationManageFormPage):
175    """ Page to manage bed tickets.
176    This manage form page is for both students and students officers.
177    """
178    with_hostel_selection = True
179
180class StudentGetMatricNumberPage(UtilityView, grok.View):
181    """ Construct and set the matriculation number.
182    """
183    grok.context(IStudent)
184    grok.name('get_matric_number')
185    grok.require('waeup.viewStudent')
186
187    def update(self):
188        students_utils = getUtility(IStudentsUtils)
189        msg, mnumber = students_utils.setMatricNumber(self.context)
190        if msg:
191            self.flash(msg, type="danger")
192        else:
193            self.flash(_('Matriculation number %s assigned.' % mnumber))
194            self.context.writeLogMessage(self, '%s assigned' % mnumber)
195        self.redirect(self.url(self.context))
196        return
197
198    def render(self):
199        return
200
201class ExportPDFMatricNumberSlip(UtilityView, grok.View):
202    """Deliver a PDF notification slip.
203    """
204    grok.context(ICustomStudent)
205    grok.name('matric_number_slip.pdf')
206    grok.require('waeup.viewStudent')
207    prefix = 'form'
208
209    form_fields = grok.AutoFields(ICustomStudent).select(
210        'student_id', 'matric_number')
211    omit_fields = ('date_of_birth', 'current_level', 'flash_notice')
212
213    @property
214    def title(self):
215        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
216        return translate(_('Matriculation Number'), 'waeup.kofa',
217            target_language=portal_language)
218
219    @property
220    def label(self):
221        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
222        return translate(_('Matriculation Number Slip\n'),
223            target_language=portal_language) \
224            + ' %s' % self.context.display_fullname
225
226    def render(self):
227        if self.context.state not in (PAID,) or not self.context.is_fresh \
228            or not self.context.matric_number:
229            self.flash('Not allowed.', type="danger")
230            self.redirect(self.url(self.context))
231            return
232        students_utils = getUtility(IStudentsUtils)
233        return students_utils.renderPDFAdmissionLetter(self,
234            self.context.student, omit_fields=self.omit_fields,
235            pre_text='', post_text='')
236
237class CustomExportPDFAdmissionSlip(ExportPDFAdmissionSlip):
238    """Deliver a PDF Admission slip.
239    """
240
241    @property
242    def pre_text(self):
243        return (
244            'I am pleased to inform you that you have been offered '
245            'provisional admission into the Delta State Polytechnic, '
246            'Ogwashi-Uku as follows:')
247
248    @property
249    def post_text(self):
250        return """1. Duration: 2 years
251
2522.      This offer is conditional upon the confirmation of your qualification(s) as listed by you in the application form or which you claim to possess as at when this offer of admission was made and your meeting the minimum department entry requirement.
253
2543. At the time of Registration, you will be required to produce the original copies of your certificates or any other acceptable evidence of the qualification(s), on which this offer of admission has been based.
255
2564. If at any time after admission it is discovered that you do not possess any of the qualifications which you claimed to have obtained, you will be required to withdraw from the Polytechnic.
257
2585. Please, note that resumption/registration starts immediately.
259
2606. You are required to pay all the necessary fees, such as school fees, students\' union fees, boarding fees (optional) and any other prescribed fees online and register immediately. Late registration will attract severe sanction such as payment of late registration fee of N10000 or outright withdrawal of offer of admission.
261
2627. If you do not respond to this offer within two (2) weeks from the date of resumption, the Polytechnic will assume that you are not interested in the offer and may withdraw the offer to accommodate other candidates on awaiting list.
263
2648. If you do not pay your school fees and register within the stipulated time frame for registration, you would not be allowed to write the Polytechnic\'s semester examinations. Should you mistakenly write the exams, your scripts would not be marked.
265
2669. You are required to present at the time of registration, a letter of attestation from a clergy man, a lawyer,  a senior civil servant (Level 13 and above) or any person of reputable standing in the society.
267
26810. Before the commencement of registration, you will be required to undergo a medical examination which should be conducted in the Polytechnic clinic.
269
27011. Other information/instructions about facilities at the Polytechnic, including accommodation, can be obtained from the Polytechnic Portal. The Head of your School/Department at the Polytechnic will make the details of the programme available to you.
271
27212. At the time of registration, you are required to sign an undertaking of non-involvement in cult-related activities and acts of vandalism.
273
27413. We hope that you will be able to take advantage of this offer or provisional admission.
275
27614. Please, accept our hearty congratulations.
277
278Admissions Officer
279For: Registrar
280"""
281
282    def render(self):
283        students_utils = getUtility(IStudentsUtils)
284        return students_utils.renderPDFAdmissionLetter(self,
285            self.context.student, omit_fields=self.omit_fields,
286            pre_text=self.pre_text, post_text=self.post_text)
Note: See TracBrowser for help on using the repository browser.