Merge pull request #1237 from rolandgeider/stable/1.5.x

Handle nested lists in the motion PDF without error.
This commit is contained in:
Norman Jäckel 2014-03-31 22:41:31 +02:00
commit d3dd7ac208
3 changed files with 36 additions and 9 deletions

View File

@ -27,6 +27,7 @@ Other:
- Fixed http status code when requesting a non-existing static page using - Fixed http status code when requesting a non-existing static page using
Tornado web server. Tornado web server.
- Fixed error in main script when using other database engine. - Fixed error in main script when using other database engine.
- Fixed error on motion PDF with nested lists
Version 1.5 (2013-11-25) Version 1.5 (2013-11-25)

View File

@ -157,25 +157,25 @@ def convert_html_to_reportlab(pdf, text):
for element in soup.find_all('li'): for element in soup.find_all('li'):
# ... and replace ul list elements with <para><bullet>&bull;</bullet>...<para> # ... and replace ul list elements with <para><bullet>&bull;</bullet>...<para>
if element.parent.name == "ul": if element.parent.name == "ul":
if element.ul: # nested lists
# for nested ul lists use simple spaces (pragmatic solution) if element.ul or element.ol:
element.li.insert(0, '&nbsp;&nbsp;&nbsp;&nbsp;') for i in element.find_all('li'):
element.insert_before(element.find_all('li')) element.insert_before(i)
element.clear() element.clear()
else: else:
element.name = "para" element.name = "para"
bullet_tag = soup.new_tag("bullet") bullet_tag = soup.new_tag("bullet")
bullet_tag.string = "&bull;" bullet_tag.string = u""
element.insert(0, bullet_tag) element.insert(0, bullet_tag)
# ... and replace ol list elements with <para><bullet><seq id="%id"></seq>.</bullet>...</para> # ... and replace ol list elements with <para><bullet><seq id="%id"></seq>.</bullet>...</para>
if element.parent.name == "ol": if element.parent.name == "ol":
# set list id if element is the first of numbered list # set list id if element is the first of numbered list
if not element.find_previous_sibling(): if not element.find_previous_sibling():
id = random.randrange(0, 101) id = random.randrange(0, 101)
if element.ol: # nested lists
# nested ol list if element.ul or element.ol:
element.li.insert(0, '&nbsp;&nbsp;&nbsp;&nbsp;') for i in element.find_all('li'):
element.insert_before(element.find_all('li')) element.insert_before(i)
element.clear() element.clear()
else: else:
element.name = "para" element.name = "para"

26
tests/motion/test_pdf.py Normal file
View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from django.test.client import Client
from openslides.motion.models import Motion
from openslides.participant.models import User
from openslides.utils.test import TestCase
class MotionPDFTest(TestCase):
"""
Tests for motion PDF.
"""
def setUp(self):
# Admin
self.admin = User.objects.get(pk=1)
self.admin_client = Client()
self.admin_client.login(username='admin', password='admin')
def test_render_nested_list(self):
Motion.objects.create(
title='Test Title chieM6Aing8Eegh9ePhu',
text='<ul><li>Element 1 aKaesieze6mahR2ielie'
'<ul><li>Subelement 1 rel0liiGh0bi3ree6Jei</li>'
'<li>Subelement 2 rel0liiGh0bi3ree6Jei</li></ul></li>'
'<li>Element 2 rel0liiGh0bi3ree6Jei</li></ul>')
response = self.admin_client.get('/motion/1/pdf/')
self.assertEqual(response.status_code, 200)