[7191] | 1 | ## $Id: utils.py 12902 2015-05-05 04:37:21Z 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 | ## |
---|
[7358] | 18 | """General helper functions and utilities for the student section. |
---|
[6651] | 19 | """ |
---|
[7150] | 20 | import grok |
---|
[8595] | 21 | from time import time |
---|
[7318] | 22 | from reportlab.lib import colors |
---|
[7019] | 23 | from reportlab.lib.units import cm |
---|
| 24 | from reportlab.lib.pagesizes import A4 |
---|
[9015] | 25 | from reportlab.lib.styles import getSampleStyleSheet |
---|
| 26 | from reportlab.platypus import Paragraph, Image, Table, Spacer |
---|
[11589] | 27 | from zope.event import notify |
---|
[9922] | 28 | from zope.schema.interfaces import ConstraintNotSatisfied |
---|
[9015] | 29 | from zope.component import getUtility, createObject |
---|
[7019] | 30 | from zope.formlib.form import setUpEditWidgets |
---|
[9015] | 31 | from zope.i18n import translate |
---|
[8596] | 32 | from waeup.kofa.interfaces import ( |
---|
[9762] | 33 | IExtFileStore, IKofaUtils, RETURNING, PAID, CLEARED, |
---|
| 34 | academic_sessions_vocab) |
---|
[7811] | 35 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
| 36 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[10706] | 37 | from waeup.kofa.students.workflow import ADMITTED |
---|
[11589] | 38 | from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource |
---|
[9910] | 39 | from waeup.kofa.browser.pdf import ( |
---|
[9965] | 40 | ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, |
---|
[11550] | 41 | get_signature_tables, get_qrcode) |
---|
[9910] | 42 | from waeup.kofa.browser.interfaces import IPDFCreator |
---|
[10256] | 43 | from waeup.kofa.utils.helpers import to_timezone |
---|
[6651] | 44 | |
---|
[7318] | 45 | SLIP_STYLE = [ |
---|
| 46 | ('VALIGN',(0,0),(-1,-1),'TOP'), |
---|
| 47 | #('FONT', (0,0), (-1,-1), 'Helvetica', 11), |
---|
| 48 | ] |
---|
[7019] | 49 | |
---|
[7318] | 50 | CONTENT_STYLE = [ |
---|
| 51 | ('VALIGN',(0,0),(-1,-1),'TOP'), |
---|
| 52 | #('FONT', (0,0), (-1,-1), 'Helvetica', 8), |
---|
| 53 | #('TEXTCOLOR',(0,0),(-1,0),colors.white), |
---|
[9906] | 54 | #('BACKGROUND',(0,0),(-1,0),colors.black), |
---|
| 55 | ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), |
---|
| 56 | ('BOX', (0,0), (-1,-1), 1, colors.black), |
---|
| 57 | |
---|
[7318] | 58 | ] |
---|
[7304] | 59 | |
---|
[7318] | 60 | FONT_SIZE = 10 |
---|
| 61 | FONT_COLOR = 'black' |
---|
| 62 | |
---|
[8112] | 63 | def trans(text, lang): |
---|
| 64 | # shortcut |
---|
| 65 | return translate(text, 'waeup.kofa', target_language=lang) |
---|
| 66 | |
---|
[10261] | 67 | def formatted_text(text, color=FONT_COLOR, lang='en'): |
---|
[7511] | 68 | """Turn `text`, `color` and `size` into an HTML snippet. |
---|
[7318] | 69 | |
---|
[7511] | 70 | The snippet is suitable for use with reportlab and generating PDFs. |
---|
| 71 | Wraps the `text` into a ``<font>`` tag with passed attributes. |
---|
| 72 | |
---|
| 73 | Also non-strings are converted. Raw strings are expected to be |
---|
| 74 | utf-8 encoded (usually the case for widgets etc.). |
---|
| 75 | |
---|
[7804] | 76 | Finally, a br tag is added if widgets contain div tags |
---|
| 77 | which are not supported by reportlab. |
---|
| 78 | |
---|
[7511] | 79 | The returned snippet is unicode type. |
---|
| 80 | """ |
---|
| 81 | if not isinstance(text, unicode): |
---|
| 82 | if isinstance(text, basestring): |
---|
| 83 | text = text.decode('utf-8') |
---|
| 84 | else: |
---|
| 85 | text = unicode(text) |
---|
[9717] | 86 | if text == 'None': |
---|
| 87 | text = '' |
---|
[8141] | 88 | # Mainly for boolean values we need our customized |
---|
| 89 | # localisation of the zope domain |
---|
[10261] | 90 | text = translate(text, 'zope', target_language=lang) |
---|
[7804] | 91 | text = text.replace('</div>', '<br /></div>') |
---|
[9910] | 92 | tag1 = u'<font color="%s">' % (color) |
---|
[7511] | 93 | return tag1 + u'%s</font>' % text |
---|
| 94 | |
---|
[8481] | 95 | def generate_student_id(): |
---|
[8410] | 96 | students = grok.getSite()['students'] |
---|
| 97 | new_id = students.unique_student_id |
---|
| 98 | return new_id |
---|
[6742] | 99 | |
---|
[7186] | 100 | def set_up_widgets(view, ignore_request=False): |
---|
[7019] | 101 | view.adapters = {} |
---|
| 102 | view.widgets = setUpEditWidgets( |
---|
| 103 | view.form_fields, view.prefix, view.context, view.request, |
---|
| 104 | adapters=view.adapters, for_display=True, |
---|
| 105 | ignore_request=ignore_request |
---|
| 106 | ) |
---|
| 107 | |
---|
[11550] | 108 | def render_student_data(studentview, context, omit_fields=(), |
---|
| 109 | lang='en', slipname=None): |
---|
[7318] | 110 | """Render student table for an existing frame. |
---|
| 111 | """ |
---|
| 112 | width, height = A4 |
---|
[7186] | 113 | set_up_widgets(studentview, ignore_request=True) |
---|
[7318] | 114 | data_left = [] |
---|
[11550] | 115 | data_middle = [] |
---|
[7019] | 116 | style = getSampleStyleSheet() |
---|
[7280] | 117 | img = getUtility(IExtFileStore).getFileByContext( |
---|
| 118 | studentview.context, attr='passport.jpg') |
---|
| 119 | if img is None: |
---|
[7811] | 120 | from waeup.kofa.browser import DEFAULT_PASSPORT_IMAGE_PATH |
---|
[7280] | 121 | img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb') |
---|
[7318] | 122 | doc_img = Image(img.name, width=4*cm, height=4*cm, kind='bound') |
---|
| 123 | data_left.append([doc_img]) |
---|
| 124 | #data.append([Spacer(1, 12)]) |
---|
[9141] | 125 | |
---|
[10261] | 126 | f_label = trans(_('Name:'), lang) |
---|
[9910] | 127 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[9911] | 128 | f_text = formatted_text(studentview.context.display_fullname) |
---|
[9910] | 129 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 130 | data_middle.append([f_label,f_text]) |
---|
[9141] | 131 | |
---|
[7019] | 132 | for widget in studentview.widgets: |
---|
[9141] | 133 | if 'name' in widget.name: |
---|
[7019] | 134 | continue |
---|
[9911] | 135 | f_label = translate( |
---|
[7811] | 136 | widget.label.strip(), 'waeup.kofa', |
---|
[10261] | 137 | target_language=lang) |
---|
[9911] | 138 | f_label = Paragraph('%s:' % f_label, ENTRY1_STYLE) |
---|
[10261] | 139 | f_text = formatted_text(widget(), lang=lang) |
---|
[9910] | 140 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 141 | data_middle.append([f_label,f_text]) |
---|
[9141] | 142 | |
---|
[9452] | 143 | if getattr(studentview.context, 'certcode', None): |
---|
[10250] | 144 | if not 'certificate' in omit_fields: |
---|
[10261] | 145 | f_label = trans(_('Study Course:'), lang) |
---|
[10250] | 146 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 147 | f_text = formatted_text( |
---|
[10650] | 148 | studentview.context['studycourse'].certificate.longtitle) |
---|
[10250] | 149 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 150 | data_middle.append([f_label,f_text]) |
---|
[10250] | 151 | if not 'department' in omit_fields: |
---|
[10261] | 152 | f_label = trans(_('Department:'), lang) |
---|
[10250] | 153 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 154 | f_text = formatted_text( |
---|
| 155 | studentview.context[ |
---|
[10650] | 156 | 'studycourse'].certificate.__parent__.__parent__.longtitle, |
---|
[10250] | 157 | ) |
---|
| 158 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 159 | data_middle.append([f_label,f_text]) |
---|
[10250] | 160 | if not 'faculty' in omit_fields: |
---|
[10261] | 161 | f_label = trans(_('Faculty:'), lang) |
---|
[10250] | 162 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 163 | f_text = formatted_text( |
---|
| 164 | studentview.context[ |
---|
[10650] | 165 | 'studycourse'].certificate.__parent__.__parent__.__parent__.longtitle, |
---|
[10250] | 166 | ) |
---|
| 167 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 168 | data_middle.append([f_label,f_text]) |
---|
[10688] | 169 | if not 'current_mode' in omit_fields: |
---|
| 170 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[11535] | 171 | sm = studymodes_dict[studentview.context.current_mode] |
---|
[10688] | 172 | f_label = trans(_('Study Mode:'), lang) |
---|
| 173 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 174 | f_text = formatted_text(sm) |
---|
| 175 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 176 | data_middle.append([f_label,f_text]) |
---|
[10250] | 177 | if not 'entry_session' in omit_fields: |
---|
[10261] | 178 | f_label = trans(_('Entry Session:'), lang) |
---|
[10250] | 179 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[11535] | 180 | entry_session = studentview.context.entry_session |
---|
[10250] | 181 | entry_session = academic_sessions_vocab.getTerm(entry_session).title |
---|
| 182 | f_text = formatted_text(entry_session) |
---|
| 183 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 184 | data_middle.append([f_label,f_text]) |
---|
[11535] | 185 | # Requested by Uniben, does not really make sense |
---|
| 186 | if not 'current_level' in omit_fields: |
---|
| 187 | f_label = trans(_('Current Level:'), lang) |
---|
| 188 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 189 | current_level = studentview.context['studycourse'].current_level |
---|
| 190 | studylevelsource = StudyLevelSource().factory |
---|
| 191 | current_level = studylevelsource.getTitle( |
---|
| 192 | studentview.context, current_level) |
---|
| 193 | f_text = formatted_text(current_level) |
---|
| 194 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 195 | data_middle.append([f_label,f_text]) |
---|
[10256] | 196 | if not 'date_of_birth' in omit_fields: |
---|
[10261] | 197 | f_label = trans(_('Date of Birth:'), lang) |
---|
[10256] | 198 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 199 | date_of_birth = studentview.context.date_of_birth |
---|
| 200 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 201 | date_of_birth = to_timezone(date_of_birth, tz) |
---|
| 202 | if date_of_birth is not None: |
---|
| 203 | date_of_birth = date_of_birth.strftime("%d/%m/%Y") |
---|
| 204 | f_text = formatted_text(date_of_birth) |
---|
| 205 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
[11550] | 206 | data_middle.append([f_label,f_text]) |
---|
[9141] | 207 | |
---|
[11550] | 208 | # append QR code to the right |
---|
| 209 | if slipname: |
---|
| 210 | url = studentview.url(context, slipname) |
---|
| 211 | data_right = [[get_qrcode(url, width=70.0)]] |
---|
| 212 | table_right = Table(data_right,style=SLIP_STYLE) |
---|
| 213 | else: |
---|
| 214 | table_right = None |
---|
| 215 | |
---|
[7318] | 216 | table_left = Table(data_left,style=SLIP_STYLE) |
---|
[11550] | 217 | table_middle = Table(data_middle,style=SLIP_STYLE, colWidths=[5*cm, 5*cm]) |
---|
| 218 | table = Table([[table_left, table_middle, table_right],],style=SLIP_STYLE) |
---|
[7019] | 219 | return table |
---|
| 220 | |
---|
[10261] | 221 | def render_table_data(tableheader, tabledata, lang='en'): |
---|
[7318] | 222 | """Render children table for an existing frame. |
---|
| 223 | """ |
---|
[7304] | 224 | data = [] |
---|
[7318] | 225 | #data.append([Spacer(1, 12)]) |
---|
[7304] | 226 | line = [] |
---|
| 227 | style = getSampleStyleSheet() |
---|
| 228 | for element in tableheader: |
---|
[10261] | 229 | field = '<strong>%s</strong>' % formatted_text(element[0], lang=lang) |
---|
[7310] | 230 | field = Paragraph(field, style["Normal"]) |
---|
[7304] | 231 | line.append(field) |
---|
| 232 | data.append(line) |
---|
| 233 | for ticket in tabledata: |
---|
| 234 | line = [] |
---|
| 235 | for element in tableheader: |
---|
[7511] | 236 | field = formatted_text(getattr(ticket,element[1],u' ')) |
---|
[7318] | 237 | field = Paragraph(field, style["Normal"]) |
---|
[7304] | 238 | line.append(field) |
---|
| 239 | data.append(line) |
---|
[7310] | 240 | table = Table(data,colWidths=[ |
---|
[7318] | 241 | element[2]*cm for element in tableheader], style=CONTENT_STYLE) |
---|
[7304] | 242 | return table |
---|
| 243 | |
---|
[10261] | 244 | def render_transcript_data(view, tableheader, levels_data, lang='en'): |
---|
[10250] | 245 | """Render children table for an existing frame. |
---|
| 246 | """ |
---|
| 247 | data = [] |
---|
| 248 | style = getSampleStyleSheet() |
---|
| 249 | for level in levels_data: |
---|
| 250 | level_obj = level['level'] |
---|
[10251] | 251 | tickets = level['tickets_1'] + level['tickets_2'] + level['tickets_3'] |
---|
| 252 | headerline = [] |
---|
| 253 | tabledata = [] |
---|
[10261] | 254 | subheader = '%s %s, %s %s' % ( |
---|
| 255 | trans(_('Session'), lang), |
---|
[10250] | 256 | view.session_dict[level_obj.level_session], |
---|
[10261] | 257 | trans(_('Level'), lang), |
---|
[10266] | 258 | view.level_dict[level_obj.level]) |
---|
[10250] | 259 | data.append(Paragraph(subheader, HEADING_STYLE)) |
---|
| 260 | for element in tableheader: |
---|
| 261 | field = '<strong>%s</strong>' % formatted_text(element[0]) |
---|
| 262 | field = Paragraph(field, style["Normal"]) |
---|
[10251] | 263 | headerline.append(field) |
---|
| 264 | tabledata.append(headerline) |
---|
[10250] | 265 | for ticket in tickets: |
---|
[10251] | 266 | ticketline = [] |
---|
[10250] | 267 | for element in tableheader: |
---|
| 268 | field = formatted_text(getattr(ticket,element[1],u' ')) |
---|
| 269 | field = Paragraph(field, style["Normal"]) |
---|
[10251] | 270 | ticketline.append(field) |
---|
| 271 | tabledata.append(ticketline) |
---|
[10250] | 272 | table = Table(tabledata,colWidths=[ |
---|
| 273 | element[2]*cm for element in tableheader], style=CONTENT_STYLE) |
---|
| 274 | data.append(table) |
---|
[10479] | 275 | sgpa = '%s: %s' % (trans('Sessional GPA (rectified)', lang), level['sgpa']) |
---|
[10261] | 276 | data.append(Paragraph(sgpa, style["Normal"])) |
---|
[10250] | 277 | return data |
---|
| 278 | |
---|
[8112] | 279 | def docs_as_flowables(view, lang='en'): |
---|
| 280 | """Create reportlab flowables out of scanned docs. |
---|
| 281 | """ |
---|
| 282 | # XXX: fix circular import problem |
---|
[12448] | 283 | from waeup.kofa.browser.fileviewlets import FileManager |
---|
[8112] | 284 | from waeup.kofa.browser import DEFAULT_IMAGE_PATH |
---|
| 285 | style = getSampleStyleSheet() |
---|
| 286 | data = [] |
---|
[7318] | 287 | |
---|
[8112] | 288 | # Collect viewlets |
---|
| 289 | fm = FileManager(view.context, view.request, view) |
---|
| 290 | fm.update() |
---|
| 291 | if fm.viewlets: |
---|
| 292 | sc_translation = trans(_('Scanned Documents'), lang) |
---|
[9910] | 293 | data.append(Paragraph(sc_translation, HEADING_STYLE)) |
---|
[8112] | 294 | # Insert list of scanned documents |
---|
| 295 | table_data = [] |
---|
| 296 | for viewlet in fm.viewlets: |
---|
[10020] | 297 | if viewlet.file_exists: |
---|
| 298 | # Show viewlet only if file exists |
---|
| 299 | f_label = Paragraph(trans(viewlet.label, lang), ENTRY1_STYLE) |
---|
| 300 | img_path = getattr(getUtility(IExtFileStore).getFileByContext( |
---|
| 301 | view.context, attr=viewlet.download_name), 'name', None) |
---|
| 302 | #f_text = Paragraph(trans(_('(not provided)'),lang), ENTRY1_STYLE) |
---|
| 303 | if img_path is None: |
---|
| 304 | pass |
---|
| 305 | elif not img_path[-4:] in ('.jpg', '.JPG'): |
---|
| 306 | # reportlab requires jpg images, I think. |
---|
| 307 | f_text = Paragraph('%s (not displayable)' % ( |
---|
| 308 | viewlet.title,), ENTRY1_STYLE) |
---|
| 309 | else: |
---|
| 310 | f_text = Image(img_path, width=2*cm, height=1*cm, kind='bound') |
---|
| 311 | table_data.append([f_label, f_text]) |
---|
[8112] | 312 | if table_data: |
---|
| 313 | # safety belt; empty tables lead to problems. |
---|
| 314 | data.append(Table(table_data, style=SLIP_STYLE)) |
---|
| 315 | return data |
---|
| 316 | |
---|
[7150] | 317 | class StudentsUtils(grok.GlobalUtility): |
---|
| 318 | """A collection of methods subject to customization. |
---|
| 319 | """ |
---|
| 320 | grok.implements(IStudentsUtils) |
---|
[7019] | 321 | |
---|
[8268] | 322 | def getReturningData(self, student): |
---|
[9005] | 323 | """ Define what happens after school fee payment |
---|
[7841] | 324 | depending on the student's senate verdict. |
---|
| 325 | |
---|
| 326 | In the base configuration current level is always increased |
---|
| 327 | by 100 no matter which verdict has been assigned. |
---|
| 328 | """ |
---|
[8268] | 329 | new_level = student['studycourse'].current_level + 100 |
---|
| 330 | new_session = student['studycourse'].current_session + 1 |
---|
| 331 | return new_session, new_level |
---|
| 332 | |
---|
| 333 | def setReturningData(self, student): |
---|
[9005] | 334 | """ Define what happens after school fee payment |
---|
| 335 | depending on the student's senate verdict. |
---|
[8268] | 336 | |
---|
[9005] | 337 | This method folllows the same algorithm as getReturningData but |
---|
| 338 | it also sets the new values. |
---|
[8268] | 339 | """ |
---|
| 340 | new_session, new_level = self.getReturningData(student) |
---|
[9922] | 341 | try: |
---|
| 342 | student['studycourse'].current_level = new_level |
---|
| 343 | except ConstraintNotSatisfied: |
---|
| 344 | # Do not change level if level exceeds the |
---|
| 345 | # certificate's end_level. |
---|
| 346 | pass |
---|
[8268] | 347 | student['studycourse'].current_session = new_session |
---|
[7615] | 348 | verdict = student['studycourse'].current_verdict |
---|
[8820] | 349 | student['studycourse'].current_verdict = '0' |
---|
[7615] | 350 | student['studycourse'].previous_verdict = verdict |
---|
| 351 | return |
---|
| 352 | |
---|
[9519] | 353 | def _getSessionConfiguration(self, session): |
---|
| 354 | try: |
---|
| 355 | return grok.getSite()['configuration'][str(session)] |
---|
| 356 | except KeyError: |
---|
| 357 | return None |
---|
| 358 | |
---|
[11451] | 359 | def _isPaymentDisabled(self, p_session, category, student): |
---|
| 360 | academic_session = self._getSessionConfiguration(p_session) |
---|
[11452] | 361 | if category == 'schoolfee' and \ |
---|
| 362 | 'sf_all' in academic_session.payment_disabled: |
---|
[11451] | 363 | return True |
---|
| 364 | return False |
---|
| 365 | |
---|
[11641] | 366 | def samePaymentMade(self, student, category, p_item, p_session): |
---|
| 367 | for key in student['payments'].keys(): |
---|
| 368 | ticket = student['payments'][key] |
---|
| 369 | if ticket.p_state == 'paid' and\ |
---|
| 370 | ticket.p_category == category and \ |
---|
| 371 | ticket.p_item == p_item and \ |
---|
| 372 | ticket.p_session == p_session: |
---|
| 373 | return True |
---|
| 374 | return False |
---|
| 375 | |
---|
[9148] | 376 | def setPaymentDetails(self, category, student, |
---|
[9151] | 377 | previous_session, previous_level): |
---|
[8595] | 378 | """Create Payment object and set the payment data of a student for |
---|
| 379 | the payment category specified. |
---|
| 380 | |
---|
[7841] | 381 | """ |
---|
[8595] | 382 | p_item = u'' |
---|
| 383 | amount = 0.0 |
---|
[9148] | 384 | if previous_session: |
---|
[9517] | 385 | if previous_session < student['studycourse'].entry_session: |
---|
| 386 | return _('The previous session must not fall below ' |
---|
| 387 | 'your entry session.'), None |
---|
| 388 | if category == 'schoolfee': |
---|
| 389 | # School fee is always paid for the following session |
---|
| 390 | if previous_session > student['studycourse'].current_session: |
---|
| 391 | return _('This is not a previous session.'), None |
---|
| 392 | else: |
---|
| 393 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 394 | return _('This is not a previous session.'), None |
---|
[9148] | 395 | p_session = previous_session |
---|
| 396 | p_level = previous_level |
---|
| 397 | p_current = False |
---|
| 398 | else: |
---|
| 399 | p_session = student['studycourse'].current_session |
---|
| 400 | p_level = student['studycourse'].current_level |
---|
| 401 | p_current = True |
---|
[9519] | 402 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 403 | if academic_session == None: |
---|
[8595] | 404 | return _(u'Session configuration object is not available.'), None |
---|
[9521] | 405 | # Determine fee. |
---|
[7150] | 406 | if category == 'schoolfee': |
---|
[8595] | 407 | try: |
---|
[8596] | 408 | certificate = student['studycourse'].certificate |
---|
| 409 | p_item = certificate.code |
---|
[8595] | 410 | except (AttributeError, TypeError): |
---|
| 411 | return _('Study course data are incomplete.'), None |
---|
[9148] | 412 | if previous_session: |
---|
[9916] | 413 | # Students can pay for previous sessions in all |
---|
| 414 | # workflow states. Fresh students are excluded by the |
---|
| 415 | # update method of the PreviousPaymentAddFormPage. |
---|
[9148] | 416 | if previous_level == 100: |
---|
| 417 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 418 | else: |
---|
| 419 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 420 | else: |
---|
| 421 | if student.state == CLEARED: |
---|
| 422 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 423 | elif student.state == RETURNING: |
---|
[9916] | 424 | # In case of returning school fee payment the |
---|
| 425 | # payment session and level contain the values of |
---|
| 426 | # the session the student has paid for. Payment |
---|
| 427 | # session is always next session. |
---|
[9148] | 428 | p_session, p_level = self.getReturningData(student) |
---|
[9519] | 429 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 430 | if academic_session == None: |
---|
[9916] | 431 | return _( |
---|
| 432 | u'Session configuration object is not available.' |
---|
| 433 | ), None |
---|
[9148] | 434 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
| 435 | elif student.is_postgrad and student.state == PAID: |
---|
[9916] | 436 | # Returning postgraduate students also pay for the |
---|
| 437 | # next session but their level always remains the |
---|
| 438 | # same. |
---|
[9148] | 439 | p_session += 1 |
---|
[9519] | 440 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 441 | if academic_session == None: |
---|
[9916] | 442 | return _( |
---|
| 443 | u'Session configuration object is not available.' |
---|
| 444 | ), None |
---|
[9148] | 445 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[7150] | 446 | elif category == 'clearance': |
---|
[9178] | 447 | try: |
---|
| 448 | p_item = student['studycourse'].certificate.code |
---|
| 449 | except (AttributeError, TypeError): |
---|
| 450 | return _('Study course data are incomplete.'), None |
---|
[8595] | 451 | amount = academic_session.clearance_fee |
---|
[7150] | 452 | elif category == 'bed_allocation': |
---|
[8595] | 453 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
| 454 | amount = academic_session.booking_fee |
---|
[9423] | 455 | elif category == 'hostel_maintenance': |
---|
[10681] | 456 | amount = 0.0 |
---|
[9429] | 457 | bedticket = student['accommodation'].get( |
---|
| 458 | str(student.current_session), None) |
---|
| 459 | if bedticket: |
---|
| 460 | p_item = bedticket.bed_coordinates |
---|
[10681] | 461 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
| 462 | amount = bedticket.bed.__parent__.maint_fee |
---|
| 463 | else: |
---|
| 464 | # fallback |
---|
| 465 | amount = academic_session.maint_fee |
---|
[9429] | 466 | else: |
---|
| 467 | # Should not happen because this is already checked |
---|
| 468 | # in the browser module, but anyway ... |
---|
| 469 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 470 | p_item = trans(_('no bed allocated'), portal_language) |
---|
[10449] | 471 | elif category == 'transcript': |
---|
| 472 | amount = academic_session.transcript_fee |
---|
[8595] | 473 | if amount in (0.0, None): |
---|
[9517] | 474 | return _('Amount could not be determined.'), None |
---|
[11641] | 475 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 476 | return _('This type of payment has already been made.'), None |
---|
[11451] | 477 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 478 | return _('Payment temporarily disabled.'), None |
---|
[8708] | 479 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8951] | 480 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8595] | 481 | payment.p_id = "p%s" % timestamp |
---|
| 482 | payment.p_category = category |
---|
| 483 | payment.p_item = p_item |
---|
| 484 | payment.p_session = p_session |
---|
| 485 | payment.p_level = p_level |
---|
[9148] | 486 | payment.p_current = p_current |
---|
[8595] | 487 | payment.amount_auth = amount |
---|
| 488 | return None, payment |
---|
[7019] | 489 | |
---|
[9868] | 490 | def setBalanceDetails(self, category, student, |
---|
[9864] | 491 | balance_session, balance_level, balance_amount): |
---|
| 492 | """Create Payment object and set the payment data of a student for. |
---|
| 493 | |
---|
| 494 | """ |
---|
[9868] | 495 | p_item = u'Balance' |
---|
[9864] | 496 | p_session = balance_session |
---|
| 497 | p_level = balance_level |
---|
| 498 | p_current = False |
---|
| 499 | amount = balance_amount |
---|
| 500 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 501 | if academic_session == None: |
---|
| 502 | return _(u'Session configuration object is not available.'), None |
---|
[9874] | 503 | if amount in (0.0, None) or amount < 0: |
---|
| 504 | return _('Amount must be greater than 0.'), None |
---|
[11641] | 505 | if self.samePaymentMade(student, 'balance', p_item, p_session): |
---|
| 506 | return _('This type of payment has already been made.'), None |
---|
[9864] | 507 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 508 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 509 | payment.p_id = "p%s" % timestamp |
---|
[9868] | 510 | payment.p_category = category |
---|
[9864] | 511 | payment.p_item = p_item |
---|
| 512 | payment.p_session = p_session |
---|
| 513 | payment.p_level = p_level |
---|
| 514 | payment.p_current = p_current |
---|
| 515 | payment.amount_auth = amount |
---|
| 516 | return None, payment |
---|
| 517 | |
---|
[12896] | 518 | def increaseMatricInteger(self, student): |
---|
| 519 | """Increase counter for matric numbers. |
---|
| 520 | |
---|
| 521 | This counter can be a centrally stored attribute or an attribute of |
---|
| 522 | faculties, departments or certificates. In the base package the counter |
---|
| 523 | is as an attribute of the site configuration object. |
---|
| 524 | """ |
---|
| 525 | grok.getSite()['configuration'].next_matric_integer += 1 |
---|
| 526 | return |
---|
| 527 | |
---|
[11595] | 528 | def constructMatricNumber(self, student): |
---|
[12896] | 529 | """Fetch the matric number counter which fits the student and |
---|
| 530 | construct the new matric number of the student. |
---|
| 531 | |
---|
[12902] | 532 | In the base package the counter is returned which is as an attribute |
---|
| 533 | of the site configuration object. |
---|
[12896] | 534 | """ |
---|
[11595] | 535 | next_integer = grok.getSite()['configuration'].next_matric_integer |
---|
| 536 | if next_integer == 0: |
---|
[11619] | 537 | return _('Matriculation number cannot be set.'), None |
---|
| 538 | return None, unicode(next_integer) |
---|
[11589] | 539 | |
---|
| 540 | def setMatricNumber(self, student): |
---|
| 541 | """Set matriculation number of student. |
---|
| 542 | |
---|
| 543 | If the student's matric number is unset a new matric number is |
---|
[12896] | 544 | constructed according to the matriculation number construction rules |
---|
| 545 | defined in the constructMatricNumber method. The new matric number is |
---|
| 546 | set, the students catalog updated. The corresponding matric number |
---|
| 547 | counter is increased by one. |
---|
[11589] | 548 | |
---|
| 549 | This method is tested but not used in the base package. It can |
---|
| 550 | be used in custom packages by adding respective views |
---|
[12896] | 551 | and by customizing increaseMatricInteger and constructMatricNumber |
---|
| 552 | according to the university's matriculation number construction rules. |
---|
[11589] | 553 | |
---|
[12896] | 554 | The method can be disabled by setting the counter to zero. |
---|
[11589] | 555 | """ |
---|
| 556 | if student.matric_number is not None: |
---|
| 557 | return _('Matriculation number already set.'), None |
---|
[11590] | 558 | if student.certcode is None: |
---|
| 559 | return _('No certificate assigned.'), None |
---|
[11619] | 560 | error, matric_number = self.constructMatricNumber(student) |
---|
| 561 | if error: |
---|
| 562 | return error, None |
---|
[11589] | 563 | try: |
---|
[11592] | 564 | student.matric_number = matric_number |
---|
[11589] | 565 | except MatNumNotInSource: |
---|
| 566 | return _('Matriculation number exists.'), None |
---|
| 567 | notify(grok.ObjectModifiedEvent(student)) |
---|
[12896] | 568 | self.increaseMatricInteger(student) |
---|
[11595] | 569 | return None, matric_number |
---|
[11589] | 570 | |
---|
[7186] | 571 | def getAccommodationDetails(self, student): |
---|
[9219] | 572 | """Determine the accommodation data of a student. |
---|
[7841] | 573 | """ |
---|
[7150] | 574 | d = {} |
---|
| 575 | d['error'] = u'' |
---|
[8685] | 576 | hostels = grok.getSite()['hostels'] |
---|
| 577 | d['booking_session'] = hostels.accommodation_session |
---|
| 578 | d['allowed_states'] = hostels.accommodation_states |
---|
[8688] | 579 | d['startdate'] = hostels.startdate |
---|
| 580 | d['enddate'] = hostels.enddate |
---|
| 581 | d['expired'] = hostels.expired |
---|
[7150] | 582 | # Determine bed type |
---|
| 583 | studycourse = student['studycourse'] |
---|
[7369] | 584 | certificate = getattr(studycourse,'certificate',None) |
---|
[7150] | 585 | entry_session = studycourse.entry_session |
---|
| 586 | current_level = studycourse.current_level |
---|
[9187] | 587 | if None in (entry_session, current_level, certificate): |
---|
| 588 | return d |
---|
[7369] | 589 | end_level = certificate.end_level |
---|
[9148] | 590 | if current_level == 10: |
---|
| 591 | bt = 'pr' |
---|
| 592 | elif entry_session == grok.getSite()['hostels'].accommodation_session: |
---|
[7150] | 593 | bt = 'fr' |
---|
| 594 | elif current_level >= end_level: |
---|
| 595 | bt = 'fi' |
---|
| 596 | else: |
---|
| 597 | bt = 're' |
---|
| 598 | if student.sex == 'f': |
---|
| 599 | sex = 'female' |
---|
| 600 | else: |
---|
| 601 | sex = 'male' |
---|
| 602 | special_handling = 'regular' |
---|
| 603 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 604 | return d |
---|
[7019] | 605 | |
---|
[7186] | 606 | def selectBed(self, available_beds): |
---|
[7841] | 607 | """Select a bed from a list of available beds. |
---|
| 608 | |
---|
| 609 | In the base configuration we select the first bed found, |
---|
| 610 | but can also randomize the selection if we like. |
---|
| 611 | """ |
---|
[7150] | 612 | return available_beds[0] |
---|
| 613 | |
---|
[9981] | 614 | def _admissionText(self, student, portal_language): |
---|
[9979] | 615 | inst_name = grok.getSite()['configuration'].name |
---|
| 616 | text = trans(_( |
---|
| 617 | 'This is to inform you that you have been provisionally' |
---|
| 618 | ' admitted into ${a} as follows:', mapping = {'a': inst_name}), |
---|
| 619 | portal_language) |
---|
| 620 | return text |
---|
| 621 | |
---|
[10686] | 622 | def renderPDFAdmissionLetter(self, view, student=None, omit_fields=(), |
---|
| 623 | pre_text=None, post_text=None,): |
---|
[9191] | 624 | """Render pdf admission letter. |
---|
| 625 | """ |
---|
| 626 | if student is None: |
---|
| 627 | return |
---|
| 628 | style = getSampleStyleSheet() |
---|
[9949] | 629 | creator = self.getPDFCreator(student) |
---|
[9979] | 630 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9191] | 631 | data = [] |
---|
| 632 | doc_title = view.label |
---|
| 633 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 634 | view.request.principal.id) |
---|
[9944] | 635 | footer_text = view.label.split('\n') |
---|
| 636 | if len(footer_text) > 1: |
---|
| 637 | # We can add a department in first line |
---|
| 638 | footer_text = footer_text[1] |
---|
| 639 | else: |
---|
| 640 | # Only the first line is used for the footer |
---|
| 641 | footer_text = footer_text[0] |
---|
[9191] | 642 | if getattr(student, 'student_id', None) is not None: |
---|
| 643 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
| 644 | |
---|
[10702] | 645 | # Text before student data |
---|
[10686] | 646 | if pre_text is None: |
---|
| 647 | html = format_html(self._admissionText(student, portal_language)) |
---|
| 648 | else: |
---|
| 649 | html = format_html(pre_text) |
---|
[11875] | 650 | if html: |
---|
| 651 | data.append(Paragraph(html, NOTE_STYLE)) |
---|
| 652 | data.append(Spacer(1, 20)) |
---|
[9191] | 653 | |
---|
| 654 | # Student data |
---|
[11550] | 655 | data.append(render_student_data(view, student, |
---|
| 656 | omit_fields, lang=portal_language, |
---|
| 657 | slipname='admission_slip.pdf')) |
---|
[9191] | 658 | |
---|
[10702] | 659 | # Text after student data |
---|
[9191] | 660 | data.append(Spacer(1, 20)) |
---|
[10686] | 661 | if post_text is None: |
---|
| 662 | datelist = student.history.messages[0].split()[0].split('-') |
---|
| 663 | creation_date = u'%s/%s/%s' % (datelist[2], datelist[1], datelist[0]) |
---|
[10702] | 664 | post_text = trans(_( |
---|
[10686] | 665 | 'Your Kofa student record was created on ${a}.', |
---|
| 666 | mapping = {'a': creation_date}), |
---|
| 667 | portal_language) |
---|
[10702] | 668 | #html = format_html(post_text) |
---|
| 669 | #data.append(Paragraph(html, NOTE_STYLE)) |
---|
[9191] | 670 | |
---|
| 671 | # Create pdf stream |
---|
| 672 | view.response.setHeader( |
---|
| 673 | 'Content-Type', 'application/pdf') |
---|
| 674 | pdf_stream = creator.create_pdf( |
---|
| 675 | data, None, doc_title, author=author, footer=footer_text, |
---|
[10702] | 676 | note=post_text) |
---|
[9191] | 677 | return pdf_stream |
---|
| 678 | |
---|
[9949] | 679 | def getPDFCreator(self, context): |
---|
| 680 | """Get a pdf creator suitable for `context`. |
---|
| 681 | |
---|
| 682 | The default implementation always returns the default creator. |
---|
| 683 | """ |
---|
| 684 | return getUtility(IPDFCreator) |
---|
| 685 | |
---|
[8257] | 686 | def renderPDF(self, view, filename='slip.pdf', student=None, |
---|
[9906] | 687 | studentview=None, |
---|
[10439] | 688 | tableheader=[], tabledata=[], |
---|
[9555] | 689 | note=None, signatures=None, sigs_in_footer=(), |
---|
[10250] | 690 | show_scans=True, topMargin=1.5, |
---|
| 691 | omit_fields=()): |
---|
[7841] | 692 | """Render pdf slips for various pages. |
---|
| 693 | """ |
---|
[10261] | 694 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[9916] | 695 | # XXX: tell what the different parameters mean |
---|
[8112] | 696 | style = getSampleStyleSheet() |
---|
[9949] | 697 | creator = self.getPDFCreator(student) |
---|
[8112] | 698 | data = [] |
---|
| 699 | doc_title = view.label |
---|
| 700 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 701 | view.request.principal.id) |
---|
[9913] | 702 | footer_text = view.label.split('\n') |
---|
| 703 | if len(footer_text) > 2: |
---|
| 704 | # We can add a department in first line |
---|
| 705 | footer_text = footer_text[1] |
---|
| 706 | else: |
---|
[9917] | 707 | # Only the first line is used for the footer |
---|
[9913] | 708 | footer_text = footer_text[0] |
---|
[7714] | 709 | if getattr(student, 'student_id', None) is not None: |
---|
[7310] | 710 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
[7150] | 711 | |
---|
[7318] | 712 | # Insert student data table |
---|
[7310] | 713 | if student is not None: |
---|
[8112] | 714 | bd_translation = trans(_('Base Data'), portal_language) |
---|
[9910] | 715 | data.append(Paragraph(bd_translation, HEADING_STYLE)) |
---|
[10261] | 716 | data.append(render_student_data( |
---|
[11550] | 717 | studentview, view.context, omit_fields, lang=portal_language, |
---|
| 718 | slipname=filename)) |
---|
[7304] | 719 | |
---|
[7318] | 720 | # Insert widgets |
---|
[9191] | 721 | if view.form_fields: |
---|
[9910] | 722 | data.append(Paragraph(view.title, HEADING_STYLE)) |
---|
[9191] | 723 | separators = getattr(self, 'SEPARATORS_DICT', {}) |
---|
| 724 | table = creator.getWidgetsTable( |
---|
| 725 | view.form_fields, view.context, None, lang=portal_language, |
---|
| 726 | separators=separators) |
---|
| 727 | data.append(table) |
---|
[7318] | 728 | |
---|
[8112] | 729 | # Insert scanned docs |
---|
[9550] | 730 | if show_scans: |
---|
| 731 | data.extend(docs_as_flowables(view, portal_language)) |
---|
[7318] | 732 | |
---|
[9452] | 733 | # Insert history |
---|
[9910] | 734 | if filename.startswith('clearance'): |
---|
[9452] | 735 | hist_translation = trans(_('Workflow History'), portal_language) |
---|
[9910] | 736 | data.append(Paragraph(hist_translation, HEADING_STYLE)) |
---|
[9452] | 737 | data.extend(creator.fromStringList(student.history.messages)) |
---|
| 738 | |
---|
[10438] | 739 | # Insert content tables (optionally on second page) |
---|
[10439] | 740 | if hasattr(view, 'tabletitle'): |
---|
| 741 | for i in range(len(view.tabletitle)): |
---|
| 742 | if tabledata[i] and tableheader[i]: |
---|
| 743 | #data.append(PageBreak()) |
---|
| 744 | #data.append(Spacer(1, 20)) |
---|
| 745 | data.append(Paragraph(view.tabletitle[i], HEADING_STYLE)) |
---|
| 746 | data.append(Spacer(1, 8)) |
---|
| 747 | contenttable = render_table_data(tableheader[i],tabledata[i]) |
---|
| 748 | data.append(contenttable) |
---|
[7318] | 749 | |
---|
[9010] | 750 | # Insert signatures |
---|
[9965] | 751 | # XXX: We are using only sigs_in_footer in waeup.kofa, so we |
---|
| 752 | # do not have a test for the following lines. |
---|
[9555] | 753 | if signatures and not sigs_in_footer: |
---|
[9010] | 754 | data.append(Spacer(1, 20)) |
---|
[9966] | 755 | # Render one signature table per signature to |
---|
| 756 | # get date and signature in line. |
---|
| 757 | for signature in signatures: |
---|
| 758 | signaturetables = get_signature_tables(signature) |
---|
| 759 | data.append(signaturetables[0]) |
---|
[9010] | 760 | |
---|
[7150] | 761 | view.response.setHeader( |
---|
| 762 | 'Content-Type', 'application/pdf') |
---|
[8112] | 763 | try: |
---|
| 764 | pdf_stream = creator.create_pdf( |
---|
[8257] | 765 | data, None, doc_title, author=author, footer=footer_text, |
---|
[9948] | 766 | note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin) |
---|
[8112] | 767 | except IOError: |
---|
| 768 | view.flash('Error in image file.') |
---|
| 769 | return view.redirect(view.url(view.context)) |
---|
| 770 | return pdf_stream |
---|
[7620] | 771 | |
---|
[10578] | 772 | gpa_boundaries = ((1, 'Fail'), |
---|
| 773 | (1.5, 'Pass'), |
---|
| 774 | (2.4, '3rd Class'), |
---|
| 775 | (3.5, '2nd Class Lower'), |
---|
| 776 | (4.5, '2nd Class Upper'), |
---|
| 777 | (5, '1st Class')) |
---|
[10576] | 778 | |
---|
[10445] | 779 | def getClassFromCGPA(self, gpa): |
---|
[10578] | 780 | if gpa < self.gpa_boundaries[0][0]: |
---|
| 781 | return 0, self.gpa_boundaries[0][1] |
---|
| 782 | if gpa < self.gpa_boundaries[1][0]: |
---|
| 783 | return 1, self.gpa_boundaries[1][1] |
---|
| 784 | if gpa < self.gpa_boundaries[2][0]: |
---|
| 785 | return 2, self.gpa_boundaries[2][1] |
---|
| 786 | if gpa < self.gpa_boundaries[3][0]: |
---|
| 787 | return 3, self.gpa_boundaries[3][1] |
---|
| 788 | if gpa < self.gpa_boundaries[4][0]: |
---|
| 789 | return 4, self.gpa_boundaries[4][1] |
---|
| 790 | if gpa <= self.gpa_boundaries[5][0]: |
---|
| 791 | return 5, self.gpa_boundaries[5][1] |
---|
| 792 | return 'N/A' |
---|
[10445] | 793 | |
---|
[10250] | 794 | def renderPDFTranscript(self, view, filename='transcript.pdf', |
---|
| 795 | student=None, |
---|
| 796 | studentview=None, |
---|
| 797 | note=None, signatures=None, sigs_in_footer=(), |
---|
| 798 | show_scans=True, topMargin=1.5, |
---|
| 799 | omit_fields=(), |
---|
| 800 | tableheader=None): |
---|
| 801 | """Render pdf slips for transcript. |
---|
| 802 | """ |
---|
[10261] | 803 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
[10250] | 804 | # XXX: tell what the different parameters mean |
---|
| 805 | style = getSampleStyleSheet() |
---|
| 806 | creator = self.getPDFCreator(student) |
---|
| 807 | data = [] |
---|
| 808 | doc_title = view.label |
---|
| 809 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 810 | view.request.principal.id) |
---|
| 811 | footer_text = view.label.split('\n') |
---|
| 812 | if len(footer_text) > 2: |
---|
| 813 | # We can add a department in first line |
---|
| 814 | footer_text = footer_text[1] |
---|
| 815 | else: |
---|
| 816 | # Only the first line is used for the footer |
---|
| 817 | footer_text = footer_text[0] |
---|
| 818 | if getattr(student, 'student_id', None) is not None: |
---|
| 819 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
| 820 | |
---|
| 821 | # Insert student data table |
---|
| 822 | if student is not None: |
---|
| 823 | #bd_translation = trans(_('Base Data'), portal_language) |
---|
| 824 | #data.append(Paragraph(bd_translation, HEADING_STYLE)) |
---|
[10261] | 825 | data.append(render_student_data( |
---|
[11550] | 826 | studentview, view.context, |
---|
| 827 | omit_fields, lang=portal_language, |
---|
| 828 | slipname=filename)) |
---|
[10250] | 829 | |
---|
| 830 | transcript_data = view.context.getTranscriptData() |
---|
| 831 | levels_data = transcript_data[0] |
---|
| 832 | gpa = transcript_data[1] |
---|
| 833 | |
---|
| 834 | contextdata = [] |
---|
[10261] | 835 | f_label = trans(_('Course of Study:'), portal_language) |
---|
[10250] | 836 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10650] | 837 | f_text = formatted_text(view.context.certificate.longtitle) |
---|
[10250] | 838 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 839 | contextdata.append([f_label,f_text]) |
---|
| 840 | |
---|
[10261] | 841 | f_label = trans(_('Faculty:'), portal_language) |
---|
[10250] | 842 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 843 | f_text = formatted_text( |
---|
[10650] | 844 | view.context.certificate.__parent__.__parent__.__parent__.longtitle) |
---|
[10250] | 845 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 846 | contextdata.append([f_label,f_text]) |
---|
| 847 | |
---|
[10261] | 848 | f_label = trans(_('Department:'), portal_language) |
---|
[10250] | 849 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 850 | f_text = formatted_text( |
---|
[10650] | 851 | view.context.certificate.__parent__.__parent__.longtitle) |
---|
[10250] | 852 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 853 | contextdata.append([f_label,f_text]) |
---|
| 854 | |
---|
[10261] | 855 | f_label = trans(_('Entry Session:'), portal_language) |
---|
[10250] | 856 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10256] | 857 | f_text = formatted_text( |
---|
| 858 | view.session_dict.get(view.context.entry_session)) |
---|
[10250] | 859 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 860 | contextdata.append([f_label,f_text]) |
---|
| 861 | |
---|
[10261] | 862 | f_label = trans(_('Entry Mode:'), portal_language) |
---|
[10250] | 863 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10256] | 864 | f_text = formatted_text(view.studymode_dict.get( |
---|
| 865 | view.context.entry_mode)) |
---|
[10250] | 866 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 867 | contextdata.append([f_label,f_text]) |
---|
| 868 | |
---|
[10262] | 869 | f_label = trans(_('Cumulative GPA:'), portal_language) |
---|
[10250] | 870 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
[10576] | 871 | f_text = formatted_text('%s (%s)' % (gpa, self.getClassFromCGPA(gpa)[1])) |
---|
[10250] | 872 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 873 | contextdata.append([f_label,f_text]) |
---|
| 874 | |
---|
| 875 | contexttable = Table(contextdata,style=SLIP_STYLE) |
---|
| 876 | data.append(contexttable) |
---|
| 877 | |
---|
| 878 | transcripttables = render_transcript_data( |
---|
[10261] | 879 | view, tableheader, levels_data, lang=portal_language) |
---|
[10250] | 880 | data.extend(transcripttables) |
---|
| 881 | |
---|
| 882 | # Insert signatures |
---|
| 883 | # XXX: We are using only sigs_in_footer in waeup.kofa, so we |
---|
| 884 | # do not have a test for the following lines. |
---|
| 885 | if signatures and not sigs_in_footer: |
---|
| 886 | data.append(Spacer(1, 20)) |
---|
| 887 | # Render one signature table per signature to |
---|
| 888 | # get date and signature in line. |
---|
| 889 | for signature in signatures: |
---|
| 890 | signaturetables = get_signature_tables(signature) |
---|
| 891 | data.append(signaturetables[0]) |
---|
| 892 | |
---|
| 893 | view.response.setHeader( |
---|
| 894 | 'Content-Type', 'application/pdf') |
---|
| 895 | try: |
---|
| 896 | pdf_stream = creator.create_pdf( |
---|
| 897 | data, None, doc_title, author=author, footer=footer_text, |
---|
| 898 | note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin) |
---|
| 899 | except IOError: |
---|
[10261] | 900 | view.flash(_('Error in image file.')) |
---|
[10250] | 901 | return view.redirect(view.url(view.context)) |
---|
| 902 | return pdf_stream |
---|
| 903 | |
---|
[9830] | 904 | def maxCredits(self, studylevel): |
---|
| 905 | """Return maximum credits. |
---|
[9532] | 906 | |
---|
[9830] | 907 | In some universities maximum credits is not constant, it |
---|
[12048] | 908 | depends on the student's study level. Set maxCredits None or 0 |
---|
| 909 | in order to deactivate the limitation. |
---|
[9830] | 910 | """ |
---|
| 911 | return 50 |
---|
| 912 | |
---|
[9532] | 913 | def maxCreditsExceeded(self, studylevel, course): |
---|
[9830] | 914 | max_credits = self.maxCredits(studylevel) |
---|
| 915 | if max_credits and \ |
---|
| 916 | studylevel.total_credits + course.credits > max_credits: |
---|
| 917 | return max_credits |
---|
[9532] | 918 | return 0 |
---|
| 919 | |
---|
[9987] | 920 | def getBedCoordinates(self, bedticket): |
---|
| 921 | """Return bed coordinates. |
---|
| 922 | |
---|
| 923 | This method can be used to customize the display_coordinates |
---|
| 924 | property method. |
---|
| 925 | """ |
---|
| 926 | return bedticket.bed_coordinates |
---|
| 927 | |
---|
[11772] | 928 | def clearance_disabled_message(self, student): |
---|
| 929 | try: |
---|
| 930 | session_config = grok.getSite()[ |
---|
| 931 | 'configuration'][str(student.current_session)] |
---|
| 932 | except KeyError: |
---|
| 933 | return _('Session configuration object is not available.') |
---|
| 934 | if not session_config.clearance_enabled: |
---|
| 935 | return _('Clearance is disabled for this session.') |
---|
| 936 | return None |
---|
| 937 | |
---|
[7841] | 938 | VERDICTS_DICT = { |
---|
[8820] | 939 | '0': _('(not yet)'), |
---|
[7841] | 940 | 'A': 'Successful student', |
---|
| 941 | 'B': 'Student with carryover courses', |
---|
| 942 | 'C': 'Student on probation', |
---|
| 943 | } |
---|
[8099] | 944 | |
---|
| 945 | SEPARATORS_DICT = { |
---|
| 946 | } |
---|
[8410] | 947 | |
---|
[10021] | 948 | SKIP_UPLOAD_VIEWLETS = () |
---|
| 949 | |
---|
[10803] | 950 | PWCHANGE_STATES = (ADMITTED,) |
---|
[10706] | 951 | |
---|
[12104] | 952 | #: A tuple containing all exporter names referring to students or |
---|
| 953 | #: subobjects thereof. |
---|
| 954 | STUDENT_EXPORTER_NAMES = ('students', 'studentstudycourses', |
---|
| 955 | 'studentstudylevels', 'coursetickets', |
---|
| 956 | 'studentpayments', 'bedtickets', 'paymentsoverview', |
---|
| 957 | 'studylevelsoverview', 'combocard', 'bursary') |
---|
| 958 | |
---|
[8410] | 959 | #: A prefix used when generating new student ids. Each student id will |
---|
| 960 | #: start with this string. The default is 'K' for ``Kofa``. |
---|
| 961 | STUDENT_ID_PREFIX = u'K' |
---|