[PATCH eac] Export multi-line description as distinct <p> elements (CONSEJIRA-582)

Denis Laxalde denis.laxalde at logilab.fr
Tue Sep 18 15:50:43 CEST 2018


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1537278198 -7200
#      Tue Sep 18 15:43:18 2018 +0200
# Node ID 7b8516b0f4e55735b33aaf96e75c9f93c631776f
# Parent  c1a4aeb2030a7aa7e224ebeda9f16d576295ed7d
# Available At http://hg.logilab.org/review/cubes/eac
#              hg pull http://hg.logilab.org/review/cubes/eac -r 7b8516b0f4e5
# EXP-Topic CONSEJIRA-582
Export multi-line description as distinct <p> elements (CONSEJIRA-582)

When a description attribute in text/plain mime type has several lines, we
now export each of them in a distinct <p> element.

diff --git a/cubicweb_eac/entities.py b/cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py
+++ b/cubicweb_eac/entities.py
@@ -634,7 +634,7 @@ class AuthorityRecordEACAdapter(Abstract
             value = getattr(entity, attr_name)
             if not value:
                 return []
-            return [self.element('p', text=value)]
+            return [self.element('p', text=line) for line in value.splitlines()]
         else:
             value = entity.printable_value(attr_name)
             if not value:
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -30,17 +30,19 @@ class EACExportTC(CubicWebTC):
     def test_richstring_plain(self):
         with self.admin_access.cnx() as cnx:
             alice = testutils.authority_record(cnx, u'Alice')
-            desc = u'ding'
+            desc = u'ding\nlikes rabbits'
             mandate = cnx.create_entity(
                 'Mandate', term=u'ding-girl',
                 description=desc, description_format=u'text/plain',
                 mandate_agent=alice)
             cnx.commit()
             serializer = alice.cw_adapt_to('EAC-CPF')
-            tag, = serializer._eac_richstring_paragraph_elements(
+            line1, line2 = serializer._eac_richstring_paragraph_elements(
                 mandate, 'description')
-        self.assertEqual(tag.tag, 'p')
-        self.assertEqual(tag.text, desc)
+        self.assertEqual(line1.tag, 'p')
+        self.assertEqual(line1.text, u'ding')
+        self.assertEqual(line2.tag, 'p')
+        self.assertEqual(line2.text, u'likes rabbits')
 
     def test_richstring_html_simple(self):
         with self.admin_access.cnx() as cnx:



More information about the saem-devel mailing list