[saem-devel] [PATCH 6 of 9] [org] Refactor RTypeList view to inherit from RelatedEntitiesListView

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Jan 27 16:02:54 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485331207 -3600
#      Wed Jan 25 09:00:07 2017 +0100
# Node ID 592c2f80165a8f3f2eb84229a2a652b252c7ed33
# Parent  2ebc393146a67ef760440abfa0a3b7526019b027
[org] Refactor RTypeList view to inherit from RelatedEntitiesListView

and explain the differences.

diff --git a/cubicweb_saem_ref/views/org.py b/cubicweb_saem_ref/views/org.py
--- a/cubicweb_saem_ref/views/org.py
+++ b/cubicweb_saem_ref/views/org.py
@@ -18,12 +18,11 @@ Agent types)
 """
 
 from six import text_type
 
 from cubicweb import tags, _
-from cubicweb.predicates import (partial_has_related_entities, is_instance, match_kwargs,
-                                 relation_possible)
+from cubicweb.predicates import is_instance, match_kwargs, relation_possible
 from cubicweb.view import EntityView
 from cubicweb.uilib import js
 from cubicweb.web import formwidgets as fw
 from cubicweb.web.views import ajaxcontroller, tabs, uicfg
 
@@ -217,10 +216,27 @@ class LinkedObjectsTab(SubviewsTabView):
             self.w(tags.div(id=divid, style='display: none'))
             self.w(dropdown_button(self._cw._('add'), links))
             self.w(tags.div(klass='clearfix'))
 
 
+class RTypeListView(RelatedEntitiesListView):
+    """List of related entities the organization unit is using.
+
+    Slightly different from default RelatedEntitiesListView behaviour:
+
+    * only include button delete the relation (not the entity),
+    * give extra arguments so the permission to delete the relation is checked.
+    """
+    __abstract__ = True
+
+    @property
+    def subvid_kwargs(self):
+        entity = self.cw_rset.one()
+        return {'unit': entity, '__redirectpath': entity.rest_path(),
+                'rtype': self.rtype, 'role': self.role}
+
+
 class DepositOrganizationUnitConceptsProfilesTab(LinkedObjectsTab):
     """SEDA profiles and concept schemes used by an organization unit with role "deposit"."""
     __regid__ = 'saem_ou_concepts_profiles_tab'
     __select__ = EntityView.__select__ & is_instance('OrganizationUnit')
     required_role = 'deposit'
@@ -259,27 +275,10 @@ def add_relations(self, eid, rtype, role
     for related_eid in related_eids:
         self._cw.execute(rql, {'eids': eid if role == 'subject' else int(related_eid),
                                'eido': eid if role == 'object' else int(related_eid)})
 
 
-class RTypeListView(EntityView):
-    """List of related entities the organization unit is using"""
-    __abstract__ = True
-    __select__ = EntityView.__select__ & partial_has_related_entities()
-    rtype = None
-    role = None
-
-    def entity_call(self, entity, **kwargs):
-        title = (self._cw.__(self.rtype + '_object')
-                 if self.role == 'object' else self._cw.__(self.rtype))
-        self.w(tags.h2(self._cw._(title)))
-        rset = entity.related(self.rtype, self.role)
-        subvid = 'saem.listitem'
-        self._cw.view('list', rset=rset, w=self.w, subvid=subvid, unit=entity,
-                      rtype=self.rtype, role=self.role, __redirectpath=entity.rest_path())
-
-
 class OrganizationUnitUsingConceptSchemeListView(RTypeListView):
     """View for ConceptScheme, to be displayed in the context of an organization unit."""
     __regid__ = 'saem.ou.schemes'
     rtype = 'related_concept_scheme'
     role = 'subject'


More information about the saem-devel mailing list