[code gen] Record XSD tag name and documentation on RdefMapping objects
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 09 Oct 2017 17:00:32 +0200
changeset 2737 94862fecbcfd
parent 2736 6622d3157176
child 2738 9d7e736c3449
[code gen] Record XSD tag name and documentation on RdefMapping objects so that they may be used later to generate tooltips in the UI. This requires using yet unreleased pyxst to get support for documentation elements. Related to #17106808
cubicweb_seda/xsd2yams.py
dev-requirements.txt
--- a/cubicweb_seda/xsd2yams.py	Mon Oct 09 16:56:52 2017 +0200
+++ b/cubicweb_seda/xsd2yams.py	Mon Oct 09 17:00:32 2017 +0200
@@ -302,7 +302,10 @@
 
 class RdefMapping(object):
     """Map a relation to a simple relation definition."""
-    def __init__(self, subjtype, rtype, objtypes, card, composite=None, inlined=False, alias=None):
+
+    def __init__(self, subjtype, rtype, objtypes, card,
+                 composite=None, inlined=False, alias=None,
+                 desc=(), element_name=None):
         assert len(card) == 2, card
         self.subjtype = subjtype
         self.rtype = rtype
@@ -311,6 +314,8 @@
         self.composite = composite
         self.inlined = inlined
         self.alias = alias
+        self.desc = desc  # list of text collected under xsd:documentation
+        self.element_name = element_name  # XML tag name
 
     @property
     def final(self):
@@ -361,6 +366,8 @@
                     # (it should be systematically added in XSD for the later)
                     if rtype == 'seda_uri' and emapping.etype == 'SEDAAttachment':
                         continue
+                    rdef_options['desc'] = getattr(occ.target, 'desc', ())
+                    rdef_options['element_name'] = getattr(occ.target, 'local_name', None)
                     if role == 'subject':
                         subjtype = current_emapping.etype
                         objtype = target_etype
@@ -421,11 +428,14 @@
             self.ordered.append(emapping)
         return emapping
 
-    def map_rdef(self, subjtype, rtype, objtypes, card, composite=None, inlined=False, alias=None):
+    def map_rdef(self, subjtype, rtype, objtypes, card,
+                 composite=None, inlined=False, alias=None,
+                 desc=(), element_name=None):
         """Register a relation definition."""
         objtypes = _ensure_set(objtypes)
         mapping = RdefMapping(subjtype, rtype, objtypes,
-                              card=card, composite=composite, inlined=inlined, alias=alias)
+                              card=card, composite=composite, inlined=inlined, alias=alias,
+                              desc=desc, element_name=element_name)
         self.ordered.append(mapping)
         return mapping
 
--- a/dev-requirements.txt	Mon Oct 09 16:56:52 2017 +0200
+++ b/dev-requirements.txt	Mon Oct 09 17:00:32 2017 +0200
@@ -1,1 +1,2 @@
 pytest
+http://hg.logilab.org/review/pyxst/archive/tip.tar.bz2#egg=pyxst