Rewrite history/indexation tab following folding of the SEDAContent entity
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 11 Jan 2017 12:06:48 +0100
changeset 2291 82a17de65358
parent 2272 5f865a907e6c
child 2292 7c3ee1f5bdaf
Rewrite history/indexation tab following folding of the SEDAContent entity This was done only for simplified profile, but since we folded SEDAContent entity we want this for the generic case. Along the way, introduce base classes that will be used to do more tabs like those (all the content's tab will be moved up to the archive unit). Related to #16684017
views/archiveunit.py
--- a/views/archiveunit.py	Wed Jan 11 09:50:56 2017 +0100
+++ b/views/archiveunit.py	Wed Jan 11 12:06:48 2017 +0100
@@ -31,7 +31,7 @@
 from ..entities.itree import parent_archive_unit
 from . import (CONTENT_ETYPE, add_subobject_link, add_subobjects_button, dropdown_button,
                rtags_from_rtype_role_targets, copy_rtag, has_rel_perm)
-from . import clone, viewlib, widgets, content
+from . import clone, viewlib, widgets
 from . import uicfg as sedauicfg  # noqa - ensure those rules are defined first
 
 
@@ -134,6 +134,62 @@
         parent_archive_unit(entity).view('incontext', w=self.w)
 
 
+class ArchiveUnitSubObjectsTab(viewlib.SubObjectsTab):
+    """Abstract subobjects tab specific to archive unit to handle subentities below choice>sequence
+    child transparently.
+    """
+
+    __abstract__ = True
+    __select__ = is_instance('SEDAArchiveUnit') & ~is_archive_unit_ref()
+
+    def entity_call(self, entity):
+        seq = entity.first_level_choice.content_sequence
+        self.display_add_button(seq)
+        self.display_subobjects_list(seq)
+
+    def url_params(self, entity):
+        archive_unit = parent_archive_unit(entity)
+        return {'__redirectparams': 'tab=' + self.__regid__,
+                '__redirectpath': archive_unit.rest_path()}
+
+    def parent(self, entity):
+        return parent_archive_unit(entity)
+
+
+class ArchiveUnitContentTab(tabs.TabsMixin, EntityView):
+    """Base class for tabs whose content is generated by redirecting to a view on archive unit's
+    content.
+    """
+
+    __abstract__ = True
+    __select__ = ArchiveUnitSubObjectsTab.__select__
+    content_vid = None  # set in concrete class
+
+    def entity_call(self, entity):
+        seq = entity.first_level_choice.content_sequence
+        seq.view(self.content_vid, w=self.w)
+
+
+class ContentSubObjectsView(viewlib.SubObjectsTab):
+    """Base class to display subobjects of archive unit's content as if they were directly linked
+    to it.
+    """
+
+    __abstract__ = True
+    __select__ = is_instance(CONTENT_ETYPE)
+    tabid = None  # set in concrete class
+
+    def url_params(self, entity):
+        params = super(ContentSubObjectsView, self).url_params(entity)
+        params['__redirectpath'] = self.parent(entity).rest_path()
+        return params
+
+    def parent(self, entity):
+        return (entity
+                .reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management[0]
+                .reverse_seda_alt_archive_unit_archive_unit_ref_id[0])
+
+
 class ArchiveUnitTabbedPrimaryView(tabs.TabbedPrimaryView):
     __select__ = is_instance('SEDAArchiveUnit')
 
@@ -141,10 +197,12 @@
         'main_tab',
         _('seda_management_tab'),
         _('seda_au_content_tab'),
-        _('seda_au_indexation_tab'),
-        _('seda_history_tab'),
         _('seda_archive_units_tab'),
         _('seda_au_data_objects_refs_tab'),
+        # Content tabs
+        _('seda_indexation_tab'),
+        _('seda_history_tab'),
+
     ]
 
     def entity_call(self, entity, **kwargs):
@@ -208,28 +266,6 @@
     )
 
 
-class ArchiveUnitSubObjectsTab(viewlib.SubObjectsTab):
-    """Abstract subobjects tab specific to archive unit to handle subentities below choice>sequence
-    child transparently.
-    """
-
-    __abstract__ = True
-    __select__ = is_instance('SEDAArchiveUnit') & ~is_archive_unit_ref()
-
-    def entity_call(self, entity):
-        seq = entity.first_level_choice.content_sequence
-        self.display_add_button(seq)
-        self.display_subobjects_list(seq)
-
-    def url_params(self, entity):
-        archive_unit = parent_archive_unit(entity)
-        return {'__redirectparams': 'tab=' + self.__regid__,
-                '__redirectpath': archive_unit.rest_path()}
-
-    def parent(self, entity):
-        return parent_archive_unit(entity)
-
-
 class SimplifiedArchiveUnitContentTab(tabs.TabsMixin, EntityView):
     """Display content information about an archive unit of a simplified profile: direct link to
     some content's attributes.
@@ -263,65 +299,61 @@
     rsection, display_ctrl = rtags_from_rtype_role_targets(CONTENT_ETYPE, rtype_role_targets)
 
 
-class SimplifiedArchiveUnitIndexationTab(tabs.TabsMixin, EntityView):
-    """Display content's indexation about an archive unit of a simplified profile.
-    """
+# indexation tab ###############################################################
 
-    __regid__ = 'seda_au_indexation_tab'
-    __select__ = ArchiveUnitSubObjectsTab.__select__ & simplified_profile()
+class ArchiveUnitIndexationTab(ArchiveUnitContentTab):
+    """Display content's indexation about an archive unit."""
 
-    def entity_call(self, entity):
-        seq = entity.first_level_choice.content_sequence
-        seq.view('seda_content_indexation_tab', w=self.w)
+    __regid__ = 'seda_indexation_tab'
+    content_vid = 'seda_content_indexation'
 
 
-class SimplifiedArchiveUnitContentIndexationView(content.ContentIndexationTab):
+class ContentIndexationView(ContentSubObjectsView):
+    """Display indexation (keywords and tags) about an archive unit content."""
 
-    __select__ = content.ContentIndexationTab.__select__ & simplified_profile()
-
-    rtype_role_targets = [('seda_keyword', 'object', 'SEDAKeyword')]
-    tabid = 'seda_au_indexation_tab'
+    __regid__ = 'seda_content_indexation'
+    tabid = ArchiveUnitIndexationTab.__regid__
 
-    def url_params(self, entity):
-        params = super(SimplifiedArchiveUnitContentIndexationView, self).url_params(entity)
-        params['__redirectpath'] = self.parent(entity).rest_path()
-        return params
+    rtype_role_targets = [
+        ('seda_keyword', 'object', 'SEDAKeyword'),
+        ('seda_tag', 'object', 'SEDATag'),
+    ]
 
-    def parent(self, entity):
-        return (entity
-                .reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management[0]
-                .reverse_seda_alt_archive_unit_archive_unit_ref_id[0])
+    _('creating SEDAKeyword (SEDAKeyword seda_keyword '
+      'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement %(linkto)s)')
+    _('creating SEDATag (SEDATag seda_tag '
+      'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement %(linkto)s)')
 
 
-class SimplifiedArchiveUnitHistoryTab(tabs.TabsMixin, EntityView):
-    """Display content's custodial history about an archive unit of a simplified profile.
-    """
+class SimplifiedArchiveUnitContentIndexationView(ContentIndexationView):
 
-    __regid__ = 'seda_history_tab'
-    __select__ = ArchiveUnitSubObjectsTab.__select__ & simplified_profile()
+    __select__ = ContentIndexationView.__select__ & simplified_profile()
 
-    def entity_call(self, entity):
-        seq = entity.first_level_choice.content_sequence
-        seq.view('seda_content_history_tab', w=self.w)
+    rtype_role_targets = [('seda_keyword', 'object', 'SEDAKeyword')]
 
 
-class SimplifiedArchiveUnitContentHistoryView(content.ContentHistoryTab):
+# history tab ##################################################################
 
-    __select__ = content.ContentHistoryTab.__select__ & simplified_profile()
+class ArchiveUnitHistoryTab(ArchiveUnitContentTab):
+    """Display content's custodial history about an archive unit."""
 
-    tabid = 'seda_history_tab'
+    __regid__ = 'seda_history_tab'
+    content_vid = 'seda_content_history'
+
 
-    def url_params(self, entity):
-        params = super(SimplifiedArchiveUnitContentHistoryView, self).url_params(entity)
-        params['__redirectpath'] = self.parent(entity).rest_path()
-        return params
+class ContentHistoryView(ContentSubObjectsView):
+    """Display custodial history information about an archive unit content."""
+
+    __regid__ = 'seda_content_history'
+    tabid = ArchiveUnitHistoryTab.__regid__
 
-    def parent(self, entity):
-        # return parent archive unit
-        return (entity
-                .reverse_seda_seq_alt_archive_unit_archive_unit_ref_id_management[0]
-                .reverse_seda_alt_archive_unit_archive_unit_ref_id[0])
+    rtype_role_targets = [('seda_custodial_history_item', 'object', None)]
 
+    _('creating SEDACustodialHistoryItem (SEDACustodialHistoryItem seda_custodial_history_item '
+      'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement %(linkto)s)')
+
+
+# archive units tab ############################################################
 
 class ArchiveUnitArchiveUnitsTab(tabs.TabsMixin, EntityView):
     """Tab for sub-archive units of an archive unit"""