Reimplement hiding of user_cardinality by customizing entity form
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 21 Oct 2016 17:34:40 +0200
changeset 1949 c61b45994daa
parent 1948 52a312af8f19
child 1950 4775f5b15412
Reimplement hiding of user_cardinality by customizing entity form instead of a simple uicfg rule which isn't enough because of the ambivalent usage of SEDAStartDate: it was also currently hiding it from archive unit's start date which is undesirable.
views/simplified.py
--- a/views/simplified.py	Fri Oct 21 17:33:20 2016 +0200
+++ b/views/simplified.py	Fri Oct 21 17:34:40 2016 +0200
@@ -40,9 +40,26 @@
                              'main', 'hidden')
 simplified_afs.tag_attribute(('SEDASeqAccessRuleRule', 'user_cardinality'),
                              'main', 'hidden')
-# 2. hide start date's cardinality
-simplified_afs.tag_attribute(('SEDAStartDate', 'user_cardinality'),
-                             'main', 'hidden')
+
+
+# 2. hide start date's cardinality - uicfg is not enough since we want it when edited in the context
+# of SEDAContent but not of rule entity types
+
+class StartDateAutomaticEntityForm(autoform.AutomaticEntityForm):
+    __select__ = (is_instance('SEDAStartDate')
+                  & simplified_profile())
+
+    def editable_attributes(self, strict=False):
+        """return a list of (relation schema, role) to edit for the entity"""
+        attributes = super(StartDateAutomaticEntityForm, self).editable_attributes(strict)
+        if self.linked_to.get(('seda_start_date', 'subject')):
+            eid = self.linked_to[('seda_start_date', 'subject')][0]
+            start_date_of = self._cw.entity_from_eid(eid)
+        else:
+            start_date_of = self.edited_entity.reverse_start_date_of
+        if start_date_of.cw_etype != 'SEDAContent':
+            attributes.remove(('user_cardinality', 'subject'))
+        return attributes
 
 
 class RuleAutomaticEntityForm(autoform.AutomaticEntityForm):