Basic uicfg setup for simplified archive transfer entity
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 25 Aug 2016 09:56:42 +0200
changeset 1498 7c4ea7a5677c
parent 1497 cb556ac5ce2f
child 1499 b4cf3e8c8d2e
Basic uicfg setup for simplified archive transfer entity * hide all SEDA fields but archival agreement from primary view, * hide all SEDA fields from main form, since we don't want to handle the simplified form switch yet, * hide code list versions, data objects and related transfers tabs.
views/archivetransfer.py
--- a/views/archivetransfer.py	Thu Aug 25 09:50:23 2016 +0200
+++ b/views/archivetransfer.py	Thu Aug 25 09:56:42 2016 +0200
@@ -21,9 +21,9 @@
 from cubicweb.web import formwidgets as fw
 from cubicweb.web.views import tabs, uicfg, reledit
 
-from cubes.seda.entities import full_seda2_profile
+from cubes.seda.entities import full_seda2_profile, simplified_profile
 from cubes.seda.views import rtags_from_xsd_element, rtags_from_rtype_role_targets
-from cubes.seda.views import viewlib
+from cubes.seda.views import viewlib, copy_rtag
 from cubes.seda.views import uicfg as sedauicfg  # noqa - ensure those rules are defined first
 
 _ = unicode
@@ -40,24 +40,34 @@
 pvs = uicfg.primaryview_section
 pvdc = uicfg.primaryview_display_ctrl
 rec = uicfg.reledit_ctrl
+afs = uicfg.autoform_section
 affk = uicfg.autoform_field_kwargs
 
 pvs.tag_attribute(('SEDAArchiveTransfer', 'title'), 'hidden')
 pvs.tag_attribute(('SEDAArchiveTransfer', 'simplified_profile'), '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>')})
     else:
         assert role == 'object'
         pvs.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'), 'attributes')
+        simplified_section = 'attributes' if rtype == 'seda_archival_agreement' else 'hidden'
+        simplified_pvs.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'), simplified_section)
         rec.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'),
                           {'rvid': 'seda.reledit.text',
                            'novalue_label': _('<unauthorized>')})
+        # hide extra-fields from main form, as their appearance depends on the simplified_profile
+        # switch
+        afs.tag_object_of(('*', rtype, 'SEDAArchiveTransfer'), 'main', 'hidden')
 
 affk.set_field_kwargs('SEDAArchiveTransfer', 'title', widget=fw.TextInput({'size': 80}))
 affk.set_fields_order('SEDAArchiveTransfer',
@@ -108,7 +118,9 @@
 class ArchiveTransferDataObjectsTab(viewlib.SubObjectsTab):
     """Tab for data objects of an archive transfer"""
     __regid__ = 'seda_at_data_objects_tab'
-    __select__ = is_instance('SEDAArchiveTransfer')
+    __select__ = (tabs.PrimaryTab.__select__
+                  & is_instance('SEDAArchiveTransfer')
+                  & full_seda2_profile())
 
     rtype_role_targets = [
         ('seda_binary_data_object', 'object', 'SEDABinaryDataObject'),
@@ -144,7 +156,9 @@
 class ArchiveTransferRelatedTransfersTab(viewlib.SubObjectsTab):
     """Tab for previous transfers related to an archive transfer"""
     __regid__ = 'seda_at_related_transfers_tab'
-    __select__ = is_instance('SEDAArchiveTransfer') & full_seda2_profile()
+    __select__ = (tabs.PrimaryTab.__select__
+                  & is_instance('SEDAArchiveTransfer')
+                  & full_seda2_profile())
 
     rtype_role_targets = [('seda_related_transfer_reference', 'object', None)]