[PATCH 9 of 9 seda] [html gen] Support for list as target value

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Oct 12 16:59:54 CEST 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1507814651 -7200
#      Thu Oct 12 15:24:11 2017 +0200
# Node ID 1d2ccc92ac3c02a06d67a9f3272d6c8702569906
# Parent  cc3b3e0f6d427c8413ddea9dd7dd69749b678859
# Available At https://hg.logilab.org/review/cubes/seda
#              hg pull https://hg.logilab.org/review/cubes/seda -r 1d2ccc92ac3c
[html gen] Support for list as target value

which will occurs when the profile has some data object linked to several mime
types or format ids. Tests setup is shared with profile generation, so modify it
there, it won't hurt the original functional case to cover this as well.

Closes #36331831

diff --git a/cubicweb_seda/entities/html_generation.py b/cubicweb_seda/entities/html_generation.py
--- a/cubicweb_seda/entities/html_generation.py
+++ b/cubicweb_seda/entities/html_generation.py
@@ -236,21 +236,30 @@ class SEDA2HTMLExport(SEDA2ExportAdapter
             ct_div = self.element('div', div)
             self.element('span', ct_div, text=self._cw._('XSD content type'),
                          attributes={'class': 'label'})
             xstypes = self._cw._(' ALT_I18N ').join(u'xsd:' + xstype for xstype in xstypes)
             self.element('span', ct_div, text=xstypes, attributes={'class': 'value'})
-        fixed_value = self.serialize(target_value)
-        if fixed_value is None:
-            return
-        value_div = self.element('div', div)
-        self.element('span', value_div, text=self._cw._('fixed value'),
-                     attributes={'class': 'label'})
-        if isinstance(fixed_value, string_types):
-            self.element('span', value_div, text=fixed_value, attributes={'class': 'value'})
+        if target_value is None:
+            values = ()
+        elif not isinstance(target_value, list):
+            values = [target_value]
         else:
-            span = self.element('span', value_div, attributes={'class': 'value'})
-            span.append(fixed_value)
+            values = target_value
+        value_div = None
+        for value in values:
+            fixed_value = self.serialize(value)
+            if fixed_value is None:
+                continue
+            if value_div is None:
+                value_div = self.element('div', div)
+                self.element('span', value_div, text=self._cw._('fixed value'),
+                             attributes={'class': 'label'})
+            if isinstance(fixed_value, string_types):
+                self.element('span', value_div, text=fixed_value, attributes={'class': 'value'})
+            else:
+                span = self.element('span', value_div, attributes={'class': 'value'})
+                span.append(fixed_value)
 
     def concept_scheme_attribute(self, xselement, div, scheme):
         try:
             xsattr = xselement_scheme_attribute(xselement)
         except KeyError:
diff --git a/test/test_profile_generation.py b/test/test_profile_generation.py
--- a/test/test_profile_generation.py
+++ b/test/test_profile_generation.py
@@ -607,10 +607,11 @@ class SEDAExportFuncTCMixIn(object):
         with self.admin_access.cnx() as cnx:
             create = cnx.create_entity
             scheme = create('ConceptScheme', title=u'Keyword Types')
             # ensure we're able to export concept with unexpected language code
             some_concept = scheme.add_concept(label=u'md5', language_code=u'de')
+            some_other_concept = scheme.add_concept(label=u'hash/md5', language_code=u'de')
 
             transfer = create('SEDAArchiveTransfer', title=u'test profile')
             create('SEDAMessageDigestAlgorithmCodeListVersion',
                    seda_message_digest_algorithm_code_list_version_from=transfer,
                    seda_message_digest_algorithm_code_list_version_to=scheme)
@@ -627,10 +628,11 @@ class SEDAExportFuncTCMixIn(object):
                                      reverse_seda_seq_access_rule_rule=access_rule)
             create('SEDAStartDate', user_cardinality=u'0..1', seda_start_date=access_rule_seq)
             # binary data object
             bdo = testutils.create_data_object(transfer, user_cardinality=u'0..n',
                                                seda_algorithm=some_concept)
+            bdo.mime_type.cw_set(seda_mime_type_to=[some_concept, some_other_concept])
             create('SEDAFormatLitteral',
                    user_cardinality=u'0..1',
                    seda_format_litteral=bdo)
             create('SEDAEncoding',
                    user_cardinality=u'0..1',


More information about the saem-devel mailing list