[html gen] Support for list as target value
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 12 Oct 2017 15:24:11 +0200
changeset 2762 1d2ccc92ac3c
parent 2760 cc3b3e0f6d42
child 2763 49e134799b43
[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
cubicweb_seda/entities/html_generation.py
test/test_profile_generation.py
--- a/cubicweb_seda/entities/html_generation.py	Thu Oct 12 12:52:30 2017 +0200
+++ b/cubicweb_seda/entities/html_generation.py	Thu Oct 12 15:24:11 2017 +0200
@@ -238,17 +238,26 @@
                          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:
--- a/test/test_profile_generation.py	Thu Oct 12 12:52:30 2017 +0200
+++ b/test/test_profile_generation.py	Thu Oct 12 15:24:11 2017 +0200
@@ -609,6 +609,7 @@
             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',
@@ -629,6 +630,7 @@
             # 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)