From 5bac8ec1e474b65d76a67dcf6c94d593d36e9383 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 31 Mar 2014 22:07:14 +0200 Subject: [PATCH 1/2] Correctly handle nested lists in the motion PDF See #1217 --- openslides/motion/pdf.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/openslides/motion/pdf.py b/openslides/motion/pdf.py index 2f89dc31a..6257192c5 100644 --- a/openslides/motion/pdf.py +++ b/openslides/motion/pdf.py @@ -157,25 +157,25 @@ def convert_html_to_reportlab(pdf, text): for element in soup.find_all('li'): # ... and replace ul list elements with ... if element.parent.name == "ul": - if element.ul: - # for nested ul lists use simple spaces (pragmatic solution) - element.li.insert(0, '    ') - element.insert_before(element.find_all('li')) + # nested lists + if element.ul or element.ol: + for i in element.find_all('li'): + element.insert_before(i) element.clear() else: element.name = "para" bullet_tag = soup.new_tag("bullet") - bullet_tag.string = "•" + bullet_tag.string = u"•" element.insert(0, bullet_tag) # ... and replace ol list elements with .... if element.parent.name == "ol": # set list id if element is the first of numbered list if not element.find_previous_sibling(): id = random.randrange(0, 101) - if element.ol: - # nested ol list - element.li.insert(0, '    ') - element.insert_before(element.find_all('li')) + # nested lists + if element.ul or element.ol: + for i in element.find_all('li'): + element.insert_before(i) element.clear() else: element.name = "para" From e96f984a035f3f212e5ca20403d067aa0cca56cf Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Mon, 31 Mar 2014 22:17:10 +0200 Subject: [PATCH 2/2] Add tests for motion PDF and update changelog file --- CHANGELOG | 1 + tests/motion/test_pdf.py | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/motion/test_pdf.py diff --git a/CHANGELOG b/CHANGELOG index 770c39e8a..0f3e59dc0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,7 @@ Other: - Fixed http status code when requesting a non-existing static page using Tornado web server. - Fixed error in main script when using other database engine. +- Fixed error on motion PDF with nested lists Version 1.5 (2013-11-25) diff --git a/tests/motion/test_pdf.py b/tests/motion/test_pdf.py new file mode 100644 index 000000000..7becbd12c --- /dev/null +++ b/tests/motion/test_pdf.py @@ -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='
  • Element 1 aKaesieze6mahR2ielie' + '
    • Subelement 1 rel0liiGh0bi3ree6Jei
    • ' + '
    • Subelement 2 rel0liiGh0bi3ree6Jei
  • ' + '
  • Element 2 rel0liiGh0bi3ree6Jei
') + response = self.admin_client.get('/motion/1/pdf/') + self.assertEqual(response.status_code, 200)