Index: /main/waeup.kofa/branches/uli-stud-utils-cleanup/src/waeup/kofa/students/utils.py
===================================================================
--- /main/waeup.kofa/branches/uli-stud-utils-cleanup/src/waeup/kofa/students/utils.py	(revision 11910)
+++ /main/waeup.kofa/branches/uli-stud-utils-cleanup/src/waeup/kofa/students/utils.py	(revision 11911)
@@ -36,7 +36,9 @@
 from waeup.kofa.students.interfaces import IStudentsUtils
 from waeup.kofa.students.workflow import ADMITTED
-from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource
+from waeup.kofa.students.vocabularies import (
+    StudyLevelSource, MatNumNotInSource,
+    )
 from waeup.kofa.browser.pdf import (
-    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, 
+    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
     get_signature_tables, get_qrcode)
 from waeup.kofa.browser.interfaces import IPDFCreator
@@ -44,24 +46,25 @@
 
 SLIP_STYLE = [
-    ('VALIGN',(0,0),(-1,-1),'TOP'),
-    #('FONT', (0,0), (-1,-1), 'Helvetica', 11),
+    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
+    #('FONT', (0, 0), (-1, -1), 'Helvetica', 11),
     ]
 
 CONTENT_STYLE = [
-    ('VALIGN',(0,0),(-1,-1),'TOP'),
-    #('FONT', (0,0), (-1,-1), 'Helvetica', 8),
-    #('TEXTCOLOR',(0,0),(-1,0),colors.white),
-    #('BACKGROUND',(0,0),(-1,0),colors.black),
-    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
-    ('BOX', (0,0), (-1,-1), 1, colors.black),
-
+    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
+    #('FONT', (0, 0), (-1, -1), 'Helvetica', 8),
+    #('TEXTCOLOR', (0, 0), (-1, 0), colors.white),
+    #('BACKGROUND', (0, 0),(-1, 0), colors.black),
+    ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
+    ('BOX', (0, 0), (-1, -1), 1, colors.black),
     ]
 
 FONT_SIZE = 10
 FONT_COLOR = 'black'
+
 
 def trans(text, lang):
     # shortcut
     return translate(text, 'waeup.kofa', target_language=lang)
+
 
 def formatted_text(text, color=FONT_COLOR, lang='en'):
@@ -93,8 +96,10 @@
     return tag1 + u'%s</font>' % text
 
+
 def generate_student_id():
     students = grok.getSite()['students']
     new_id = students.unique_student_id
     return new_id
+
 
 def set_up_widgets(view, ignore_request=False):
@@ -105,4 +110,5 @@
         ignore_request=ignore_request
         )
+
 
 def render_student_data(studentview, context, omit_fields=(),
@@ -120,5 +126,5 @@
         from waeup.kofa.browser import DEFAULT_PASSPORT_IMAGE_PATH
         img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb')
-    doc_img = Image(img.name, width=4*cm, height=4*cm, kind='bound')
+    doc_img = Image(img.name, width=4 * cm, height=4 * cm, kind='bound')
     data_left.append([doc_img])
     #data.append([Spacer(1, 12)])
@@ -128,5 +134,5 @@
     f_text = formatted_text(studentview.context.display_fullname)
     f_text = Paragraph(f_text, ENTRY1_STYLE)
-    data_middle.append([f_label,f_text])
+    data_middle.append([f_label, f_text])
 
     for widget in studentview.widgets:
@@ -139,5 +145,5 @@
         f_text = formatted_text(widget(), lang=lang)
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        data_middle.append([f_label,f_text])
+        data_middle.append([f_label, f_text])
 
     if getattr(studentview.context, 'certcode', None):
@@ -148,5 +154,5 @@
                 studentview.context['studycourse'].certificate.longtitle)
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
         if not 'department' in omit_fields:
             f_label = trans(_('Department:'), lang)
@@ -157,14 +163,14 @@
                 )
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
         if not 'faculty' in omit_fields:
             f_label = trans(_('Faculty:'), lang)
             f_label = Paragraph(f_label, ENTRY1_STYLE)
-            f_text = formatted_text(
-                studentview.context[
-                'studycourse'].certificate.__parent__.__parent__.__parent__.longtitle,
-                )
+            course = studentview.context['studycourse']
+            cert = course.certificate
+            longtitle = cert.__parent__.__parent__.__parent__.longtitle
+            f_text = formatted_text(longtitle)
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
         if not 'current_mode' in omit_fields:
             studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
@@ -174,13 +180,14 @@
             f_text = formatted_text(sm)
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
         if not 'entry_session' in omit_fields:
             f_label = trans(_('Entry Session:'), lang)
             f_label = Paragraph(f_label, ENTRY1_STYLE)
             entry_session = studentview.context.entry_session
-            entry_session = academic_sessions_vocab.getTerm(entry_session).title
+            entry_session = academic_sessions_vocab.getTerm(
+                entry_session).title
             f_text = formatted_text(entry_session)
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
         # Requested by Uniben, does not really make sense
         if not 'current_level' in omit_fields:
@@ -193,5 +200,5 @@
             f_text = formatted_text(current_level)
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
         if not 'date_of_birth' in omit_fields:
             f_label = trans(_('Date of Birth:'), lang)
@@ -204,5 +211,5 @@
             f_text = formatted_text(date_of_birth)
             f_text = Paragraph(f_text, ENTRY1_STYLE)
-            data_middle.append([f_label,f_text])
+            data_middle.append([f_label, f_text])
 
     # append QR code to the right
@@ -210,12 +217,15 @@
         url = studentview.url(context, slipname)
         data_right = [[get_qrcode(url, width=70.0)]]
-        table_right = Table(data_right,style=SLIP_STYLE)
+        table_right = Table(data_right, style=SLIP_STYLE)
     else:
         table_right = None
 
-    table_left = Table(data_left,style=SLIP_STYLE)
-    table_middle = Table(data_middle,style=SLIP_STYLE, colWidths=[5*cm, 5*cm])
-    table = Table([[table_left, table_middle, table_right],],style=SLIP_STYLE)
+    table_left = Table(data_left, style=SLIP_STYLE)
+    table_middle = Table(data_middle, style=SLIP_STYLE,
+                         colWidths=[5 * cm, 5 * cm])
+    table = Table([[table_left, table_middle, table_right], ],
+                  style=SLIP_STYLE)
     return table
+
 
 def render_table_data(tableheader, tabledata, lang='en'):
@@ -234,11 +244,12 @@
         line = []
         for element in tableheader:
-              field = formatted_text(getattr(ticket,element[1],u' '))
-              field = Paragraph(field, style["Normal"])
-              line.append(field)
+            field = formatted_text(getattr(ticket, element[1], u' '))
+            field = Paragraph(field, style["Normal"])
+            line.append(field)
         data.append(line)
-    table = Table(data,colWidths=[
-        element[2]*cm for element in tableheader], style=CONTENT_STYLE)
+    table = Table(data, colWidths=[
+        element[2] * cm for element in tableheader], style=CONTENT_STYLE)
     return table
+
 
 def render_transcript_data(view, tableheader, levels_data, lang='en'):
@@ -266,14 +277,16 @@
             ticketline = []
             for element in tableheader:
-                  field = formatted_text(getattr(ticket,element[1],u' '))
-                  field = Paragraph(field, style["Normal"])
-                  ticketline.append(field)
+                field = formatted_text(getattr(ticket, element[1], u' '))
+                field = Paragraph(field, style["Normal"])
+                ticketline.append(field)
             tabledata.append(ticketline)
-        table = Table(tabledata,colWidths=[
-            element[2]*cm for element in tableheader], style=CONTENT_STYLE)
+        table = Table(tabledata, colWidths=[
+            element[2] * cm for element in tableheader], style=CONTENT_STYLE)
         data.append(table)
-        sgpa = '%s: %s' % (trans('Sessional GPA (rectified)', lang), level['sgpa'])
+        sgpa = '%s: %s' % (
+            trans('Sessional GPA (rectified)', lang), level['sgpa'])
         data.append(Paragraph(sgpa, style["Normal"]))
     return data
+
 
 def docs_as_flowables(view, lang='en'):
@@ -300,5 +313,4 @@
                 img_path = getattr(getUtility(IExtFileStore).getFileByContext(
                     view.context, attr=viewlet.download_name), 'name', None)
-                #f_text = Paragraph(trans(_('(not provided)'),lang), ENTRY1_STYLE)
                 if img_path is None:
                     pass
@@ -308,5 +320,6 @@
                         viewlet.title,), ENTRY1_STYLE)
                 else:
-                    f_text = Image(img_path, width=2*cm, height=1*cm, kind='bound')
+                    f_text = Image(
+                        img_path, width=2 * cm, height=1 * cm, kind='bound')
                 table_data.append([f_label, f_text])
         if table_data:
@@ -314,4 +327,5 @@
             data.append(Table(table_data, style=SLIP_STYLE))
     return data
+
 
 class StudentsUtils(grok.GlobalUtility):
@@ -367,9 +381,9 @@
         for key in student['payments'].keys():
             ticket = student['payments'][key]
-            if ticket.p_state == 'paid' and\
-               ticket.p_category == category and \
-               ticket.p_item == p_item and \
-               ticket.p_session == p_session:
-                  return True
+            if (ticket.p_state == 'paid') and (
+                ticket.p_category == category) and (
+                ticket.p_item == p_item) and (
+                    ticket.p_session == p_session):
+                return True
         return False
 
@@ -391,5 +405,6 @@
                     return _('This is not a previous session.'), None
             else:
-                if previous_session > student['studycourse'].current_session - 1:
+                if previous_session > (
+                    student['studycourse'].current_session - 1):
                     return _('This is not a previous session.'), None
             p_session = previous_session
@@ -478,5 +493,5 @@
             return _('Payment temporarily disabled.'), None
         payment = createObject(u'waeup.StudentOnlinePayment')
-        timestamp = ("%d" % int(time()*10000))[1:]
+        timestamp = ("%d" % int(time() * 10000))[1:]
         payment.p_id = "p%s" % timestamp
         payment.p_category = category
@@ -506,5 +521,5 @@
             return _('This type of payment has already been made.'), None
         payment = createObject(u'waeup.StudentOnlinePayment')
-        timestamp = ("%d" % int(time()*10000))[1:]
+        timestamp = ("%d" % int(time() * 10000))[1:]
         payment.p_id = "p%s" % timestamp
         payment.p_category = category
@@ -568,5 +583,5 @@
         # Determine bed type
         studycourse = student['studycourse']
-        certificate = getattr(studycourse,'certificate',None)
+        certificate = getattr(studycourse, 'certificate', None)
         entry_session = studycourse.entry_session
         current_level = studycourse.current_level
@@ -587,5 +602,5 @@
             sex = 'male'
         special_handling = 'regular'
-        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
+        d['bt'] = u'%s_%s_%s' % (special_handling, sex, bt)
         return d
 
@@ -602,5 +617,5 @@
         text = trans(_(
             'This is to inform you that you have been provisionally'
-            ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
+            ' admitted into ${a} as follows:', mapping={'a': inst_name}),
             portal_language)
         return text
@@ -647,8 +662,9 @@
         if post_text is None:
             datelist = student.history.messages[0].split()[0].split('-')
-            creation_date = u'%s/%s/%s' % (datelist[2], datelist[1], datelist[0])
+            creation_date = u'%s/%s/%s' % (
+                datelist[2], datelist[1], datelist[0])
             post_text = trans(_(
                 'Your Kofa student record was created on ${a}.',
-                mapping = {'a': creation_date}),
+                mapping={'a': creation_date}),
                 portal_language)
         #html = format_html(post_text)
@@ -731,5 +747,6 @@
                     data.append(Paragraph(view.tabletitle[i], HEADING_STYLE))
                     data.append(Spacer(1, 8))
-                    contenttable = render_table_data(tableheader[i],tabledata[i])
+                    contenttable = render_table_data(
+                        tableheader[i], tabledata[i])
                     data.append(contenttable)
 
@@ -823,12 +840,13 @@
         f_text = formatted_text(view.context.certificate.longtitle)
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        contextdata.append([f_label,f_text])
+        contextdata.append([f_label, f_text])
 
         f_label = trans(_('Faculty:'), portal_language)
         f_label = Paragraph(f_label, ENTRY1_STYLE)
+        cert = view.context.certificate
         f_text = formatted_text(
-            view.context.certificate.__parent__.__parent__.__parent__.longtitle)
+            cert.__parent__.__parent__.__parent__.longtitle)
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        contextdata.append([f_label,f_text])
+        contextdata.append([f_label, f_text])
 
         f_label = trans(_('Department:'), portal_language)
@@ -837,5 +855,5 @@
             view.context.certificate.__parent__.__parent__.longtitle)
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        contextdata.append([f_label,f_text])
+        contextdata.append([f_label, f_text])
 
         f_label = trans(_('Entry Session:'), portal_language)
@@ -844,5 +862,5 @@
             view.session_dict.get(view.context.entry_session))
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        contextdata.append([f_label,f_text])
+        contextdata.append([f_label, f_text])
 
         f_label = trans(_('Entry Mode:'), portal_language)
@@ -851,13 +869,14 @@
             view.context.entry_mode))
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        contextdata.append([f_label,f_text])
+        contextdata.append([f_label, f_text])
 
         f_label = trans(_('Cumulative GPA:'), portal_language)
         f_label = Paragraph(f_label, ENTRY1_STYLE)
-        f_text = formatted_text('%s (%s)' % (gpa, self.getClassFromCGPA(gpa)[1]))
+        f_text = formatted_text('%s (%s)' % (
+                gpa, self.getClassFromCGPA(gpa)[1]))
         f_text = Paragraph(f_text, ENTRY1_STYLE)
-        contextdata.append([f_label,f_text])
-
-        contexttable = Table(contextdata,style=SLIP_STYLE)
+        contextdata.append([f_label, f_text])
+
+        contexttable = Table(contextdata, style=SLIP_STYLE)
         data.append(contexttable)
 
