Use ArchiveUnitSubObjectsTab as parent class of ArchiveUnitArchiveUnitsTab
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 19 Jan 2017 19:48:49 +0100
changeset 2310 d7f6c9b89b7b
parent 2309 b4e5981f7aad
child 2311 1fe3dfa71ce3
Use ArchiveUnitSubObjectsTab as parent class of ArchiveUnitArchiveUnitsTab This allows to factorize url parameters generation and to have consistent separation of concerns.
views/archiveunit.py
--- a/views/archiveunit.py	Thu Jan 19 19:53:11 2017 +0100
+++ b/views/archiveunit.py	Thu Jan 19 19:48:49 2017 +0100
@@ -887,11 +887,10 @@
 
 # archive units tab ############################################################
 
-class ArchiveUnitArchiveUnitsTab(tabs.TabsMixin, EntityView):
+class ArchiveUnitArchiveUnitsTab(ArchiveUnitSubObjectsTab):
     """Tab for sub-archive units of an archive unit"""
 
     __regid__ = 'seda_archive_units_tab'
-    __select__ = is_instance('SEDAArchiveUnit') & ~is_archive_unit_ref()
 
     rtype = 'seda_archive_unit'
     role = 'object'
@@ -903,18 +902,18 @@
     _('creating SEDAArchiveUnit (SEDAArchiveUnit seda_archive_unit '
       'SEDASeqAltArchiveUnitArchiveUnitRefIdManagement %(linkto)s)')
 
-    def entity_call(self, entity):
-        urlparams = {'__redirectparams': 'tab=' + self.__regid__,
-                     '__redirectpath': entity.rest_path()}
+    def display_add_button(self, entity):
+        urlparams = self.url_params(entity)
         links = add_links_with_custom_arguments(entity, self.rtype, self.role, urlparams,
                                                 self.unit_custom_arguments)
         viewlib.display_add_button(self.w, links, self._cw.__('add'))
-        seq = entity.first_level_choice.content_sequence
-        rset = seq.related(self.rtype, self.role)
+
+    def display_subobjects_list(self, entity):
+        rset = entity.related(self.rtype, self.role)
         if rset:
             subvid = 'seda.listitem'
-            self._cw.view('list', rset=rset, w=self.w, subvid=subvid, parent=entity,
-                          tabid=self.__regid__)
+            self._cw.view('list', rset=rset, w=self.w, subvid=subvid,
+                          parent=self.parent(entity), tabid=self.__regid__)
 
 
 class SimplifiedArchiveUnitArchiveUnitsTab(ArchiveUnitArchiveUnitsTab):