Attempt to rationalize usage of rtags copy
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 09 Nov 2016 16:55:29 +0100
changeset 1961 c6614962180f
parent 1960 a7ea5df9e886
child 1962 3729d83ac7e4
Attempt to rationalize usage of rtags copy Move all (?) rtags customization for the case of simplified profiles to the ``simplified`` module. This: * avoid rtags proliferation, hence errors, * provide a single entry point for client module (eg saem_ref). The situation could be a bit improved by using implementation for cubicweb's #16164880.
views/archivetransfer.py
views/archiveunit.py
views/dataobject.py
views/simplified.py
--- a/views/archivetransfer.py	Thu Nov 03 18:29:02 2016 +0100
+++ b/views/archivetransfer.py	Wed Nov 09 16:55:29 2016 +0100
@@ -50,14 +50,10 @@
 pvs.tag_attribute(('SEDAArchiveTransfer', 'simplified_profile'), 'hidden')
 pvs.tag_attribute(('SEDAArchiveTransfer', 'compat_list'), 'hidden')
 
-simplified_pvs = copy_rtag(pvs, __name__,
-                           is_instance('SEDAArchiveTransfer') & simplified_profile())
-
 for rtype, role in at_ordered_fields:
     if rtype.endswith('agency'):
         assert role == 'subject'
         pvs.tag_subject_of(('SEDAArchiveTransfer', rtype, '*'), 'attributes')
-        simplified_pvs.tag_subject_of(('SEDAArchiveTransfer', rtype, '*'), 'attributes')
         rec.tag_subject_of(('SEDAArchiveTransfer', rtype, '*'),
                            {'rvid': 'seda.reledit.simplelink',
                             'novalue_label': _('<no value specified>')})
@@ -68,7 +64,6 @@
             simplified_section = 'attributes'
         else:
             simplified_section = 'hidden'
-        simplified_pvs.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'), simplified_section)
         rec.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'),
                           {'rvid': 'seda.reledit.text',
                            'novalue_label': _('<unauthorized>')})
--- a/views/archiveunit.py	Thu Nov 03 18:29:02 2016 +0100
+++ b/views/archiveunit.py	Wed Nov 09 16:55:29 2016 +0100
@@ -508,27 +508,6 @@
                         & is_archive_unit_ref())))
 
 
-bdo_afs = copy_rtag(afs, __name__,
-                    is_instance('SEDABinaryDataObject', 'SEDAPhysicalDataObject')
-                    & simplified_profile())
-bdo_afs.tag_object_of(
-    ('SEDADataObjectReference', 'seda_data_object_reference_id', '*'),
-    'main', 'inlined')
-bdo_afs.tag_object_of(
-    ('SEDACustodialHistoryFile', 'seda_data_object_reference_id', '*'),
-    'main', 'hidden')
-
-do_ref_afs = copy_rtag(afs, __name__,
-                       # Add yes to overtake afs for DataObjectReference defined in content
-                       is_instance('SEDADataObjectReference') & simplified_profile() & yes())
-do_ref_afs.tag_subject_of(
-    ('SEDADataObjectReference', 'seda_data_object_reference_id', '*'),
-    'inlined', 'hidden')
-do_ref_afs.tag_attribute(
-    ('SEDADataObjectReference', 'user_cardinality'),
-    'inlined', 'hidden')
-
-
 class DataObjectSimplifiedAutomaticEntityForm(widgets.SimplifiedAutomaticEntityForm):
     """On creation of a BinaryDataObject or PhysicalDataObject's in the context of a simplified
     profile, add a field to handle the creation of the relation to the archive unit specified in
--- a/views/dataobject.py	Thu Nov 03 18:29:02 2016 +0100
+++ b/views/dataobject.py	Wed Nov 09 16:55:29 2016 +0100
@@ -31,7 +31,7 @@
 from cubes.seda.xsd2yams import RDEF_CONSTRAINTS
 from cubes.seda.entities import parent_and_container, simplified_profile, full_seda2_profile
 from cubes.seda.views import rtags_from_xsd_element, add_subobject_link
-from cubes.seda.views import viewlib, copy_rtag
+from cubes.seda.views import viewlib
 from cubes.seda.views import uicfg as sedauicfg  # noqa - ensure those rules are defined first
 
 
@@ -106,10 +106,6 @@
 pvs.tag_subject_of(('*', 'seda_algorithm', '*'), 'attributes')
 pvs.tag_object_of(('*', 'seda_target', '*'), 'hidden')  # in the relationship tab
 
-simplified_pvs = copy_rtag(pvs, __name__,
-                           is_instance('SEDABinaryDataObject') & simplified_profile())
-simplified_pvs.tag_object_of(('*', 'seda_data_object_reference_id', '*'), 'hidden')
-
 for rtype in ('seda_compressed', 'seda_data_object_version_from'):
     # hide relation from autoform because of limitation of _container_eid
     afs.tag_object_of(('*', rtype, '*'), 'main', 'hidden')
@@ -117,7 +113,6 @@
     rec.tag_object_of(('*', rtype, '*'),
                       {'rvid': 'seda.reledit.complexlink',
                        'novalue_label': _('<unauthorized>')})
-    simplified_pvs.tag_object_of(('*', rtype, '*'), 'hidden')
 
 rec.tag_subject_of(('SEDABinaryDataObject', 'seda_alt_binary_data_object_attachment', '*'),
                    {'rvid': 'seda.reledit.alternative',
--- a/views/simplified.py	Thu Nov 03 18:29:02 2016 +0100
+++ b/views/simplified.py	Wed Nov 09 16:55:29 2016 +0100
@@ -15,7 +15,7 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """cubicweb-seda views configuration / overrides for simplified profiles."""
 
-from logilab.common.registry import objectify_predicate
+from logilab.common.registry import objectify_predicate, yes
 
 from cubicweb.predicates import is_instance
 from cubicweb.web.views import uicfg, autoform, formrenderers
@@ -26,8 +26,11 @@
 from cubes.seda.views import mgmt_rules, archivetransfer, dataobject, archiveunit, content  # noqa
 
 
+# Add arbitrary score using `yes` to overtake e.g. afs for DataObjectReference defined in content
 afs = uicfg.autoform_section
-simplified_afs = copy_rtag(afs, __name__, simplified_profile())
+simplified_afs = copy_rtag(afs, __name__, simplified_profile() & yes(10))
+pvs = uicfg.primaryview_section
+simplified_pvs = copy_rtag(pvs, __name__, simplified_profile())
 
 # appraisal/access rules have a single top level cardinality in simplified profile, as well as
 # always a start date. This implies:
@@ -200,3 +203,35 @@
     def render_title(self, w, form, values):
         values['title'] = values['title'].split(':', 1)[1]
         super(NotAnAltEntityInlinedFormRenderer, self).render_title(w, form, values)
+
+
+# SEDAArchiveTransfer customization
+for rtype, role in archivetransfer.at_ordered_fields:
+    if not rtype.endswith('agency'):
+        assert role == 'object'
+        if rtype in ('seda_archival_agreement', 'seda_comment'):
+            simplified_section = 'attributes'
+        else:
+            simplified_section = 'hidden'
+        simplified_pvs.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'), simplified_section)
+
+
+# SEDABinaryDataObject/SEDAPhysicalDataObject customization
+simplified_afs.tag_object_of(
+    ('SEDADataObjectReference', 'seda_data_object_reference_id', '*'),
+    'main', 'inlined')
+simplified_afs.tag_object_of(
+    ('SEDACustodialHistoryFile', 'seda_data_object_reference_id', '*'),
+    'main', 'hidden')
+simplified_pvs.tag_object_of(('*', 'seda_data_object_reference_id', '*'), 'hidden')
+for rtype in ('seda_compressed', 'seda_data_object_version_from'):
+    simplified_pvs.tag_object_of(('*', rtype, '*'), 'hidden')
+
+
+# SEDADataObjectReference
+simplified_afs.tag_subject_of(
+    ('SEDADataObjectReference', 'seda_data_object_reference_id', '*'),
+    'inlined', 'hidden')
+simplified_afs.tag_attribute(
+    ('SEDADataObjectReference', 'user_cardinality'),
+    'inlined', 'hidden')