[ui] Don't display cardinality on data object reference for the typed reference alternative
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 12 Jul 2016 14:33:31 +0200
changeset 1413 ea9e4c81b4aa
parent 1412 4ab284d9934d
child 1414 9ee425bbaedc
[ui] Don't display cardinality on data object reference for the typed reference alternative Is this context, user should not have this option which only makes sense for data object reference directly from archive units.
views/content.py
--- a/views/content.py	Tue Jul 12 10:47:46 2016 +0200
+++ b/views/content.py	Tue Jul 12 14:33:31 2016 +0200
@@ -15,6 +15,9 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda views for content of archive units."""
 
+from copy import deepcopy
+
+from logilab.common.registry import objectify_predicate
 from logilab.mtconverter import xml_escape
 
 from cubicweb.predicates import is_instance
@@ -29,6 +32,33 @@
 
 _ = unicode
 
+pvs = uicfg.primaryview_section
+pvdc = uicfg.primaryview_display_ctrl
+rec = uicfg.reledit_ctrl
+afs = uicfg.autoform_section
+affk = uicfg.autoform_field_kwargs
+
+
+@objectify_predicate
+def is_typed_reference(cls, req, entity=None, **kwargs):
+    """Return positive score for content's typed data object references (IsPartOf, VersionOf, etc.), not
+    used those starting directly from archive unit.
+    """
+    if entity is None or not entity.has_eid():
+        try:
+            rtype, eid, role = req.form['__linkto'].split(':')
+        except KeyError:
+            pass
+        else:
+            if rtype == 'seda_data_object_reference':
+                entity = req.entity_from_eid(eid)
+    else:
+        entity = entity.seda_data_object_reference[0]
+    if entity is not None and entity.cw_etype == 'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement':
+        return 0
+    return 1
+
+
 content_ordered_fields = [
     ('seda_description_level', 'subject'),
     ('seda_title', 'object'),
@@ -40,13 +70,6 @@
     ('seda_language_from', 'object'),
     ('seda_description_language_from', 'object'),
 ]
-
-pvs = uicfg.primaryview_section
-pvdc = uicfg.primaryview_display_ctrl
-rec = uicfg.reledit_ctrl
-afs = uicfg.autoform_section
-affk = uicfg.autoform_field_kwargs
-
 for rtype, role in content_ordered_fields:
     if role == 'subject':
         pvs.tag_subject_of(('SEDAContent', rtype, '*'), 'attributes')
@@ -343,3 +366,9 @@
                     content = xml_escape(self._cw._('<no value specified>'))
                 alternatives.append(value.dc_type() + ' ' + content)
         return (u'<b>{0}</b>'.format(self._cw._(' ALT_I18N '))).join(alternatives)
+
+
+dor_afs = deepcopy(afs)
+dor_afs.__module__ = __name__
+dor_afs.__select__ = is_instance('SEDADataObjectReference') & is_typed_reference()
+dor_afs.tag_attribute(('SEDADataObjectReference', 'user_cardinality'), 'main', 'hidden')