Changeset 15234


Ignore:
Timestamp:
13 Nov 2018, 06:54:19 (6 years ago)
Author:
Henrik Bettermann
Message:

Titles with redundant whitespaces could cause an infinite loop. Remove this bug and use the textwrapper functions instead.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r15203 r15234  
    43944394    def test_lecturers_can_download_course_tickets(self):
    43954395        # A course ticket slip can be downloaded
    4396         self.course.title = (u'Lorem ipsum dolor sit amet, consectetur adipisici, '
    4397                              u'sed eiusmod tempor incidunt ut labore et dolore ')
     4396        self.course.title = (u'Lorem ipsum     dolor sit amet, consectetur    adipisici, '
     4397                             u'sed         eiusmod tempor    incidunt ut  labore et dolore')
    43984398        self.login_as_lecturer()
    43994399        pdf_url = '%s/coursetickets.pdf' % self.course_url
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r15212 r15234  
    1919"""
    2020import grok
     21import textwrap
    2122from time import time
    2223from cStringIO import StringIO
     
    10081009        style = getSampleStyleSheet()
    10091010        pdf_data = []
    1010         ct = ft = view.context.title
    1011         # Process title if too long
    1012         if len(view.context.title) + len(view.context.code) > title_length:
    1013             i = 0
    1014             titlelist = view.context.title.split()
    1015             while len(' '.join(titlelist[:i+1])) < title_length:
    1016                 i += 1
    1017             ct = ' '.join(titlelist[:i]) + '\n' + ' '.join(titlelist[i:])
    1018             ft = view.context.title[
    1019                 :(title_length-len(view.context.code))] + u' ...'
    10201011        pdf_data += [Paragraph(
    10211012            translate(_('<b>Lecturer(s): ${a}</b>',
     
    10441035        pdf_data.append(Spacer(1, 20))
    10451036        pdf_data += [Table(data[0], style=CONTENT_STYLE)]
     1037        # Process title if too long
     1038        title = " ".join(view.context.title.split())
     1039        ct = textwrap.fill(title, title_length)
     1040        ft = title
     1041        if len(ct) > 1:
     1042            ft = textwrap.wrap(title, title_length)[0] + ' ...'
    10461043        doc_title = translate(_('${a} (${b})\nAcademic Session ${d}',
    10471044            mapping = {'a':ct,
Note: See TracChangeset for help on using the changeset viewer.