[PATCH eac v2] Do not export empty "descriptiveNote" elements

Denis Laxalde denis.laxalde at logilab.fr
Tue Dec 19 12:02:31 CET 2017

# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1513680984 -3600
#      Tue Dec 19 11:56:24 2017 +0100
# Node ID cbb5837d118b2fd7c569232b28f7a0b7b7d66cec
# Parent  1cfd40162c0d0752e9294f43ed617afcce51789f
# EXP-Topic empty-descriptiveNote
Do not export empty "descriptiveNote" elements

It happens that if an entity has a "description" set which renders as
nothing from "printable_value()" call, a descriptiveNote element will
still be exported by the EAC-CPF exporter as demonstrated by added test

So instead of checking that entity's description attribute has a truth
value, we now check that rendering this attribute as a "rich string
paragraph" produces something before inserting the descriptiveNote

This should avoid getting exported element like:

      <term vocabularySource="http://data.culture.fr/thesaurus/resource/ark:/67717/T3-144">note</term>

diff --git a/cubicweb_eac/entities.py b/cubicweb_eac/entities.py
--- a/cubicweb_eac/entities.py
+++ b/cubicweb_eac/entities.py
@@ -274,9 +274,11 @@ def add_descriptive_note(func):
     def wrapper(self, entity, *args, **kwargs):
         element = func(self, entity, *args, **kwargs)
-        if element is not None and entity.description:
+        description = self._eac_richstring_paragraph_elements(
+            entity, "description")
+        if element is not None and description:
             self.element('descriptiveNote', parent=element).extend(
-                self._eac_richstring_paragraph_elements(entity, "description"))
+                description)
         return element
     return wrapper
diff --git a/test/test_entities.py b/test/test_entities.py
--- a/test/test_entities.py
+++ b/test/test_entities.py
@@ -135,6 +135,19 @@ class EACExportTC(CubicWebTC):
                 'Any X WHERE N name_entry_for X, N parts "Alice"').one()
+    def test_richstring_non_none_non_html(self):
+        with self.admin_access.cnx() as cnx:
+            arecord = testutils.authority_record(cnx, u'R')
+            mandate = cnx.create_entity(
+                'Mandate', term=u'w',
+                description=u' ',
+                description_format=u'text/markdown',
+                mandate_agent=arecord)
+            cnx.commit()
+            serializer = arecord.cw_adapt_to('EAC-CPF')
+            element = serializer.mandate_element(mandate)
+            self.assertEqual(['term'], [child.tag for child in element])
 if __name__ == '__main__':
     import unittest

More information about the saem-devel mailing list