| 1 | ## $Id: session_results_presentation.py 16694 2021-11-03 09:45:56Z henrik $ |
|---|
| 2 | ## |
|---|
| 3 | ## Copyright (C) 2013 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 | ## |
|---|
| 18 | |
|---|
| 19 | import grok |
|---|
| 20 | from zope.component import getUtility |
|---|
| 21 | from zope.interface import implementer, Interface, Attribute |
|---|
| 22 | from waeup.kofa.interfaces import IKofaUtils |
|---|
| 23 | from waeup.kofa.students.reports.session_results_presentation import ( |
|---|
| 24 | SessionResultsPresentation, SessionResultsPresentationGenerator, |
|---|
| 25 | ISessionResultsPresentation, SessionResultsPresentationGeneratorPage, |
|---|
| 26 | SessionResultsPresentationPDFView) |
|---|
| 27 | |
|---|
| 28 | class CustomSessionResultsPresentation(SessionResultsPresentation): |
|---|
| 29 | |
|---|
| 30 | note = "" |
|---|
| 31 | |
|---|
| 32 | pdfcreator = '' |
|---|
| 33 | |
|---|
| 34 | @property |
|---|
| 35 | def introduction (self): |
|---|
| 36 | havenot = '' |
|---|
| 37 | plurals = '' |
|---|
| 38 | num_students = sum([len(i) for i in self.data]) |
|---|
| 39 | site = grok.getSite() |
|---|
| 40 | certificate = site[ |
|---|
| 41 | 'faculties'][self.faccode][self.depcode].certificates[self.certcode] |
|---|
| 42 | study_mode = getattr(certificate, 'study_mode', None) |
|---|
| 43 | if num_students == 0: |
|---|
| 44 | return '' |
|---|
| 45 | if num_students > 1: |
|---|
| 46 | plurals = 's' |
|---|
| 47 | if len(self.data[0]) == num_students: |
|---|
| 48 | havenot = 'have not' |
|---|
| 49 | elif len(self.data[0]): |
|---|
| 50 | havenot = 'have/have not' |
|---|
| 51 | else: |
|---|
| 52 | havenot = 'have' |
|---|
| 53 | else: |
|---|
| 54 | if self.data[0]: |
|---|
| 55 | havenot = 'has not' |
|---|
| 56 | else: |
|---|
| 57 | havenot = 'has' |
|---|
| 58 | if self.faccode == 'FBM': |
|---|
| 59 | board = 'College Academic Board' |
|---|
| 60 | elif study_mode and study_mode.startswith('dp'): |
|---|
| 61 | board = 'Institute Board' |
|---|
| 62 | else: |
|---|
| 63 | board = 'Faculty Board' |
|---|
| 64 | |
|---|
| 65 | text = """I present to Senate, on behalf of the %s, |
|---|
| 66 | the results of courses taught and examinations held this academic session. |
|---|
| 67 | The following candidate%s %s satisfied the degree requirements |
|---|
| 68 | of the Faculty and %s qualified for the award of a degree as follows: |
|---|
| 69 | """ % (board, plurals, havenot, havenot) |
|---|
| 70 | return text |
|---|
| 71 | |
|---|
| 72 | # note = """ |
|---|
| 73 | #<br /><br /><br /><br /> |
|---|
| 74 | #<font size='10'> |
|---|
| 75 | #<strong>Note:</strong> This copy is subject to correction for typographical errors and ratification by the departmental board. |
|---|
| 76 | #</font> |
|---|
| 77 | #""" |
|---|
| 78 | |
|---|
| 79 | note = """ |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | FRNS (Faculty Requirements Not Satisfied) |
|---|
| 84 | NER (No Evidence of Registration) |
|---|
| 85 | NEV (No Evidence of Verification) |
|---|
| 86 | """ |
|---|
| 87 | |
|---|
| 88 | @property |
|---|
| 89 | def signatures(self): |
|---|
| 90 | site = grok.getSite() |
|---|
| 91 | dean = site['faculties'][self.faccode].officer_1 |
|---|
| 92 | hod = site['faculties'][self.faccode][self.depcode].officer_1 |
|---|
| 93 | ca = site['faculties'][self.faccode][self.depcode].officer_2 |
|---|
| 94 | if not dean: |
|---|
| 95 | dean = 'Dean of Faculty' |
|---|
| 96 | if not hod: |
|---|
| 97 | hod = 'Head of Department' |
|---|
| 98 | if not ca: |
|---|
| 99 | ca = 'Course Adviser' |
|---|
| 100 | dean = dean.replace(' - ', '<br />') |
|---|
| 101 | hod = hod.replace(' - ', '<br />') |
|---|
| 102 | ca = ca.replace(' - ', '<br />') |
|---|
| 103 | return [hod, dean] |
|---|
| 104 | |
|---|
| 105 | class CustomSessionResultsPresentationGenerator( |
|---|
| 106 | SessionResultsPresentationGenerator): |
|---|
| 107 | |
|---|
| 108 | def generate(self, site, faccode=None, depcode=None, certcode=None, |
|---|
| 109 | session=None, level=None, author=None): |
|---|
| 110 | result = CustomSessionResultsPresentation(faccode=faccode, |
|---|
| 111 | depcode=depcode, certcode=certcode, session=session, |
|---|
| 112 | level=level, author=author) |
|---|
| 113 | return result |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | # Session Results Presentation for graduating students only |
|---|
| 117 | |
|---|
| 118 | class IGradSessionResultsPresentation(ISessionResultsPresentation): |
|---|
| 119 | """Marker interface to distuingish graduating students level reports |
|---|
| 120 | from ordinary level reports. |
|---|
| 121 | """ |
|---|
| 122 | |
|---|
| 123 | @implementer(IGradSessionResultsPresentation) |
|---|
| 124 | class GradSessionResultsPresentation(CustomSessionResultsPresentation): |
|---|
| 125 | """ |
|---|
| 126 | """ |
|---|
| 127 | |
|---|
| 128 | title = 'Presentation of Results to Senate (Graduating Students)' |
|---|
| 129 | |
|---|
| 130 | def _excluded(self, level_obj): |
|---|
| 131 | # Do not list student if selecetd level is not final or an extension |
|---|
| 132 | if level_obj.level < level_obj.student['studycourse'].certificate.end_level: |
|---|
| 133 | return True |
|---|
| 134 | # Filter out students with extension levels higher than selected level |
|---|
| 135 | final_level = int(max(level_obj.student['studycourse'].keys())) |
|---|
| 136 | if final_level > level_obj.level: |
|---|
| 137 | return True |
|---|
| 138 | if level_obj.remark not in ( |
|---|
| 139 | 'Pass', '3s_rd_s', '2s_2_s', '2s_1_s', '1s_st_s', |
|---|
| 140 | 'Merit', 'Credit', 'Distinction'): |
|---|
| 141 | return True |
|---|
| 142 | return False |
|---|
| 143 | |
|---|
| 144 | class GradSessionResultsPresentationGenerator(SessionResultsPresentationGenerator): |
|---|
| 145 | |
|---|
| 146 | title = 'Presentation of Results to Senate (Graduating Students)' |
|---|
| 147 | grok.name('grad_session_results_presentation') |
|---|
| 148 | |
|---|
| 149 | def generate(self, site, faccode=None, depcode=None, certcode=None, |
|---|
| 150 | session=None, level=None, author=None): |
|---|
| 151 | result = GradSessionResultsPresentation(faccode=faccode, depcode=depcode, |
|---|
| 152 | certcode=certcode, session=session, level=level, author=author) |
|---|
| 153 | return result |
|---|
| 154 | |
|---|
| 155 | class GradSessionResultsPresentationGeneratorPage(SessionResultsPresentationGeneratorPage): |
|---|
| 156 | |
|---|
| 157 | grok.context(GradSessionResultsPresentationGenerator) |
|---|
| 158 | |
|---|
| 159 | class GradSessionResultsPresentationPDFView(SessionResultsPresentationPDFView): |
|---|
| 160 | |
|---|
| 161 | grok.context(IGradSessionResultsPresentation) |
|---|
| 162 | grok.name('pdf') |
|---|
| 163 | grok.require('waeup.handleReports') |
|---|
| 164 | |
|---|
| 165 | def _filename(self): |
|---|
| 166 | return 'GradSessionResultsPresentation_rno%s_%s.pdf' % ( |
|---|
| 167 | self.context.__name__, |
|---|
| 168 | self.context.creation_dt_string) |
|---|