Do not display data object's filename in two tabs and fix its reledit view
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Aug 2016 10:43:23 +0200
changeset 1586 3f8a4288c11e
parent 1579 7fcc34c201fe
child 1587 3001f8a4afdd
Do not display data object's filename in two tabs and fix its reledit view filename is a bit specific since it's a BinaryDataObject attribute retrieved from its jumped FileInfo element. As an attribute, it's displayed in the BDO main tab. As a FileInfo element, it was also catched by rtags_from_xsd_element to be displayed in the tab display FileInfo subelements. This was also screwing up its reledit view. Skipping such attributes in underlying `rtags_from_rtype_role_targets` function fixes both problems.
test/test_views.py
views/__init__.py
--- a/test/test_views.py	Fri Aug 26 09:21:45 2016 +0200
+++ b/test/test_views.py	Fri Aug 26 10:43:23 2016 +0200
@@ -15,6 +15,8 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda unit tests for schema"""
 
+import unittest
+
 from cubicweb.devtools.testlib import CubicWebTC
 from cubicweb.web import INTERNAL_FIELD_VALUE
 
@@ -126,6 +128,18 @@
             self.assertEqual(len(view.linkable_rset()), 1)
 
 
+class HelperFunctionsTC(CubicWebTC):
+    def test_rtags_from_xsd_element(self):
+        from cubicweb.web.views.uicfg import reledit_ctrl
+        from cubes.seda.views import rtags_from_xsd_element
+
+        rsection, display_ctrl = rtags_from_xsd_element('SEDABinaryDataObject', 'FileInfo')
+
+        self.assertEqual(rsection.etype_get('SEDABinaryDataObject', 'filename', 'subject'),
+                         None)
+        self.assertEqual(reledit_ctrl.etype_get('SEDABinaryDataObject', 'filename', 'subject'),
+                         {'novalue_include_rtype': False, 'novalue_label': u'<no value specified>'})
+
+
 if __name__ == '__main__':
-    import unittest
     unittest.main()
--- a/views/__init__.py	Fri Aug 26 09:21:45 2016 +0200
+++ b/views/__init__.py	Fri Aug 26 10:43:23 2016 +0200
@@ -79,6 +79,9 @@
     rsection = cwuicfg.PrimaryViewSectionRelationTags(__module__=__name__)
     for rtype, role, target in rtype_role_targets:
         if role == 'subject':
+            if target in BASE_TYPES:
+                # attribute handled by the main tab (e.g. filename), skip it
+                continue
             # mandatory elements
             relation = (etype, rtype, '*', role)
             rec.tag_subject_of(('*', rtype, '*'),