[7191] | 1 | ## $Id: utils.py 17917 2024-09-07 15:38:05Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 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 | ## |
---|
[13076] | 18 | """General helper functions and utilities for the students section. |
---|
[6651] | 19 | """ |
---|
[7150] | 20 | import grok |
---|
[15234] | 21 | import textwrap |
---|
[16159] | 22 | from copy import deepcopy |
---|
[15584] | 23 | from cgi import escape |
---|
[8595] | 24 | from time import time |
---|
[15163] | 25 | from cStringIO import StringIO |
---|
[16157] | 26 | from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter |
---|
[7318] | 27 | from reportlab.lib import colors |
---|
[7019] | 28 | from reportlab.lib.units import cm |
---|
| 29 | from reportlab.lib.pagesizes import A4 |
---|
[9015] | 30 | from reportlab.lib.styles import getSampleStyleSheet |
---|
| 31 | from reportlab.platypus import Paragraph, Image, Table, Spacer |
---|
[14256] | 32 | from reportlab.platypus.doctemplate import LayoutError |
---|
[15984] | 33 | from reportlab.platypus.flowables import PageBreak |
---|
[11589] | 34 | from zope.event import notify |
---|
[9922] | 35 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
[15998] | 36 | from zope.component import getUtility, createObject, queryUtility |
---|
| 37 | from zope.catalog.interfaces import ICatalog |
---|
[7019] | 38 | from zope.formlib.form import setUpEditWidgets |
---|
[9015] | 39 | from zope.i18n import translate |
---|
[8596] | 40 | from waeup.kofa.interfaces import ( |
---|
[15881] | 41 | IExtFileStore, IKofaUtils, RETURNING, PAID, CLEARED, GRADUATED, |
---|
[15163] | 42 | academic_sessions_vocab, IFileStoreNameChooser) |
---|
[7811] | 43 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 44 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[10706] | 45 | from waeup.kofa.students.workflow import ADMITTED |
---|
[11589] | 46 | from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource |
---|
[9910] | 47 | from waeup.kofa.browser.pdf import ( |
---|
[9965] | 48 | ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, |
---|
[11550] | 49 | get_signature_tables, get_qrcode) |
---|
[9910] | 50 | from waeup.kofa.browser.interfaces import IPDFCreator |
---|
[10256] | 51 | from waeup.kofa.utils.helpers import to_timezone |
---|
[6651] | 52 | |
---|
[7318] | 53 | SLIP_STYLE = [ |
---|
| 54 | ('VALIGN',(0,0),(-1,-1),'TOP'), |
---|
| 55 | #('FONT', (0,0), (-1,-1), 'Helvetica', 11), |
---|
| 56 | ] |
---|
[7019] | 57 | |
---|
[7318] | 58 | CONTENT_STYLE = [ |
---|
| 59 | ('VALIGN',(0,0),(-1,-1),'TOP'), |
---|
| 60 | #('FONT', (0,0), (-1,-1), 'Helvetica', 8), |
---|
| 61 | #('TEXTCOLOR',(0,0),(-1,0),colors.white), |
---|
[9906] | 62 | #('BACKGROUND',(0,0),(-1,0),colors.black), |
---|
| 63 | ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
---|
| 64 | ('BOX', (0,0), (-1,-1), 1, colors.black), |
---|
[7318] | 65 | ] |
---|
[7304] | 66 | |
---|
[7318] | 67 | FONT_SIZE = 10 |
---|
| 68 | FONT_COLOR = 'black' |
---|
| 69 | |
---|
[8112] | 70 | def trans(text, lang): |
---|
| 71 | # shortcut |
---|
| 72 | return translate(text, 'waeup.kofa', target_language=lang) |
---|
| 73 | |
---|
[10261] | 74 | def formatted_text(text, color=FONT_COLOR, lang='en'): |
---|
[7511] | 75 | """Turn `text`, `color` and `size` into an HTML snippet. |
---|
[7318] | 76 | |
---|
[7511] | 77 | The snippet is suitable for use with reportlab and generating PDFs. |
---|
| 78 | Wraps the `text` into a ``<font>`` tag with passed attributes. |
---|
| 79 | |
---|
| 80 | Also non-strings are converted. Raw strings are expected to be |
---|
| 81 | utf-8 encoded (usually the case for widgets etc.). |
---|
| 82 | |
---|
[7804] | 83 | Finally, a br tag is added if widgets contain div tags |
---|
| 84 | which are not supported by reportlab. |
---|
| 85 | |
---|
[7511] | 86 | The returned snippet is unicode type. |
---|
| 87 | """ |
---|
| 88 | if not isinstance(text, unicode): |
---|
| 89 | if isinstance(text, basestring): |
---|
| 90 | text = text.decode('utf-8') |
---|
| 91 | else: |
---|
| 92 | text = unicode(text) |
---|
[9717] | 93 | if text == 'None': |
---|
| 94 | text = '' |
---|
[13665] | 95 | # Very long matriculation numbers need to be wrapped |
---|
| 96 | if text.find(' ') == -1 and len(text.split('/')) > 6: |
---|
| 97 | text = '/'.join(text.split('/')[:5]) + \ |
---|
| 98 | '/ ' + '/'.join(text.split('/')[5:]) |
---|
[8141] | 99 | # Mainly for boolean values we need our customized |
---|
| 100 | # localisation of the zope domain |
---|
[10261] | 101 | text = translate(text, 'zope', target_language=lang) |
---|
[7804] | 102 | text = text.replace('</div>', '<br /></div>') |
---|
[9910] | 103 | tag1 = u'<font color="%s">' % (color) |
---|
[7511] | 104 | return tag1 + u'%s</font>' % text |
---|
| 105 | |
---|
[8481] | 106 | def generate_student_id(): |
---|
[8410] | 107 | students = grok.getSite()['students'] |
---|
| 108 | new_id = students.unique_student_id |
---|
| 109 | return new_id |
---|
[6742] | 110 | |
---|
[7186] | 111 | def set_up_widgets(view, ignore_request=False): |
---|
[7019] | 112 | view.adapters = {} |
---|
| 113 | view.widgets = setUpEditWidgets( |
---|
| 114 | view.form_fields, view.prefix, view.context, view.request, |
---|
| 115 | adapters=view.adapters, for_display=True, |
---|
| 116 | ignore_request=ignore_request |
---|
| 117 | ) |
---|
| 118 | |
---|
[11550] | 119 | def render_student_data(studentview, context, omit_fields=(), |
---|
[14292] | 120 | lang='en', slipname=None, no_passport=False): |
---|
[7318] | 121 | """Render student table for an existing frame. |
---|
| 122 | """ |
---|
| 123 | width, height = A4 |
---|
[7186] | 124 | set_up_widgets(studentview, ignore_request=True) |
---|
[7318] | 125 | data_left = [] |
---|
[11550] | 126 | data_middle = [] |
---|
[7019] | 127 | style = getSampleStyleSheet() |
---|
[7280] | 128 | img = getUtility(IExtFileStore).getFileByContext( |
---|
| 129 | studentview.context, attr='passport.jpg') |
---|
| 130 | if img is None: |
---|
[7811] | 131 | from waeup.kofa.browser import DEFAULT_PASSPORT_IMAGE_PATH |
---|
[7280] | 132 | img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb') |
---|
[7318] | 133 | doc_img = Image(img.name, width=4*cm, height=4*cm, kind='bound') |
---|
| 134 | data_left.append([doc_img]) |
---|
[16442] | 135 | # Uniben wants a second picture. We add this picture here. |
---|
| 136 | img2 = getUtility(IExtFileStore).getFileByContext( |
---|
| 137 | studentview.context, attr='passport2.jpg') |
---|
| 138 | if img2 is not None: |
---|
| 139 | doc_img2 = Image(img2.name, width=4*cm, height=4*cm, kind='bound') |
---|
| 140 | data_left.append([doc_img2]) |
---|
[7318] | 141 | #data.append([Spacer(1, 12)]) |
---|
[9141] | 142 | |
---|
[10261] | 143 | f_label = trans(_('Name:'), lang) |
---|
[9910] | 144 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[9911] | 145 | f_text = formatted_text(studentview.context.display_fullname) |
---|
[9910] | 146 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 147 | data_middle.append([f_label,f_text]) |
---|
[9141] | 148 | |
---|
[7019] | 149 | for widget in studentview.widgets: |
---|
[9141] | 150 | if 'name' in widget.name: |
---|
[7019] | 151 | continue |
---|
[9911] | 152 | f_label = translate( |
---|
[7811] | 153 | widget.label.strip(), 'waeup.kofa', |
---|
[10261] | 154 | target_language=lang) |
---|
[9911] | 155 | f_label = Paragraph('%s:' % f_label, ENTRY1_STYLE) |
---|
[10261] | 156 | f_text = formatted_text(widget(), lang=lang) |
---|
[9910] | 157 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 158 | data_middle.append([f_label,f_text]) |
---|
[16086] | 159 | if not 'date_of_birth' in omit_fields: |
---|
| 160 | f_label = trans(_('Date of Birth:'), lang) |
---|
| 161 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 162 | date_of_birth = studentview.context.date_of_birth |
---|
| 163 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 164 | date_of_birth = to_timezone(date_of_birth, tz) |
---|
| 165 | if date_of_birth is not None: |
---|
| 166 | date_of_birth = date_of_birth.strftime("%d/%m/%Y") |
---|
| 167 | f_text = formatted_text(date_of_birth) |
---|
| 168 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 169 | data_middle.append([f_label,f_text]) |
---|
[9452] | 170 | if getattr(studentview.context, 'certcode', None): |
---|
[10250] | 171 | if not 'certificate' in omit_fields: |
---|
[10261] | 172 | f_label = trans(_('Study Course:'), lang) |
---|
[10250] | 173 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 174 | f_text = formatted_text( |
---|
[10650] | 175 | studentview.context['studycourse'].certificate.longtitle) |
---|
[10250] | 176 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 177 | data_middle.append([f_label,f_text]) |
---|
[10250] | 178 | if not 'department' in omit_fields: |
---|
[10261] | 179 | f_label = trans(_('Department:'), lang) |
---|
[10250] | 180 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 181 | f_text = formatted_text( |
---|
| 182 | studentview.context[ |
---|
[10650] | 183 | 'studycourse'].certificate.__parent__.__parent__.longtitle, |
---|
[10250] | 184 | ) |
---|
| 185 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 186 | data_middle.append([f_label,f_text]) |
---|
[10250] | 187 | if not 'faculty' in omit_fields: |
---|
[10261] | 188 | f_label = trans(_('Faculty:'), lang) |
---|
[10250] | 189 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 190 | f_text = formatted_text( |
---|
| 191 | studentview.context[ |
---|
[10650] | 192 | 'studycourse'].certificate.__parent__.__parent__.__parent__.longtitle, |
---|
[10250] | 193 | ) |
---|
| 194 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 195 | data_middle.append([f_label,f_text]) |
---|
[10688] | 196 | if not 'current_mode' in omit_fields: |
---|
| 197 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[11535] | 198 | sm = studymodes_dict[studentview.context.current_mode] |
---|
[10688] | 199 | f_label = trans(_('Study Mode:'), lang) |
---|
| 200 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 201 | f_text = formatted_text(sm) |
---|
| 202 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 203 | data_middle.append([f_label,f_text]) |
---|
[10250] | 204 | if not 'entry_session' in omit_fields: |
---|
[10261] | 205 | f_label = trans(_('Entry Session:'), lang) |
---|
[10250] | 206 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[11535] | 207 | entry_session = studentview.context.entry_session |
---|
[15662] | 208 | try: |
---|
| 209 | entry_session = academic_sessions_vocab.getTerm( |
---|
| 210 | entry_session).title |
---|
| 211 | except LookupError: |
---|
| 212 | entry_session = _('void') |
---|
[10250] | 213 | f_text = formatted_text(entry_session) |
---|
| 214 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 215 | data_middle.append([f_label,f_text]) |
---|
[11535] | 216 | # Requested by Uniben, does not really make sense |
---|
| 217 | if not 'current_level' in omit_fields: |
---|
[17863] | 218 | f_label = trans(_('Current Session:'), lang) |
---|
| 219 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 220 | current_session = studentview.context['studycourse'].current_session |
---|
| 221 | current_session = academic_sessions_vocab.getTerm( |
---|
| 222 | current_session).title |
---|
| 223 | f_text = formatted_text(current_session) |
---|
| 224 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 225 | data_middle.append([f_label,f_text]) |
---|
[11535] | 226 | f_label = trans(_('Current Level:'), lang) |
---|
| 227 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 228 | current_level = studentview.context['studycourse'].current_level |
---|
| 229 | studylevelsource = StudyLevelSource().factory |
---|
| 230 | current_level = studylevelsource.getTitle( |
---|
| 231 | studentview.context, current_level) |
---|
| 232 | f_text = formatted_text(current_level) |
---|
| 233 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 234 | data_middle.append([f_label,f_text]) |
---|
[9141] | 235 | |
---|
[14292] | 236 | if no_passport: |
---|
[14294] | 237 | table = Table(data_middle,style=SLIP_STYLE) |
---|
[14292] | 238 | table.hAlign = 'LEFT' |
---|
| 239 | return table |
---|
| 240 | |
---|
[11550] | 241 | # append QR code to the right |
---|
| 242 | if slipname: |
---|
| 243 | url = studentview.url(context, slipname) |
---|
| 244 | data_right = [[get_qrcode(url, width=70.0)]] |
---|
| 245 | table_right = Table(data_right,style=SLIP_STYLE) |
---|
| 246 | else: |
---|
| 247 | table_right = None |
---|
| 248 | |
---|
[7318] | 249 | table_left = Table(data_left,style=SLIP_STYLE) |
---|
[11550] | 250 | table_middle = Table(data_middle,style=SLIP_STYLE, colWidths=[5*cm, 5*cm]) |
---|
| 251 | table = Table([[table_left, table_middle, table_right],],style=SLIP_STYLE) |
---|
[7019] | 252 | return table |
---|
| 253 | |
---|
[10261] | 254 | def render_table_data(tableheader, tabledata, lang='en'): |
---|
[7318] | 255 | """Render children table for an existing frame. |
---|
| 256 | """ |
---|
[7304] | 257 | data = [] |
---|
[7318] | 258 | #data.append([Spacer(1, 12)]) |
---|
[7304] | 259 | line = [] |
---|
| 260 | style = getSampleStyleSheet() |
---|
| 261 | for element in tableheader: |
---|
[10261] | 262 | field = '<strong>%s</strong>' % formatted_text(element[0], lang=lang) |
---|
[7310] | 263 | field = Paragraph(field, style["Normal"]) |
---|
[7304] | 264 | line.append(field) |
---|
| 265 | data.append(line) |
---|
| 266 | for ticket in tabledata: |
---|
| 267 | line = [] |
---|
| 268 | for element in tableheader: |
---|
[7511] | 269 | field = formatted_text(getattr(ticket,element[1],u' ')) |
---|
[7318] | 270 | field = Paragraph(field, style["Normal"]) |
---|
[7304] | 271 | line.append(field) |
---|
| 272 | data.append(line) |
---|
[7310] | 273 | table = Table(data,colWidths=[ |
---|
[7318] | 274 | element[2]*cm for element in tableheader], style=CONTENT_STYLE) |
---|
[7304] | 275 | return table |
---|
| 276 | |
---|
[10261] | 277 | def render_transcript_data(view, tableheader, levels_data, lang='en'): |
---|
[10250] | 278 | """Render children table for an existing frame. |
---|
| 279 | """ |
---|
| 280 | data = [] |
---|
| 281 | style = getSampleStyleSheet() |
---|
[14473] | 282 | format_float = getUtility(IKofaUtils).format_float |
---|
[10250] | 283 | for level in levels_data: |
---|
| 284 | level_obj = level['level'] |
---|
[10251] | 285 | tickets = level['tickets_1'] + level['tickets_2'] + level['tickets_3'] |
---|
[16902] | 286 | if not tickets: |
---|
| 287 | continue |
---|
[10251] | 288 | headerline = [] |
---|
| 289 | tabledata = [] |
---|
[15203] | 290 | if 'evel' in view.level_dict.get('ticket.level', str(level_obj.level)): |
---|
| 291 | subheader = '%s %s, %s' % ( |
---|
| 292 | trans(_('Session'), lang), |
---|
| 293 | view.session_dict[level_obj.level_session], |
---|
| 294 | view.level_dict.get('ticket.level', str(level_obj.level))) |
---|
| 295 | else: |
---|
| 296 | subheader = '%s %s, %s %s' % ( |
---|
| 297 | trans(_('Session'), lang), |
---|
| 298 | view.session_dict[level_obj.level_session], |
---|
| 299 | trans(_('Level'), lang), |
---|
[15212] | 300 | view.level_dict.get(level_obj.level, str(level_obj.level))) |
---|
[10250] | 301 | data.append(Paragraph(subheader, HEADING_STYLE)) |
---|
| 302 | for element in tableheader: |
---|
| 303 | field = '<strong>%s</strong>' % formatted_text(element[0]) |
---|
| 304 | field = Paragraph(field, style["Normal"]) |
---|
[10251] | 305 | headerline.append(field) |
---|
| 306 | tabledata.append(headerline) |
---|
[10250] | 307 | for ticket in tickets: |
---|
[10251] | 308 | ticketline = [] |
---|
[10250] | 309 | for element in tableheader: |
---|
| 310 | field = formatted_text(getattr(ticket,element[1],u' ')) |
---|
| 311 | field = Paragraph(field, style["Normal"]) |
---|
[10251] | 312 | ticketline.append(field) |
---|
| 313 | tabledata.append(ticketline) |
---|
[10250] | 314 | table = Table(tabledata,colWidths=[ |
---|
| 315 | element[2]*cm for element in tableheader], style=CONTENT_STYLE) |
---|
| 316 | data.append(table) |
---|
[14473] | 317 | sgpa = format_float(level['sgpa'], 2) |
---|
| 318 | sgpa = '%s: %s' % (trans('Sessional GPA (rectified)', lang), sgpa) |
---|
| 319 | #sgpa = '%s: %.2f' % (trans('Sessional GPA (rectified)', lang), level['sgpa']) |
---|
[10261] | 320 | data.append(Paragraph(sgpa, style["Normal"])) |
---|
[15333] | 321 | if getattr(level_obj, 'transcript_remark', None): |
---|
[15331] | 322 | remark = '%s: %s' % ( |
---|
[15333] | 323 | trans('Transcript Remark', lang), |
---|
| 324 | getattr(level_obj, 'transcript_remark')) |
---|
[15331] | 325 | data.append(Paragraph(remark, style["Normal"])) |
---|
[10250] | 326 | return data |
---|
| 327 | |
---|
[8112] | 328 | def docs_as_flowables(view, lang='en'): |
---|
| 329 | """Create reportlab flowables out of scanned docs. |
---|
| 330 | """ |
---|
| 331 | # XXX: fix circular import problem |
---|
[12448] | 332 | from waeup.kofa.browser.fileviewlets import FileManager |
---|
[8112] | 333 | from waeup.kofa.browser import DEFAULT_IMAGE_PATH |
---|
| 334 | style = getSampleStyleSheet() |
---|
| 335 | data = [] |
---|
[7318] | 336 | |
---|
[8112] | 337 | # Collect viewlets |
---|
| 338 | fm = FileManager(view.context, view.request, view) |
---|
| 339 | fm.update() |
---|
| 340 | if fm.viewlets: |
---|
| 341 | sc_translation = trans(_('Scanned Documents'), lang) |
---|
[9910] | 342 | data.append(Paragraph(sc_translation, HEADING_STYLE)) |
---|
[8112] | 343 | # Insert list of scanned documents |
---|
| 344 | table_data = [] |
---|
| 345 | for viewlet in fm.viewlets: |
---|
[10020] | 346 | if viewlet.file_exists: |
---|
| 347 | # Show viewlet only if file exists |
---|
| 348 | f_label = Paragraph(trans(viewlet.label, lang), ENTRY1_STYLE) |
---|
| 349 | img_path = getattr(getUtility(IExtFileStore).getFileByContext( |
---|
| 350 | view.context, attr=viewlet.download_name), 'name', None) |
---|
| 351 | #f_text = Paragraph(trans(_('(not provided)'),lang), ENTRY1_STYLE) |
---|
| 352 | if img_path is None: |
---|
| 353 | pass |
---|
| 354 | elif not img_path[-4:] in ('.jpg', '.JPG'): |
---|
| 355 | # reportlab requires jpg images, I think. |
---|
| 356 | f_text = Paragraph('%s (not displayable)' % ( |
---|
| 357 | viewlet.title,), ENTRY1_STYLE) |
---|
| 358 | else: |
---|
| 359 | f_text = Image(img_path, width=2*cm, height=1*cm, kind='bound') |
---|
| 360 | table_data.append([f_label, f_text]) |
---|
[8112] | 361 | if table_data: |
---|
| 362 | # safety belt; empty tables lead to problems. |
---|
| 363 | data.append(Table(table_data, style=SLIP_STYLE)) |
---|
| 364 | return data |
---|
| 365 | |
---|
[7150] | 366 | class StudentsUtils(grok.GlobalUtility): |
---|
| 367 | """A collection of methods subject to customization. |
---|
| 368 | """ |
---|
| 369 | grok.implements(IStudentsUtils) |
---|
[7019] | 370 | |
---|
[8268] | 371 | def getReturningData(self, student): |
---|
[9005] | 372 | """ Define what happens after school fee payment |
---|
[7841] | 373 | depending on the student's senate verdict. |
---|
| 374 | In the base configuration current level is always increased |
---|
| 375 | by 100 no matter which verdict has been assigned. |
---|
| 376 | """ |
---|
[8268] | 377 | new_level = student['studycourse'].current_level + 100 |
---|
| 378 | new_session = student['studycourse'].current_session + 1 |
---|
| 379 | return new_session, new_level |
---|
| 380 | |
---|
| 381 | def setReturningData(self, student): |
---|
[9005] | 382 | """ Define what happens after school fee payment |
---|
| 383 | depending on the student's senate verdict. |
---|
[16777] | 384 | This method follows the same algorithm as `getReturningData` but |
---|
[9005] | 385 | it also sets the new values. |
---|
[8268] | 386 | """ |
---|
| 387 | new_session, new_level = self.getReturningData(student) |
---|
[9922] | 388 | try: |
---|
| 389 | student['studycourse'].current_level = new_level |
---|
| 390 | except ConstraintNotSatisfied: |
---|
| 391 | # Do not change level if level exceeds the |
---|
| 392 | # certificate's end_level. |
---|
| 393 | pass |
---|
[8268] | 394 | student['studycourse'].current_session = new_session |
---|
[7615] | 395 | verdict = student['studycourse'].current_verdict |
---|
[8820] | 396 | student['studycourse'].current_verdict = '0' |
---|
[7615] | 397 | student['studycourse'].previous_verdict = verdict |
---|
| 398 | return |
---|
| 399 | |
---|
[9519] | 400 | def _getSessionConfiguration(self, session): |
---|
| 401 | try: |
---|
| 402 | return grok.getSite()['configuration'][str(session)] |
---|
| 403 | except KeyError: |
---|
| 404 | return None |
---|
| 405 | |
---|
[11451] | 406 | def _isPaymentDisabled(self, p_session, category, student): |
---|
| 407 | academic_session = self._getSessionConfiguration(p_session) |
---|
[11452] | 408 | if category == 'schoolfee' and \ |
---|
| 409 | 'sf_all' in academic_session.payment_disabled: |
---|
[11451] | 410 | return True |
---|
| 411 | return False |
---|
| 412 | |
---|
[11641] | 413 | def samePaymentMade(self, student, category, p_item, p_session): |
---|
| 414 | for key in student['payments'].keys(): |
---|
| 415 | ticket = student['payments'][key] |
---|
| 416 | if ticket.p_state == 'paid' and\ |
---|
| 417 | ticket.p_category == category and \ |
---|
[16113] | 418 | ticket.p_item != 'Balance' and \ |
---|
[11641] | 419 | ticket.p_item == p_item and \ |
---|
| 420 | ticket.p_session == p_session: |
---|
| 421 | return True |
---|
| 422 | return False |
---|
| 423 | |
---|
[9148] | 424 | def setPaymentDetails(self, category, student, |
---|
[16157] | 425 | previous_session=None, previous_level=None, combi=[]): |
---|
[13124] | 426 | """Create a payment ticket and set the payment data of a |
---|
[13040] | 427 | student for the payment category specified. |
---|
[7841] | 428 | """ |
---|
[8595] | 429 | p_item = u'' |
---|
| 430 | amount = 0.0 |
---|
[9148] | 431 | if previous_session: |
---|
[9517] | 432 | if previous_session < student['studycourse'].entry_session: |
---|
| 433 | return _('The previous session must not fall below ' |
---|
| 434 | 'your entry session.'), None |
---|
| 435 | if category == 'schoolfee': |
---|
| 436 | # School fee is always paid for the following session |
---|
| 437 | if previous_session > student['studycourse'].current_session: |
---|
| 438 | return _('This is not a previous session.'), None |
---|
| 439 | else: |
---|
| 440 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 441 | return _('This is not a previous session.'), None |
---|
[9148] | 442 | p_session = previous_session |
---|
| 443 | p_level = previous_level |
---|
| 444 | p_current = False |
---|
| 445 | else: |
---|
| 446 | p_session = student['studycourse'].current_session |
---|
| 447 | p_level = student['studycourse'].current_level |
---|
| 448 | p_current = True |
---|
[9519] | 449 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 450 | if academic_session == None: |
---|
[8595] | 451 | return _(u'Session configuration object is not available.'), None |
---|
[9521] | 452 | # Determine fee. |
---|
[7150] | 453 | if category == 'schoolfee': |
---|
[8595] | 454 | try: |
---|
[8596] | 455 | certificate = student['studycourse'].certificate |
---|
| 456 | p_item = certificate.code |
---|
[8595] | 457 | except (AttributeError, TypeError): |
---|
| 458 | return _('Study course data are incomplete.'), None |
---|
[9148] | 459 | if previous_session: |
---|
[9916] | 460 | # Students can pay for previous sessions in all |
---|
| 461 | # workflow states. Fresh students are excluded by the |
---|
| 462 | # update method of the PreviousPaymentAddFormPage. |
---|
[9148] | 463 | if previous_level == 100: |
---|
| 464 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 465 | else: |
---|
| 466 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 467 | else: |
---|
| 468 | if student.state == CLEARED: |
---|
| 469 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 470 | elif student.state == RETURNING: |
---|
[9916] | 471 | # In case of returning school fee payment the |
---|
| 472 | # payment session and level contain the values of |
---|
| 473 | # the session the student has paid for. Payment |
---|
| 474 | # session is always next session. |
---|
[9148] | 475 | p_session, p_level = self.getReturningData(student) |
---|
[9519] | 476 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 477 | if academic_session == None: |
---|
[9916] | 478 | return _( |
---|
| 479 | u'Session configuration object is not available.' |
---|
| 480 | ), None |
---|
[9148] | 481 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 482 | elif student.is_postgrad and student.state == PAID: |
---|
[9916] | 483 | # Returning postgraduate students also pay for the |
---|
| 484 | # next session but their level always remains the |
---|
| 485 | # same. |
---|
[9148] | 486 | p_session += 1 |
---|
[9519] | 487 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 488 | if academic_session == None: |
---|
[9916] | 489 | return _( |
---|
| 490 | u'Session configuration object is not available.' |
---|
| 491 | ), None |
---|
[9148] | 492 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[7150] | 493 | elif category == 'clearance': |
---|
[9178] | 494 | try: |
---|
| 495 | p_item = student['studycourse'].certificate.code |
---|
| 496 | except (AttributeError, TypeError): |
---|
| 497 | return _('Study course data are incomplete.'), None |
---|
[8595] | 498 | amount = academic_session.clearance_fee |
---|
[7150] | 499 | elif category == 'bed_allocation': |
---|
[17182] | 500 | acco_details = self.getAccommodationDetails(student) |
---|
| 501 | p_session = acco_details['booking_session'] |
---|
| 502 | p_item = acco_details['bt'] |
---|
[8595] | 503 | amount = academic_session.booking_fee |
---|
[9423] | 504 | elif category == 'hostel_maintenance': |
---|
[10681] | 505 | amount = 0.0 |
---|
[17182] | 506 | booking_session = grok.getSite()['hostels'].accommodation_session |
---|
| 507 | bedticket = student['accommodation'].get(str(booking_session), None) |
---|
[13501] | 508 | if bedticket is not None and bedticket.bed is not None: |
---|
[17182] | 509 | p_session = booking_session |
---|
[9429] | 510 | p_item = bedticket.bed_coordinates |
---|
[10681] | 511 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
| 512 | amount = bedticket.bed.__parent__.maint_fee |
---|
| 513 | else: |
---|
| 514 | # fallback |
---|
| 515 | amount = academic_session.maint_fee |
---|
[9429] | 516 | else: |
---|
[13505] | 517 | return _(u'No bed allocated.'), None |
---|
[15664] | 518 | elif category == 'combi' and combi: |
---|
| 519 | categories = getUtility(IKofaUtils).COMBI_PAYMENT_CATEGORIES |
---|
| 520 | for cat in combi: |
---|
| 521 | fee_name = cat + '_fee' |
---|
| 522 | cat_amount = getattr(academic_session, fee_name, 0.0) |
---|
| 523 | if not cat_amount: |
---|
| 524 | return _('%s undefined.' % categories[cat]), None |
---|
| 525 | amount += cat_amount |
---|
| 526 | p_item += u'%s + ' % categories[cat] |
---|
| 527 | p_item = p_item.strip(' + ') |
---|
[15652] | 528 | else: |
---|
| 529 | fee_name = category + '_fee' |
---|
| 530 | amount = getattr(academic_session, fee_name, 0.0) |
---|
[8595] | 531 | if amount in (0.0, None): |
---|
[9517] | 532 | return _('Amount could not be determined.'), None |
---|
[11641] | 533 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 534 | return _('This type of payment has already been made.'), None |
---|
[11451] | 535 | if self._isPaymentDisabled(p_session, category, student): |
---|
[13797] | 536 | return _('This category of payments has been disabled.'), None |
---|
[8708] | 537 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8951] | 538 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8595] | 539 | payment.p_id = "p%s" % timestamp |
---|
| 540 | payment.p_category = category |
---|
| 541 | payment.p_item = p_item |
---|
| 542 | payment.p_session = p_session |
---|
| 543 | payment.p_level = p_level |
---|
[9148] | 544 | payment.p_current = p_current |
---|
[8595] | 545 | payment.amount_auth = amount |
---|
[15685] | 546 | payment.p_combi = combi |
---|
[8595] | 547 | return None, payment |
---|
[7019] | 548 | |
---|
[9868] | 549 | def setBalanceDetails(self, category, student, |
---|
[9864] | 550 | balance_session, balance_level, balance_amount): |
---|
[13124] | 551 | """Create a balance payment ticket and set the payment data |
---|
| 552 | as selected by the student. |
---|
[9864] | 553 | """ |
---|
[9868] | 554 | p_item = u'Balance' |
---|
[9864] | 555 | p_session = balance_session |
---|
| 556 | p_level = balance_level |
---|
| 557 | p_current = False |
---|
| 558 | amount = balance_amount |
---|
| 559 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 560 | if academic_session == None: |
---|
| 561 | return _(u'Session configuration object is not available.'), None |
---|
[9874] | 562 | if amount in (0.0, None) or amount < 0: |
---|
| 563 | return _('Amount must be greater than 0.'), None |
---|
[9864] | 564 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 565 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 566 | payment.p_id = "p%s" % timestamp |
---|
[9868] | 567 | payment.p_category = category |
---|
[9864] | 568 | payment.p_item = p_item |
---|
| 569 | payment.p_session = p_session |
---|
| 570 | payment.p_level = p_level |
---|
| 571 | payment.p_current = p_current |
---|
| 572 | payment.amount_auth = amount |
---|
| 573 | return None, payment |
---|
| 574 | |
---|
[12896] | 575 | def increaseMatricInteger(self, student): |
---|
| 576 | """Increase counter for matric numbers. |
---|
| 577 | This counter can be a centrally stored attribute or an attribute of |
---|
| 578 | faculties, departments or certificates. In the base package the counter |
---|
[13124] | 579 | is as an attribute of the site configuration container. |
---|
[12896] | 580 | """ |
---|
| 581 | grok.getSite()['configuration'].next_matric_integer += 1 |
---|
| 582 | return |
---|
| 583 | |
---|
[11595] | 584 | def constructMatricNumber(self, student): |
---|
[12896] | 585 | """Fetch the matric number counter which fits the student and |
---|
| 586 | construct the new matric number of the student. |
---|
[12902] | 587 | In the base package the counter is returned which is as an attribute |
---|
[13124] | 588 | of the site configuration container. |
---|
[12896] | 589 | """ |
---|
[11595] | 590 | next_integer = grok.getSite()['configuration'].next_matric_integer |
---|
| 591 | if next_integer == 0: |
---|
[11619] | 592 | return _('Matriculation number cannot be set.'), None |
---|
| 593 | return None, unicode(next_integer) |
---|
[11589] | 594 | |
---|
| 595 | def setMatricNumber(self, student): |
---|
[13124] | 596 | """Set matriculation number of student. If the student's matric number |
---|
| 597 | is unset a new matric number is |
---|
[12896] | 598 | constructed according to the matriculation number construction rules |
---|
[13124] | 599 | defined in the `constructMatricNumber` method. The new matric number is |
---|
[12896] | 600 | set, the students catalog updated. The corresponding matric number |
---|
| 601 | counter is increased by one. |
---|
[11589] | 602 | |
---|
| 603 | This method is tested but not used in the base package. It can |
---|
| 604 | be used in custom packages by adding respective views |
---|
[13124] | 605 | and by customizing `increaseMatricInteger` and `constructMatricNumber` |
---|
[12896] | 606 | according to the university's matriculation number construction rules. |
---|
[11589] | 607 | |
---|
[12896] | 608 | The method can be disabled by setting the counter to zero. |
---|
[11589] | 609 | """ |
---|
| 610 | if student.matric_number is not None: |
---|
| 611 | return _('Matriculation number already set.'), None |
---|
[11590] | 612 | if student.certcode is None: |
---|
| 613 | return _('No certificate assigned.'), None |
---|
[11619] | 614 | error, matric_number = self.constructMatricNumber(student) |
---|
| 615 | if error: |
---|
| 616 | return error, None |
---|
[11589] | 617 | try: |
---|
[11592] | 618 | student.matric_number = matric_number |
---|
[11589] | 619 | except MatNumNotInSource: |
---|
[13224] | 620 | return _('Matriculation number %s exists.' % matric_number), None |
---|
[11589] | 621 | notify(grok.ObjectModifiedEvent(student)) |
---|
[12896] | 622 | self.increaseMatricInteger(student) |
---|
[11595] | 623 | return None, matric_number |
---|
[11589] | 624 | |
---|
[16671] | 625 | def allowPortraitChange(self, student): |
---|
| 626 | """Check if student is allowed to change the portrait file. |
---|
| 627 | """ |
---|
| 628 | if student.state not in self.PORTRAIT_CHANGE_STATES: |
---|
| 629 | return False |
---|
| 630 | return True |
---|
| 631 | |
---|
[7186] | 632 | def getAccommodationDetails(self, student): |
---|
[9219] | 633 | """Determine the accommodation data of a student. |
---|
[7841] | 634 | """ |
---|
[7150] | 635 | d = {} |
---|
| 636 | d['error'] = u'' |
---|
[8685] | 637 | hostels = grok.getSite()['hostels'] |
---|
| 638 | d['booking_session'] = hostels.accommodation_session |
---|
| 639 | d['allowed_states'] = hostels.accommodation_states |
---|
[8688] | 640 | d['startdate'] = hostels.startdate |
---|
| 641 | d['enddate'] = hostels.enddate |
---|
| 642 | d['expired'] = hostels.expired |
---|
[7150] | 643 | # Determine bed type |
---|
| 644 | studycourse = student['studycourse'] |
---|
[7369] | 645 | certificate = getattr(studycourse,'certificate',None) |
---|
[7150] | 646 | entry_session = studycourse.entry_session |
---|
| 647 | current_level = studycourse.current_level |
---|
[9187] | 648 | if None in (entry_session, current_level, certificate): |
---|
| 649 | return d |
---|
[7369] | 650 | end_level = certificate.end_level |
---|
[9148] | 651 | if current_level == 10: |
---|
| 652 | bt = 'pr' |
---|
| 653 | elif entry_session == grok.getSite()['hostels'].accommodation_session: |
---|
[7150] | 654 | bt = 'fr' |
---|
| 655 | elif current_level >= end_level: |
---|
| 656 | bt = 'fi' |
---|
| 657 | else: |
---|
| 658 | bt = 're' |
---|
| 659 | if student.sex == 'f': |
---|
| 660 | sex = 'female' |
---|
| 661 | else: |
---|
| 662 | sex = 'male' |
---|
| 663 | special_handling = 'regular' |
---|
| 664 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 665 | return d |
---|
[7019] | 666 | |
---|
[17176] | 667 | ACCOMMODATION_SPAN = 0 |
---|
| 668 | |
---|
[13247] | 669 | def checkAccommodationRequirements(self, student, acc_details): |
---|
| 670 | if acc_details.get('expired', False): |
---|
| 671 | startdate = acc_details.get('startdate') |
---|
| 672 | enddate = acc_details.get('enddate') |
---|
| 673 | if startdate and enddate: |
---|
| 674 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 675 | startdate = to_timezone( |
---|
| 676 | startdate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 677 | enddate = to_timezone( |
---|
| 678 | enddate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 679 | return _("Outside booking period: ${a} - ${b}", |
---|
| 680 | mapping = {'a': startdate, 'b': enddate}) |
---|
| 681 | else: |
---|
| 682 | return _("Outside booking period.") |
---|
| 683 | if not acc_details.get('bt'): |
---|
| 684 | return _("Your data are incomplete.") |
---|
| 685 | if not student.state in acc_details['allowed_states']: |
---|
| 686 | return _("You are in the wrong registration state.") |
---|
[17176] | 687 | if acc_details['booking_session'] - student[ |
---|
| 688 | 'studycourse'].current_session > self.ACCOMMODATION_SPAN: |
---|
| 689 | return _('Your current session does not allow ' + \ |
---|
| 690 | 'to book accommodation.') |
---|
[15306] | 691 | bsession = str(acc_details['booking_session']) |
---|
| 692 | if bsession in student['accommodation'].keys() \ |
---|
| 693 | and not 'booking expired' in \ |
---|
| 694 | student['accommodation'][bsession].bed_coordinates: |
---|
[13247] | 695 | return _('You already booked a bed space in ' |
---|
| 696 | 'current accommodation session.') |
---|
| 697 | return |
---|
| 698 | |
---|
[15705] | 699 | def selectBed(self, available_beds): |
---|
[13457] | 700 | """Select a bed from a filtered list of available beds. |
---|
| 701 | In the base configuration beds are sorted by the sort id |
---|
| 702 | of the hostel and the bed number. The first bed found in |
---|
| 703 | this sorted list is taken. |
---|
[7841] | 704 | """ |
---|
[13457] | 705 | sorted_beds = sorted(available_beds, |
---|
| 706 | key=lambda bed: 1000 * bed.__parent__.sort_id + bed.bed_number) |
---|
| 707 | return sorted_beds[0] |
---|
[7150] | 708 | |
---|
[15879] | 709 | def GPABoundaries(self, faccode=None, depcode=None, certcode=None): |
---|
| 710 | return ((1, 'Fail'), |
---|
| 711 | (1.5, 'Pass'), |
---|
| 712 | (2.4, '3rd Class'), |
---|
| 713 | (3.5, '2nd Class Lower'), |
---|
| 714 | (4.5, '2nd Class Upper'), |
---|
| 715 | (5, '1st Class')) |
---|
[9979] | 716 | |
---|
[15879] | 717 | def getClassFromCGPA(self, gpa, student): |
---|
| 718 | """Determine the class of degree. In some custom packages |
---|
| 719 | this class depends on e.g. the entry session of the student. In the |
---|
| 720 | base package, it does not. |
---|
[9191] | 721 | """ |
---|
[15879] | 722 | if gpa < self.GPABoundaries()[0][0]: |
---|
| 723 | return 0, self.GPABoundaries()[0][1] |
---|
| 724 | if gpa < self.GPABoundaries()[1][0]: |
---|
| 725 | return 1, self.GPABoundaries()[1][1] |
---|
| 726 | if gpa < self.GPABoundaries()[2][0]: |
---|
| 727 | return 2, self.GPABoundaries()[2][1] |
---|
| 728 | if gpa < self.GPABoundaries()[3][0]: |
---|
| 729 | return 3, self.GPABoundaries()[3][1] |
---|
| 730 | if gpa < self.GPABoundaries()[4][0]: |
---|
| 731 | return 4, self.GPABoundaries()[4][1] |
---|
| 732 | if gpa <= self.GPABoundaries()[5][0]: |
---|
| 733 | return 5, self.GPABoundaries()[5][1] |
---|
| 734 | return |
---|
[9191] | 735 | |
---|
[15879] | 736 | def getDegreeClassNumber(self, level_obj): |
---|
| 737 | """Get degree class number (used for SessionResultsPresentation |
---|
| 738 | reports). |
---|
| 739 | """ |
---|
| 740 | if level_obj.gpa_params[1] == 0: |
---|
| 741 | # No credits weighted |
---|
| 742 | return 6 |
---|
| 743 | return self.getClassFromCGPA( |
---|
| 744 | level_obj.cumulative_params[0], level_obj.student)[0] |
---|
[9191] | 745 | |
---|
[15879] | 746 | def _saveTranscriptPDF(self, student, transcript): |
---|
| 747 | """Create a transcript PDF file and store it in student folder. |
---|
| 748 | """ |
---|
| 749 | file_store = getUtility(IExtFileStore) |
---|
| 750 | file_id = IFileStoreNameChooser(student).chooseName( |
---|
| 751 | attr="final_transcript.pdf") |
---|
| 752 | file_store.createFile(file_id, StringIO(transcript)) |
---|
| 753 | return |
---|
[9191] | 754 | |
---|
[15879] | 755 | def warnCreditsOOR(self, studylevel, course=None): |
---|
| 756 | """Return message if credits are out of range. In the base |
---|
| 757 | package only maximum credits is set. |
---|
| 758 | """ |
---|
| 759 | if course and studylevel.total_credits + course.credits > 50: |
---|
| 760 | return _('Maximum credits exceeded.') |
---|
| 761 | elif studylevel.total_credits > 50: |
---|
| 762 | return _('Maximum credits exceeded.') |
---|
| 763 | return |
---|
[9191] | 764 | |
---|
[15986] | 765 | def warnCourseAlreadyPassed(self, studylevel, course): |
---|
| 766 | """Return message if course has already been passed at |
---|
| 767 | previous levels. |
---|
| 768 | """ |
---|
| 769 | for slevel in studylevel.__parent__.values(): |
---|
| 770 | for cticket in slevel.values(): |
---|
| 771 | if cticket.code == course.code \ |
---|
| 772 | and cticket.total_score >= cticket.passmark: |
---|
| 773 | return _('Course has already been passed at previous level.') |
---|
| 774 | return False |
---|
| 775 | |
---|
[15879] | 776 | def getBedCoordinates(self, bedticket): |
---|
| 777 | """Return descriptive bed coordinates. |
---|
| 778 | This method can be used to customize the `display_coordinates` |
---|
| 779 | property method in order to display a |
---|
| 780 | customary description of the bed space. |
---|
| 781 | """ |
---|
| 782 | return bedticket.bed_coordinates |
---|
[9191] | 783 | |
---|
[15879] | 784 | def clearance_disabled_message(self, student): |
---|
| 785 | """Render message if clearance is disabled. |
---|
| 786 | """ |
---|
| 787 | try: |
---|
| 788 | session_config = grok.getSite()[ |
---|
| 789 | 'configuration'][str(student.current_session)] |
---|
| 790 | except KeyError: |
---|
| 791 | return _('Session configuration object is not available.') |
---|
| 792 | if not session_config.clearance_enabled: |
---|
| 793 | return _('Clearance is disabled for this session.') |
---|
| 794 | return None |
---|
| 795 | |
---|
[9949] | 796 | def getPDFCreator(self, context): |
---|
| 797 | """Get a pdf creator suitable for `context`. |
---|
| 798 | The default implementation always returns the default creator. |
---|
| 799 | """ |
---|
| 800 | return getUtility(IPDFCreator) |
---|
| 801 | |
---|
[16254] | 802 | def _mergeFiles(self, mergefiles, watermark, pdf_stream): |
---|
[16253] | 803 | merger = PdfFileMerger() |
---|
| 804 | merger.append(StringIO(pdf_stream)) |
---|
| 805 | for file in mergefiles: |
---|
| 806 | if watermark: |
---|
| 807 | # Pass through all pages of each file |
---|
| 808 | # and merge with watermark page. Paint |
---|
| 809 | # watermark first to make it transparent. |
---|
| 810 | marked_file = PdfFileWriter() |
---|
| 811 | orig_file = PdfFileReader(file) |
---|
| 812 | num_pages = orig_file.getNumPages() |
---|
| 813 | for num in range(num_pages): |
---|
| 814 | watermark_file = PdfFileReader(watermark) |
---|
| 815 | page = watermark_file.getPage(0) |
---|
| 816 | page.mergePage(orig_file.getPage(num)) |
---|
| 817 | marked_file.addPage(page) |
---|
| 818 | # Save into a file-like object |
---|
| 819 | tmp1 = StringIO() |
---|
| 820 | marked_file.write(tmp1) |
---|
| 821 | # Append the file-like object |
---|
| 822 | merger.append(tmp1) |
---|
| 823 | else: |
---|
| 824 | # Just append the file object |
---|
| 825 | merger.append(file) |
---|
| 826 | # Save into a file-like object |
---|
| 827 | tmp2 = StringIO() |
---|
| 828 | merger.write(tmp2) |
---|
| 829 | return tmp2.getvalue() |
---|
| 830 | |
---|
[8257] | 831 | def renderPDF(self, view, filename='slip.pdf', student=None, |
---|
[9906] | 832 | studentview=None, |
---|
[10439] | 833 | tableheader=[], tabledata=[], |
---|
[9555] | 834 | note=None, signatures=None, sigs_in_footer=(), |
---|
[10250] | 835 | show_scans=True, topMargin=1.5, |
---|
[16253] | 836 | omit_fields=(), |
---|
[16291] | 837 | mergefiles=None, watermark=None, |
---|
| 838 | pagebreak=False): |
---|
[14151] | 839 | """Render pdf slips for various pages (also some pages |
---|
| 840 | in the applicants module). |
---|
[7841] | 841 | """ |
---|
[10261] | 842 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9916] | 843 | # XXX: tell what the different parameters mean |
---|
[8112] | 844 | style = getSampleStyleSheet() |
---|
[9949] | 845 | creator = self.getPDFCreator(student) |
---|
[8112] | 846 | data = [] |
---|
| 847 | doc_title = view.label |
---|
| 848 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 849 | view.request.principal.id) |
---|
[9913] | 850 | footer_text = view.label.split('\n') |
---|
[16126] | 851 | if len(footer_text) > 2: |
---|
[13304] | 852 | # We can add a department in first line, second line is used |
---|
[9913] | 853 | footer_text = footer_text[1] |
---|
| 854 | else: |
---|
[9917] | 855 | # Only the first line is used for the footer |
---|
[9913] | 856 | footer_text = footer_text[0] |
---|
[7714] | 857 | if getattr(student, 'student_id', None) is not None: |
---|
[7310] | 858 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
[7150] | 859 | |
---|
[7318] | 860 | # Insert student data table |
---|
[7310] | 861 | if student is not None: |
---|
[15988] | 862 | if view.form_fields: |
---|
| 863 | bd_translation = trans(_('Base Data'), portal_language) |
---|
| 864 | data.append(Paragraph(bd_translation, HEADING_STYLE)) |
---|
[10261] | 865 | data.append(render_student_data( |
---|
[11550] | 866 | studentview, view.context, omit_fields, lang=portal_language, |
---|
| 867 | slipname=filename)) |
---|
[7304] | 868 | |
---|
[7318] | 869 | # Insert widgets |
---|
[9191] | 870 | if view.form_fields: |
---|
[9910] | 871 | data.append(Paragraph(view.title, HEADING_STYLE)) |
---|
[9191] | 872 | separators = getattr(self, 'SEPARATORS_DICT', {}) |
---|
| 873 | table = creator.getWidgetsTable( |
---|
| 874 | view.form_fields, view.context, None, lang=portal_language, |
---|
| 875 | separators=separators) |
---|
| 876 | data.append(table) |
---|
[7318] | 877 | |
---|
[8112] | 878 | # Insert scanned docs |
---|
[9550] | 879 | if show_scans: |
---|
| 880 | data.extend(docs_as_flowables(view, portal_language)) |
---|
[7318] | 881 | |
---|
[9452] | 882 | # Insert history |
---|
[15337] | 883 | if filename == 'clearance_slip.pdf': |
---|
[9452] | 884 | hist_translation = trans(_('Workflow History'), portal_language) |
---|
[9910] | 885 | data.append(Paragraph(hist_translation, HEADING_STYLE)) |
---|
[9452] | 886 | data.extend(creator.fromStringList(student.history.messages)) |
---|
| 887 | |
---|
[10438] | 888 | # Insert content tables (optionally on second page) |
---|
[10439] | 889 | if hasattr(view, 'tabletitle'): |
---|
| 890 | for i in range(len(view.tabletitle)): |
---|
| 891 | if tabledata[i] and tableheader[i]: |
---|
[15984] | 892 | tabletitle = view.tabletitle[i] |
---|
| 893 | if tabletitle.startswith('_PB_'): |
---|
| 894 | data.append(PageBreak()) |
---|
| 895 | tabletitle = view.tabletitle[i].strip('_PB_') |
---|
[10439] | 896 | #data.append(Spacer(1, 20)) |
---|
[15984] | 897 | data.append(Paragraph(tabletitle, HEADING_STYLE)) |
---|
[10439] | 898 | data.append(Spacer(1, 8)) |
---|
| 899 | contenttable = render_table_data(tableheader[i],tabledata[i]) |
---|
| 900 | data.append(contenttable) |
---|
[7318] | 901 | |
---|
[9010] | 902 | # Insert signatures |
---|
[9965] | 903 | # XXX: We are using only sigs_in_footer in waeup.kofa, so we |
---|
| 904 | # do not have a test for the following lines. |
---|
[9555] | 905 | if signatures and not sigs_in_footer: |
---|
[16291] | 906 | # Insert page break if necessary, else some space |
---|
| 907 | if pagebreak: |
---|
| 908 | data.append(PageBreak()) |
---|
| 909 | else: |
---|
| 910 | data.append(Spacer(1, 20)) |
---|
[9966] | 911 | # Render one signature table per signature to |
---|
| 912 | # get date and signature in line. |
---|
| 913 | for signature in signatures: |
---|
| 914 | signaturetables = get_signature_tables(signature) |
---|
| 915 | data.append(signaturetables[0]) |
---|
[9010] | 916 | |
---|
[7150] | 917 | view.response.setHeader( |
---|
| 918 | 'Content-Type', 'application/pdf') |
---|
[8112] | 919 | try: |
---|
| 920 | pdf_stream = creator.create_pdf( |
---|
[8257] | 921 | data, None, doc_title, author=author, footer=footer_text, |
---|
[9948] | 922 | note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin) |
---|
[8112] | 923 | except IOError: |
---|
| 924 | view.flash('Error in image file.') |
---|
| 925 | return view.redirect(view.url(view.context)) |
---|
[14256] | 926 | except LayoutError, err: |
---|
| 927 | view.flash( |
---|
| 928 | 'PDF file could not be created. Reportlab error message: %s' |
---|
| 929 | % escape(err.message), |
---|
| 930 | type="danger") |
---|
| 931 | return view.redirect(view.url(view.context)) |
---|
[16253] | 932 | if mergefiles: |
---|
[16254] | 933 | return self._mergeFiles(mergefiles, watermark, pdf_stream) |
---|
[8112] | 934 | return pdf_stream |
---|
[7620] | 935 | |
---|
[15879] | 936 | def _admissionText(self, student, portal_language): |
---|
| 937 | inst_name = grok.getSite()['configuration'].name |
---|
| 938 | text = trans(_( |
---|
[17564] | 939 | 'This is to inform you that you have been provisionally admitted into' |
---|
| 940 | ' ${a} as follows:', mapping = {'a': inst_name}), |
---|
[15879] | 941 | portal_language) |
---|
| 942 | return text |
---|
[10576] | 943 | |
---|
[15879] | 944 | def renderPDFAdmissionLetter(self, view, student=None, omit_fields=(), |
---|
[15880] | 945 | pre_text=None, post_text=None, |
---|
[15889] | 946 | topMargin = 1.5, |
---|
[16157] | 947 | letterhead_path=None, |
---|
| 948 | mergefiles=None, watermark=None): |
---|
[15879] | 949 | """Render pdf admission letter. |
---|
[14461] | 950 | """ |
---|
[15879] | 951 | if student is None: |
---|
| 952 | return |
---|
| 953 | style = getSampleStyleSheet() |
---|
[15880] | 954 | if letterhead_path: |
---|
| 955 | creator = getUtility(IPDFCreator, name='letter') |
---|
| 956 | else: |
---|
[15888] | 957 | creator = self.getPDFCreator(student) |
---|
[15879] | 958 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 959 | data = [] |
---|
| 960 | doc_title = view.label |
---|
| 961 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 962 | view.request.principal.id) |
---|
| 963 | footer_text = view.label.split('\n') |
---|
[16126] | 964 | if len(footer_text) > 2: |
---|
[15879] | 965 | # We can add a department in first line |
---|
| 966 | footer_text = footer_text[1] |
---|
| 967 | else: |
---|
| 968 | # Only the first line is used for the footer |
---|
| 969 | footer_text = footer_text[0] |
---|
| 970 | if getattr(student, 'student_id', None) is not None: |
---|
| 971 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
[10445] | 972 | |
---|
[15879] | 973 | # Text before student data |
---|
| 974 | if pre_text is None: |
---|
| 975 | html = format_html(self._admissionText(student, portal_language)) |
---|
| 976 | else: |
---|
| 977 | html = format_html(pre_text) |
---|
| 978 | if html: |
---|
| 979 | data.append(Paragraph(html, NOTE_STYLE)) |
---|
| 980 | data.append(Spacer(1, 20)) |
---|
[14157] | 981 | |
---|
[15879] | 982 | # Student data |
---|
| 983 | data.append(render_student_data(view, student, |
---|
| 984 | omit_fields, lang=portal_language, |
---|
| 985 | slipname='admission_slip.pdf')) |
---|
[15163] | 986 | |
---|
[15879] | 987 | # Text after student data |
---|
| 988 | data.append(Spacer(1, 20)) |
---|
| 989 | if post_text is None: |
---|
| 990 | datelist = student.history.messages[0].split()[0].split('-') |
---|
| 991 | creation_date = u'%s/%s/%s' % (datelist[2], datelist[1], datelist[0]) |
---|
| 992 | post_text = trans(_( |
---|
| 993 | 'Your Kofa student record was created on ${a}.', |
---|
| 994 | mapping = {'a': creation_date}), |
---|
| 995 | portal_language) |
---|
| 996 | #html = format_html(post_text) |
---|
| 997 | #data.append(Paragraph(html, NOTE_STYLE)) |
---|
| 998 | |
---|
| 999 | # Create pdf stream |
---|
| 1000 | view.response.setHeader( |
---|
| 1001 | 'Content-Type', 'application/pdf') |
---|
| 1002 | pdf_stream = creator.create_pdf( |
---|
| 1003 | data, None, doc_title, author=author, footer=footer_text, |
---|
[15889] | 1004 | note=post_text, topMargin=topMargin, |
---|
| 1005 | letterhead_path=letterhead_path) |
---|
[16157] | 1006 | if mergefiles: |
---|
[16254] | 1007 | return self._mergeFiles(mergefiles, watermark, pdf_stream) |
---|
[15879] | 1008 | return pdf_stream |
---|
| 1009 | |
---|
[10250] | 1010 | def renderPDFTranscript(self, view, filename='transcript.pdf', |
---|
| 1011 | student=None, |
---|
| 1012 | studentview=None, |
---|
[15163] | 1013 | note=None, |
---|
| 1014 | signatures=(), |
---|
| 1015 | sigs_in_footer=(), |
---|
| 1016 | digital_sigs=(), |
---|
[10250] | 1017 | show_scans=True, topMargin=1.5, |
---|
| 1018 | omit_fields=(), |
---|
[14292] | 1019 | tableheader=None, |
---|
[15163] | 1020 | no_passport=False, |
---|
| 1021 | save_file=False): |
---|
[14583] | 1022 | """Render pdf slip of a transcripts. |
---|
[10250] | 1023 | """ |
---|
[10261] | 1024 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[10250] | 1025 | # XXX: tell what the different parameters mean |
---|
| 1026 | style = getSampleStyleSheet() |
---|
| 1027 | creator = self.getPDFCreator(student) |
---|
| 1028 | data = [] |
---|
| 1029 | doc_title = view.label |
---|
| 1030 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 1031 | view.request.principal.id) |
---|
| 1032 | footer_text = view.label.split('\n') |
---|
| 1033 | if len(footer_text) > 2: |
---|
| 1034 | # We can add a department in first line |
---|
| 1035 | footer_text = footer_text[1] |
---|
| 1036 | else: |
---|
| 1037 | # Only the first line is used for the footer |
---|
| 1038 | footer_text = footer_text[0] |
---|
| 1039 | if getattr(student, 'student_id', None) is not None: |
---|
| 1040 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
| 1041 | |
---|
| 1042 | # Insert student data table |
---|
| 1043 | if student is not None: |
---|
| 1044 | #bd_translation = trans(_('Base Data'), portal_language) |
---|
| 1045 | #data.append(Paragraph(bd_translation, HEADING_STYLE)) |
---|
[10261] | 1046 | data.append(render_student_data( |
---|
[11550] | 1047 | studentview, view.context, |
---|
| 1048 | omit_fields, lang=portal_language, |
---|
[14292] | 1049 | slipname=filename, |
---|
| 1050 | no_passport=no_passport)) |
---|
[10250] | 1051 | |
---|
| 1052 | transcript_data = view.context.getTranscriptData() |
---|
| 1053 | levels_data = transcript_data[0] |
---|
| 1054 | |
---|
| 1055 | contextdata = [] |
---|
[10261] | 1056 | f_label = trans(_('Course of Study:'), portal_language) |
---|
[10250] | 1057 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10650] | 1058 | f_text = formatted_text(view.context.certificate.longtitle) |
---|
[10250] | 1059 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 1060 | contextdata.append([f_label,f_text]) |
---|
| 1061 | |
---|
[10261] | 1062 | f_label = trans(_('Faculty:'), portal_language) |
---|
[10250] | 1063 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 1064 | f_text = formatted_text( |
---|
[10650] | 1065 | view.context.certificate.__parent__.__parent__.__parent__.longtitle) |
---|
[10250] | 1066 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 1067 | contextdata.append([f_label,f_text]) |
---|
| 1068 | |
---|
[10261] | 1069 | f_label = trans(_('Department:'), portal_language) |
---|
[10250] | 1070 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 1071 | f_text = formatted_text( |
---|
[10650] | 1072 | view.context.certificate.__parent__.__parent__.longtitle) |
---|
[10250] | 1073 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 1074 | contextdata.append([f_label,f_text]) |
---|
| 1075 | |
---|
[10261] | 1076 | f_label = trans(_('Entry Session:'), portal_language) |
---|
[10250] | 1077 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10256] | 1078 | f_text = formatted_text( |
---|
| 1079 | view.session_dict.get(view.context.entry_session)) |
---|
[10250] | 1080 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 1081 | contextdata.append([f_label,f_text]) |
---|
| 1082 | |
---|
[10261] | 1083 | f_label = trans(_('Entry Mode:'), portal_language) |
---|
[10250] | 1084 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10256] | 1085 | f_text = formatted_text(view.studymode_dict.get( |
---|
| 1086 | view.context.entry_mode)) |
---|
[10250] | 1087 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 1088 | contextdata.append([f_label,f_text]) |
---|
| 1089 | |
---|
[10262] | 1090 | f_label = trans(_('Cumulative GPA:'), portal_language) |
---|
[10250] | 1091 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[14473] | 1092 | format_float = getUtility(IKofaUtils).format_float |
---|
| 1093 | cgpa = format_float(transcript_data[1], 3) |
---|
[15881] | 1094 | if student.state == GRADUATED: |
---|
| 1095 | f_text = formatted_text('%s (%s)' % ( |
---|
| 1096 | cgpa, self.getClassFromCGPA(transcript_data[1], student)[1])) |
---|
| 1097 | else: |
---|
| 1098 | f_text = formatted_text('%s' % cgpa) |
---|
[17497] | 1099 | if not transcript_data[1]: |
---|
| 1100 | f_text = formatted_text('No results yet!') |
---|
[10250] | 1101 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 1102 | contextdata.append([f_label,f_text]) |
---|
| 1103 | |
---|
| 1104 | contexttable = Table(contextdata,style=SLIP_STYLE) |
---|
| 1105 | data.append(contexttable) |
---|
| 1106 | |
---|
[17497] | 1107 | if transcript_data[1]: |
---|
| 1108 | transcripttables = render_transcript_data( |
---|
| 1109 | view, tableheader, levels_data, lang=portal_language) |
---|
| 1110 | data.extend(transcripttables) |
---|
[10250] | 1111 | |
---|
| 1112 | # Insert signatures |
---|
| 1113 | # XXX: We are using only sigs_in_footer in waeup.kofa, so we |
---|
| 1114 | # do not have a test for the following lines. |
---|
| 1115 | if signatures and not sigs_in_footer: |
---|
| 1116 | data.append(Spacer(1, 20)) |
---|
| 1117 | # Render one signature table per signature to |
---|
| 1118 | # get date and signature in line. |
---|
| 1119 | for signature in signatures: |
---|
| 1120 | signaturetables = get_signature_tables(signature) |
---|
| 1121 | data.append(signaturetables[0]) |
---|
| 1122 | |
---|
[15163] | 1123 | # Insert digital signatures |
---|
| 1124 | if digital_sigs: |
---|
| 1125 | data.append(Spacer(1, 20)) |
---|
| 1126 | sigs = digital_sigs.split('\n') |
---|
| 1127 | for sig in sigs: |
---|
| 1128 | data.append(Paragraph(sig, NOTE_STYLE)) |
---|
| 1129 | |
---|
[10250] | 1130 | view.response.setHeader( |
---|
| 1131 | 'Content-Type', 'application/pdf') |
---|
| 1132 | try: |
---|
| 1133 | pdf_stream = creator.create_pdf( |
---|
| 1134 | data, None, doc_title, author=author, footer=footer_text, |
---|
[16966] | 1135 | note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin, |
---|
| 1136 | view=view) |
---|
[10250] | 1137 | except IOError: |
---|
[10261] | 1138 | view.flash(_('Error in image file.')) |
---|
[10250] | 1139 | return view.redirect(view.url(view.context)) |
---|
[15163] | 1140 | if save_file: |
---|
| 1141 | self._saveTranscriptPDF(student, pdf_stream) |
---|
| 1142 | return |
---|
[10250] | 1143 | return pdf_stream |
---|
| 1144 | |
---|
[13898] | 1145 | def renderPDFCourseticketsOverview( |
---|
[15423] | 1146 | self, view, name, session, data, lecturers, orientation, |
---|
[17842] | 1147 | title_length, note, |
---|
| 1148 | signatures=(), |
---|
| 1149 | sigs_in_footer=(),): |
---|
[14583] | 1150 | """Render pdf slip of course tickets for a lecturer. |
---|
| 1151 | """ |
---|
[15423] | 1152 | filename = '%s_%s_%s_%s.pdf' % ( |
---|
| 1153 | name, view.context.code, session, view.request.principal.id) |
---|
[15662] | 1154 | try: |
---|
| 1155 | session = academic_sessions_vocab.getTerm(session).title |
---|
| 1156 | except LookupError: |
---|
| 1157 | session = _('void') |
---|
[14702] | 1158 | creator = getUtility(IPDFCreator, name=orientation) |
---|
[13898] | 1159 | style = getSampleStyleSheet() |
---|
[15197] | 1160 | pdf_data = [] |
---|
| 1161 | pdf_data += [Paragraph( |
---|
[14151] | 1162 | translate(_('<b>Lecturer(s): ${a}</b>', |
---|
| 1163 | mapping = {'a':lecturers})), style["Normal"]),] |
---|
| 1164 | pdf_data += [Paragraph( |
---|
| 1165 | translate(_('<b>Credits: ${a}</b>', |
---|
| 1166 | mapping = {'a':view.context.credits})), style["Normal"]),] |
---|
[14314] | 1167 | # Not used in base package. |
---|
| 1168 | if data[1]: |
---|
| 1169 | pdf_data += [Paragraph( |
---|
[14709] | 1170 | translate(_('<b>${a}</b>', |
---|
[14314] | 1171 | mapping = {'a':data[1][0]})), style["Normal"]),] |
---|
| 1172 | pdf_data += [Paragraph( |
---|
[14709] | 1173 | translate(_('<b>${a}</b>', |
---|
[14708] | 1174 | mapping = {'a':data[1][1]})), style["Normal"]),] |
---|
| 1175 | pdf_data += [Paragraph( |
---|
| 1176 | translate(_('<b>Total Students: ${a}</b>', |
---|
| 1177 | mapping = {'a':data[1][2]})), style["Normal"]),] |
---|
| 1178 | pdf_data += [Paragraph( |
---|
[14319] | 1179 | translate(_('<b>Total Pass: ${a} (${b}%)</b>', |
---|
[14708] | 1180 | mapping = {'a':data[1][3],'b':data[1][4]})), style["Normal"]),] |
---|
[14319] | 1181 | pdf_data += [Paragraph( |
---|
| 1182 | translate(_('<b>Total Fail: ${a} (${b}%)</b>', |
---|
[14708] | 1183 | mapping = {'a':data[1][5],'b':data[1][6]})), style["Normal"]),] |
---|
[15821] | 1184 | grade_stats = [] |
---|
[15823] | 1185 | for item in sorted(data[1][7].items()): |
---|
[15821] | 1186 | grade_stats.append(('%s=%s' % (item[0], item[1]))) |
---|
| 1187 | grade_stats_string = ', '.join(grade_stats) |
---|
| 1188 | pdf_data += [Paragraph( |
---|
| 1189 | translate(_('<b>${a}</b>', |
---|
| 1190 | mapping = {'a':grade_stats_string})), style["Normal"]),] |
---|
[13899] | 1191 | pdf_data.append(Spacer(1, 20)) |
---|
[15246] | 1192 | colWidths = [None] * len(data[0][0]) |
---|
[15528] | 1193 | pdf_data += [Table(data[0], colWidths=colWidths, style=CONTENT_STYLE, |
---|
| 1194 | repeatRows=1)] |
---|
[15234] | 1195 | # Process title if too long |
---|
| 1196 | title = " ".join(view.context.title.split()) |
---|
| 1197 | ct = textwrap.fill(title, title_length) |
---|
[15526] | 1198 | ft = "" # title |
---|
| 1199 | #if len(textwrap.wrap(title, title_length)) > 1: |
---|
| 1200 | # ft = textwrap.wrap(title, title_length)[0] + ' ...' |
---|
[15197] | 1201 | doc_title = translate(_('${a} (${b})\nAcademic Session ${d}', |
---|
| 1202 | mapping = {'a':ct, |
---|
[14151] | 1203 | 'b':view.context.code, |
---|
| 1204 | 'd':session})) |
---|
[15423] | 1205 | if name == 'attendance': |
---|
[15618] | 1206 | doc_title += '\n' + translate(_('Attendance Sheet')) |
---|
[15423] | 1207 | if name == 'coursetickets': |
---|
[15618] | 1208 | doc_title += '\n' + translate(_('Course Tickets Overview')) |
---|
[15526] | 1209 | #footer_title = translate(_('${a} (${b}) - ${d}', |
---|
| 1210 | # mapping = {'a':ft, |
---|
| 1211 | # 'b':view.context.code, |
---|
| 1212 | # 'd':session})) |
---|
| 1213 | footer_title = translate(_('${b} - ${d}', |
---|
| 1214 | mapping = {'b':view.context.code, |
---|
[14705] | 1215 | 'd':session})) |
---|
[13898] | 1216 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 1217 | view.request.principal.id) |
---|
[17842] | 1218 | |
---|
| 1219 | # Insert signatures |
---|
| 1220 | # XXX: Not used in waeup.kofa, so we |
---|
| 1221 | # do not have a test for the following lines. |
---|
| 1222 | if signatures and not sigs_in_footer: |
---|
| 1223 | pdf_data.append(Spacer(1, 20)) |
---|
| 1224 | # Render one signature table per signature to |
---|
| 1225 | # get date and signature in line. |
---|
| 1226 | for signature in signatures: |
---|
| 1227 | signaturetables = get_signature_tables(signature) |
---|
| 1228 | pdf_data.append(signaturetables[0]) |
---|
| 1229 | |
---|
[13898] | 1230 | view.response.setHeader( |
---|
| 1231 | 'Content-Type', 'application/pdf') |
---|
| 1232 | view.response.setHeader( |
---|
| 1233 | 'Content-Disposition:', 'attachment; filename="%s' % filename) |
---|
| 1234 | pdf_stream = creator.create_pdf( |
---|
[17842] | 1235 | pdf_data, None, doc_title, author, footer_title + ' -', note, |
---|
| 1236 | sigs_in_footer=sigs_in_footer, |
---|
[13898] | 1237 | ) |
---|
| 1238 | return pdf_stream |
---|
| 1239 | |
---|
[15998] | 1240 | def updateCourseTickets(self, course): |
---|
| 1241 | """Udate course tickets if course attributes were changed. |
---|
| 1242 | """ |
---|
| 1243 | current_academic_session = grok.getSite()[ |
---|
| 1244 | 'configuration'].current_academic_session |
---|
| 1245 | if not current_academic_session: |
---|
| 1246 | return |
---|
| 1247 | cat = queryUtility(ICatalog, name='coursetickets_catalog') |
---|
| 1248 | coursetickets = cat.searchResults( |
---|
| 1249 | code=(course.code, course.code), |
---|
| 1250 | session=(current_academic_session,current_academic_session)) |
---|
| 1251 | number = 0 |
---|
| 1252 | ob_class = self.__implemented__.__name__.replace('waeup.kofa.', '') |
---|
| 1253 | for ticket in coursetickets: |
---|
| 1254 | if ticket.credits == course.credits: |
---|
| 1255 | continue |
---|
| 1256 | if ticket.student.current_session != current_academic_session: |
---|
| 1257 | continue |
---|
| 1258 | if ticket.student.state not in (PAID,): |
---|
| 1259 | continue |
---|
| 1260 | number += 1 |
---|
| 1261 | ticket.student.__parent__.logger.info( |
---|
| 1262 | '%s - %s %s/%s credits updated (%s->%s)' % ( |
---|
| 1263 | ob_class, ticket.student.student_id, |
---|
| 1264 | ticket.level, ticket.code, course.credits, |
---|
| 1265 | ticket.credits)) |
---|
| 1266 | ticket.credits = course.credits |
---|
| 1267 | return number |
---|
| 1268 | |
---|
[17867] | 1269 | def final_clearance_enabled(self, student): |
---|
[17917] | 1270 | # disabled in base package but can be enabled in tests |
---|
| 1271 | if getattr(student,'browsertest', None) == True: |
---|
| 1272 | return True |
---|
[17868] | 1273 | return False |
---|
[17867] | 1274 | |
---|
[13132] | 1275 | #: A dictionary which maps widget names to headlines. The headline |
---|
| 1276 | #: is rendered in forms and on pdf slips above the respective |
---|
| 1277 | #: display or input widget. There are no separating headlines |
---|
| 1278 | #: in the base package. |
---|
[13129] | 1279 | SEPARATORS_DICT = {} |
---|
[8410] | 1280 | |
---|
[13132] | 1281 | #: A tuple containing names of file upload viewlets which are not shown |
---|
| 1282 | #: on the `StudentClearanceManageFormPage`. Nothing is being skipped |
---|
| 1283 | #: in the base package. This attribute makes only sense, if intermediate |
---|
| 1284 | #: custom packages are being used, like we do for all Nigerian portals. |
---|
[10021] | 1285 | SKIP_UPLOAD_VIEWLETS = () |
---|
| 1286 | |
---|
[13132] | 1287 | #: A tuple containing the names of registration states in which changing of |
---|
| 1288 | #: passport pictures is allowed. |
---|
[13129] | 1289 | PORTRAIT_CHANGE_STATES = (ADMITTED,) |
---|
[10706] | 1290 | |
---|
[16609] | 1291 | #: A tuple containing the names of registration states in which changing of |
---|
| 1292 | #: scanned signatures is allowed. |
---|
| 1293 | SIGNATURE_CHANGE_STATES = () |
---|
| 1294 | |
---|
[12104] | 1295 | #: A tuple containing all exporter names referring to students or |
---|
| 1296 | #: subobjects thereof. |
---|
[15920] | 1297 | STUDENT_EXPORTER_NAMES = ( |
---|
| 1298 | 'students', |
---|
| 1299 | 'studentstudycourses', |
---|
[16847] | 1300 | 'studentstudycourses_1', |
---|
[16827] | 1301 | #'studentstudycourses_2', |
---|
[15920] | 1302 | 'studentstudylevels', |
---|
[16827] | 1303 | #'studentstudylevels_1', |
---|
| 1304 | #'studentstudylevels_2', |
---|
[15920] | 1305 | 'coursetickets', |
---|
[16827] | 1306 | #'coursetickets_1', |
---|
| 1307 | #'coursetickets_2', |
---|
[15920] | 1308 | 'studentpayments', |
---|
| 1309 | 'bedtickets', |
---|
[15966] | 1310 | 'trimmed', |
---|
[15920] | 1311 | 'outstandingcourses', |
---|
| 1312 | 'unpaidpayments', |
---|
| 1313 | 'sfpaymentsoverview', |
---|
| 1314 | 'sessionpaymentsoverview', |
---|
| 1315 | 'studylevelsoverview', |
---|
| 1316 | 'combocard', |
---|
| 1317 | 'bursary', |
---|
| 1318 | 'accommodationpayments', |
---|
[15979] | 1319 | 'transcriptdata', |
---|
[16034] | 1320 | 'trimmedpayments', |
---|
[15979] | 1321 | ) |
---|
[12104] | 1322 | |
---|
[12971] | 1323 | #: A tuple containing all exporter names needed for backing |
---|
| 1324 | #: up student data |
---|
[16827] | 1325 | STUDENT_BACKUP_EXPORTER_NAMES = ( |
---|
| 1326 | 'students', |
---|
| 1327 | 'studentstudycourses', |
---|
| 1328 | 'studentstudycourses_1', |
---|
| 1329 | 'studentstudycourses_2', |
---|
| 1330 | 'studentstudylevels', |
---|
| 1331 | 'studentstudylevels_1', |
---|
| 1332 | 'studentstudylevels_2', |
---|
| 1333 | 'coursetickets', |
---|
| 1334 | 'coursetickets_1', |
---|
| 1335 | 'coursetickets_2', |
---|
| 1336 | 'studentpayments', |
---|
| 1337 | 'bedtickets') |
---|
[12971] | 1338 | |
---|
[15652] | 1339 | # Maximum size of upload files in kB |
---|
| 1340 | MAX_KB = 250 |
---|
| 1341 | |
---|
[8410] | 1342 | #: A prefix used when generating new student ids. Each student id will |
---|
[13129] | 1343 | #: start with this string. The default is 'K' for Kofa. |
---|
[8410] | 1344 | STUDENT_ID_PREFIX = u'K' |
---|