[uicfg] fix autoform_section rtags initialization
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 Jan 2010 13:32:54 +0100
changeset 4364 766359c69f2f
parent 4363 5c18d82042fb
child 4365 e2d26ff8f13b
[uicfg] fix autoform_section rtags initialization 1. when a relation is marked as inlined in the 'main' form type, we want its opposite (eg when one the other side of the relation) to be marked as hidden in the 'inlined' form type 2. when no section is specified for the 'inlined' form type, use the same as in the 'main' form type to do this properly, we need two initialization stages. The first one to handle 1., the second to handle what was done before and 2. We can't do this in a single stage because we've to know the bare value of the "opposite" tag.
rtags.py
web/uicfg.py
--- a/rtags.py	Tue Jan 26 13:27:40 2010 +0100
+++ b/rtags.py	Tue Jan 26 13:32:54 2010 +0100
@@ -73,14 +73,17 @@
                         self.del_rtag(stype, rtype, otype, tagged)
                         break
         if self._initfunc is not None:
-            for eschema in schema.entities():
-                for rschema, tschemas, role in eschema.relation_definitions(True):
-                    for tschema in tschemas:
-                        if role == 'subject':
-                            sschema, oschema = eschema, tschema
-                        else:
-                            sschema, oschema = tschema, eschema
-                        self._initfunc(self, sschema, rschema, oschema, role)
+            self.apply(schema, self._initfunc)
+
+    def apply(self, schema, func):
+        for eschema in schema.entities():
+            for rschema, tschemas, role in eschema.relation_definitions(True):
+                for tschema in tschemas:
+                    if role == 'subject':
+                        sschema, oschema = eschema, tschema
+                    else:
+                        sschema, oschema = tschema, eschema
+                    func(self, sschema, rschema, oschema, role)
 
     # rtag declaration api ####################################################
 
--- a/web/uicfg.py	Tue Jan 26 13:27:40 2010 +0100
+++ b/web/uicfg.py	Tue Jan 26 13:32:54 2010 +0100
@@ -253,11 +253,26 @@
                        'muledit': ('attributes', 'hidden'),
                        }
 
+    def init(self, schema, check=True):
+        super(AutoformSectionRelationTags, self).init(schema, check)
+        self.apply(schema, self._initfunc_step2)
+
     @staticmethod
     def _initfunc(self, sschema, rschema, oschema, role):
         formsections = self.init_get(sschema, rschema, oschema, role)
         if formsections is None:
             formsections = self.tag_container_cls()
+        if not any(tag.startswith('inlined') for tag in formsections):
+            if not rschema.final:
+                negsects = self.init_get(sschema, rschema, oschema, neg_role(role))
+                if 'main_inlined' in negsects:
+                    formsections.add('inlined_hidden')
+        key = _ensure_str_key( (sschema, rschema, oschema, role) )
+        self._tagdefs[key] = formsections
+
+    @staticmethod
+    def _initfunc_step2(self, sschema, rschema, oschema, role):
+        formsections = self.get(sschema, rschema, oschema, role)
         sectdict = _formsections_as_dict(formsections)
         if rschema in META_RTYPES:
             sectdict.setdefault('main', 'hidden')
@@ -289,12 +304,10 @@
                 if card in '1+' and not composed:
                     sectdict['muledit'] = 'attributes'
         if not 'inlined' in sectdict:
-            sectdict['inlined'] = 'hidden'
+            sectdict['inlined'] = sectdict['main']
         # recompute formsections and set it to avoid recomputing
         for formtype, section in sectdict.iteritems():
             formsections.add('%s_%s' % (formtype, section))
-        key = _ensure_str_key( (sschema, rschema, oschema, role) )
-        self._tagdefs[key] = formsections
 
     def tag_relation(self, key, formtype, section=None):
         if section is None: