Ignore:
Timestamp:
29 Oct 2014, 16:44:30 (10 years ago)
Author:
uli
Message:

pep8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/branches/uli-stud-utils-cleanup/src/waeup/kofa/students/utils.py

    r11875 r11911  
    3636from waeup.kofa.students.interfaces import IStudentsUtils
    3737from waeup.kofa.students.workflow import ADMITTED
    38 from waeup.kofa.students.vocabularies import StudyLevelSource, MatNumNotInSource
     38from waeup.kofa.students.vocabularies import (
     39    StudyLevelSource, MatNumNotInSource,
     40    )
    3941from waeup.kofa.browser.pdf import (
    40     ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, 
     42    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
    4143    get_signature_tables, get_qrcode)
    4244from waeup.kofa.browser.interfaces import IPDFCreator
     
    4446
    4547SLIP_STYLE = [
    46     ('VALIGN',(0,0),(-1,-1),'TOP'),
    47     #('FONT', (0,0), (-1,-1), 'Helvetica', 11),
     48    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
     49    #('FONT', (0, 0), (-1, -1), 'Helvetica', 11),
    4850    ]
    4951
    5052CONTENT_STYLE = [
    51     ('VALIGN',(0,0),(-1,-1),'TOP'),
    52     #('FONT', (0,0), (-1,-1), 'Helvetica', 8),
    53     #('TEXTCOLOR',(0,0),(-1,0),colors.white),
    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 
     53    ('VALIGN', (0, 0), (-1, -1), 'TOP'),
     54    #('FONT', (0, 0), (-1, -1), 'Helvetica', 8),
     55    #('TEXTCOLOR', (0, 0), (-1, 0), colors.white),
     56    #('BACKGROUND', (0, 0),(-1, 0), colors.black),
     57    ('INNERGRID', (0, 0), (-1, -1), 0.25, colors.black),
     58    ('BOX', (0, 0), (-1, -1), 1, colors.black),
    5859    ]
    5960
    6061FONT_SIZE = 10
    6162FONT_COLOR = 'black'
     63
    6264
    6365def trans(text, lang):
    6466    # shortcut
    6567    return translate(text, 'waeup.kofa', target_language=lang)
     68
    6669
    6770def formatted_text(text, color=FONT_COLOR, lang='en'):
     
    9396    return tag1 + u'%s</font>' % text
    9497
     98
    9599def generate_student_id():
    96100    students = grok.getSite()['students']
    97101    new_id = students.unique_student_id
    98102    return new_id
     103
    99104
    100105def set_up_widgets(view, ignore_request=False):
     
    105110        ignore_request=ignore_request
    106111        )
     112
    107113
    108114def render_student_data(studentview, context, omit_fields=(),
     
    120126        from waeup.kofa.browser import DEFAULT_PASSPORT_IMAGE_PATH
    121127        img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb')
    122     doc_img = Image(img.name, width=4*cm, height=4*cm, kind='bound')
     128    doc_img = Image(img.name, width=4 * cm, height=4 * cm, kind='bound')
    123129    data_left.append([doc_img])
    124130    #data.append([Spacer(1, 12)])
     
    128134    f_text = formatted_text(studentview.context.display_fullname)
    129135    f_text = Paragraph(f_text, ENTRY1_STYLE)
    130     data_middle.append([f_label,f_text])
     136    data_middle.append([f_label, f_text])
    131137
    132138    for widget in studentview.widgets:
     
    139145        f_text = formatted_text(widget(), lang=lang)
    140146        f_text = Paragraph(f_text, ENTRY1_STYLE)
    141         data_middle.append([f_label,f_text])
     147        data_middle.append([f_label, f_text])
    142148
    143149    if getattr(studentview.context, 'certcode', None):
     
    148154                studentview.context['studycourse'].certificate.longtitle)
    149155            f_text = Paragraph(f_text, ENTRY1_STYLE)
    150             data_middle.append([f_label,f_text])
     156            data_middle.append([f_label, f_text])
    151157        if not 'department' in omit_fields:
    152158            f_label = trans(_('Department:'), lang)
     
    157163                )
    158164            f_text = Paragraph(f_text, ENTRY1_STYLE)
    159             data_middle.append([f_label,f_text])
     165            data_middle.append([f_label, f_text])
    160166        if not 'faculty' in omit_fields:
    161167            f_label = trans(_('Faculty:'), lang)
    162168            f_label = Paragraph(f_label, ENTRY1_STYLE)
    163             f_text = formatted_text(
    164                 studentview.context[
    165                 'studycourse'].certificate.__parent__.__parent__.__parent__.longtitle,
    166                 )
     169            course = studentview.context['studycourse']
     170            cert = course.certificate
     171            longtitle = cert.__parent__.__parent__.__parent__.longtitle
     172            f_text = formatted_text(longtitle)
    167173            f_text = Paragraph(f_text, ENTRY1_STYLE)
    168             data_middle.append([f_label,f_text])
     174            data_middle.append([f_label, f_text])
    169175        if not 'current_mode' in omit_fields:
    170176            studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
     
    174180            f_text = formatted_text(sm)
    175181            f_text = Paragraph(f_text, ENTRY1_STYLE)
    176             data_middle.append([f_label,f_text])
     182            data_middle.append([f_label, f_text])
    177183        if not 'entry_session' in omit_fields:
    178184            f_label = trans(_('Entry Session:'), lang)
    179185            f_label = Paragraph(f_label, ENTRY1_STYLE)
    180186            entry_session = studentview.context.entry_session
    181             entry_session = academic_sessions_vocab.getTerm(entry_session).title
     187            entry_session = academic_sessions_vocab.getTerm(
     188                entry_session).title
    182189            f_text = formatted_text(entry_session)
    183190            f_text = Paragraph(f_text, ENTRY1_STYLE)
    184             data_middle.append([f_label,f_text])
     191            data_middle.append([f_label, f_text])
    185192        # Requested by Uniben, does not really make sense
    186193        if not 'current_level' in omit_fields:
     
    193200            f_text = formatted_text(current_level)
    194201            f_text = Paragraph(f_text, ENTRY1_STYLE)
    195             data_middle.append([f_label,f_text])
     202            data_middle.append([f_label, f_text])
    196203        if not 'date_of_birth' in omit_fields:
    197204            f_label = trans(_('Date of Birth:'), lang)
     
    204211            f_text = formatted_text(date_of_birth)
    205212            f_text = Paragraph(f_text, ENTRY1_STYLE)
    206             data_middle.append([f_label,f_text])
     213            data_middle.append([f_label, f_text])
    207214
    208215    # append QR code to the right
     
    210217        url = studentview.url(context, slipname)
    211218        data_right = [[get_qrcode(url, width=70.0)]]
    212         table_right = Table(data_right,style=SLIP_STYLE)
     219        table_right = Table(data_right, style=SLIP_STYLE)
    213220    else:
    214221        table_right = None
    215222
    216     table_left = Table(data_left,style=SLIP_STYLE)
    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)
     223    table_left = Table(data_left, style=SLIP_STYLE)
     224    table_middle = Table(data_middle, style=SLIP_STYLE,
     225                         colWidths=[5 * cm, 5 * cm])
     226    table = Table([[table_left, table_middle, table_right], ],
     227                  style=SLIP_STYLE)
    219228    return table
     229
    220230
    221231def render_table_data(tableheader, tabledata, lang='en'):
     
    234244        line = []
    235245        for element in tableheader:
    236               field = formatted_text(getattr(ticket,element[1],u' '))
    237               field = Paragraph(field, style["Normal"])
    238               line.append(field)
     246            field = formatted_text(getattr(ticket, element[1], u' '))
     247            field = Paragraph(field, style["Normal"])
     248            line.append(field)
    239249        data.append(line)
    240     table = Table(data,colWidths=[
    241         element[2]*cm for element in tableheader], style=CONTENT_STYLE)
     250    table = Table(data, colWidths=[
     251        element[2] * cm for element in tableheader], style=CONTENT_STYLE)
    242252    return table
     253
    243254
    244255def render_transcript_data(view, tableheader, levels_data, lang='en'):
     
    266277            ticketline = []
    267278            for element in tableheader:
    268                   field = formatted_text(getattr(ticket,element[1],u' '))
    269                   field = Paragraph(field, style["Normal"])
    270                   ticketline.append(field)
     279                field = formatted_text(getattr(ticket, element[1], u' '))
     280                field = Paragraph(field, style["Normal"])
     281                ticketline.append(field)
    271282            tabledata.append(ticketline)
    272         table = Table(tabledata,colWidths=[
    273             element[2]*cm for element in tableheader], style=CONTENT_STYLE)
     283        table = Table(tabledata, colWidths=[
     284            element[2] * cm for element in tableheader], style=CONTENT_STYLE)
    274285        data.append(table)
    275         sgpa = '%s: %s' % (trans('Sessional GPA (rectified)', lang), level['sgpa'])
     286        sgpa = '%s: %s' % (
     287            trans('Sessional GPA (rectified)', lang), level['sgpa'])
    276288        data.append(Paragraph(sgpa, style["Normal"]))
    277289    return data
     290
    278291
    279292def docs_as_flowables(view, lang='en'):
     
    300313                img_path = getattr(getUtility(IExtFileStore).getFileByContext(
    301314                    view.context, attr=viewlet.download_name), 'name', None)
    302                 #f_text = Paragraph(trans(_('(not provided)'),lang), ENTRY1_STYLE)
    303315                if img_path is None:
    304316                    pass
     
    308320                        viewlet.title,), ENTRY1_STYLE)
    309321                else:
    310                     f_text = Image(img_path, width=2*cm, height=1*cm, kind='bound')
     322                    f_text = Image(
     323                        img_path, width=2 * cm, height=1 * cm, kind='bound')
    311324                table_data.append([f_label, f_text])
    312325        if table_data:
     
    314327            data.append(Table(table_data, style=SLIP_STYLE))
    315328    return data
     329
    316330
    317331class StudentsUtils(grok.GlobalUtility):
     
    367381        for key in student['payments'].keys():
    368382            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
     383            if (ticket.p_state == 'paid') and (
     384                ticket.p_category == category) and (
     385                ticket.p_item == p_item) and (
     386                    ticket.p_session == p_session):
     387                return True
    374388        return False
    375389
     
    391405                    return _('This is not a previous session.'), None
    392406            else:
    393                 if previous_session > student['studycourse'].current_session - 1:
     407                if previous_session > (
     408                    student['studycourse'].current_session - 1):
    394409                    return _('This is not a previous session.'), None
    395410            p_session = previous_session
     
    478493            return _('Payment temporarily disabled.'), None
    479494        payment = createObject(u'waeup.StudentOnlinePayment')
    480         timestamp = ("%d" % int(time()*10000))[1:]
     495        timestamp = ("%d" % int(time() * 10000))[1:]
    481496        payment.p_id = "p%s" % timestamp
    482497        payment.p_category = category
     
    506521            return _('This type of payment has already been made.'), None
    507522        payment = createObject(u'waeup.StudentOnlinePayment')
    508         timestamp = ("%d" % int(time()*10000))[1:]
     523        timestamp = ("%d" % int(time() * 10000))[1:]
    509524        payment.p_id = "p%s" % timestamp
    510525        payment.p_category = category
     
    568583        # Determine bed type
    569584        studycourse = student['studycourse']
    570         certificate = getattr(studycourse,'certificate',None)
     585        certificate = getattr(studycourse, 'certificate', None)
    571586        entry_session = studycourse.entry_session
    572587        current_level = studycourse.current_level
     
    587602            sex = 'male'
    588603        special_handling = 'regular'
    589         d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
     604        d['bt'] = u'%s_%s_%s' % (special_handling, sex, bt)
    590605        return d
    591606
     
    602617        text = trans(_(
    603618            'This is to inform you that you have been provisionally'
    604             ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
     619            ' admitted into ${a} as follows:', mapping={'a': inst_name}),
    605620            portal_language)
    606621        return text
     
    647662        if post_text is None:
    648663            datelist = student.history.messages[0].split()[0].split('-')
    649             creation_date = u'%s/%s/%s' % (datelist[2], datelist[1], datelist[0])
     664            creation_date = u'%s/%s/%s' % (
     665                datelist[2], datelist[1], datelist[0])
    650666            post_text = trans(_(
    651667                'Your Kofa student record was created on ${a}.',
    652                 mapping = {'a': creation_date}),
     668                mapping={'a': creation_date}),
    653669                portal_language)
    654670        #html = format_html(post_text)
     
    731747                    data.append(Paragraph(view.tabletitle[i], HEADING_STYLE))
    732748                    data.append(Spacer(1, 8))
    733                     contenttable = render_table_data(tableheader[i],tabledata[i])
     749                    contenttable = render_table_data(
     750                        tableheader[i], tabledata[i])
    734751                    data.append(contenttable)
    735752
     
    823840        f_text = formatted_text(view.context.certificate.longtitle)
    824841        f_text = Paragraph(f_text, ENTRY1_STYLE)
    825         contextdata.append([f_label,f_text])
     842        contextdata.append([f_label, f_text])
    826843
    827844        f_label = trans(_('Faculty:'), portal_language)
    828845        f_label = Paragraph(f_label, ENTRY1_STYLE)
     846        cert = view.context.certificate
    829847        f_text = formatted_text(
    830             view.context.certificate.__parent__.__parent__.__parent__.longtitle)
     848            cert.__parent__.__parent__.__parent__.longtitle)
    831849        f_text = Paragraph(f_text, ENTRY1_STYLE)
    832         contextdata.append([f_label,f_text])
     850        contextdata.append([f_label, f_text])
    833851
    834852        f_label = trans(_('Department:'), portal_language)
     
    837855            view.context.certificate.__parent__.__parent__.longtitle)
    838856        f_text = Paragraph(f_text, ENTRY1_STYLE)
    839         contextdata.append([f_label,f_text])
     857        contextdata.append([f_label, f_text])
    840858
    841859        f_label = trans(_('Entry Session:'), portal_language)
     
    844862            view.session_dict.get(view.context.entry_session))
    845863        f_text = Paragraph(f_text, ENTRY1_STYLE)
    846         contextdata.append([f_label,f_text])
     864        contextdata.append([f_label, f_text])
    847865
    848866        f_label = trans(_('Entry Mode:'), portal_language)
     
    851869            view.context.entry_mode))
    852870        f_text = Paragraph(f_text, ENTRY1_STYLE)
    853         contextdata.append([f_label,f_text])
     871        contextdata.append([f_label, f_text])
    854872
    855873        f_label = trans(_('Cumulative GPA:'), portal_language)
    856874        f_label = Paragraph(f_label, ENTRY1_STYLE)
    857         f_text = formatted_text('%s (%s)' % (gpa, self.getClassFromCGPA(gpa)[1]))
     875        f_text = formatted_text('%s (%s)' % (
     876                gpa, self.getClassFromCGPA(gpa)[1]))
    858877        f_text = Paragraph(f_text, ENTRY1_STYLE)
    859         contextdata.append([f_label,f_text])
    860 
    861         contexttable = Table(contextdata,style=SLIP_STYLE)
     878        contextdata.append([f_label, f_text])
     879
     880        contexttable = Table(contextdata, style=SLIP_STYLE)
    862881        data.append(contexttable)
    863882
Note: See TracChangeset for help on using the changeset viewer.