Simplify the view library
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 06 Jan 2017 12:35:08 +0100
changeset 2223 f0cdce099e45
parent 2222 f60753a132cf
child 2224 c0d56eed71cd
Simplify the view library * seda.list_meta turned into seda.listitem.content, which is overriden when desired, instead of overriding business_vid value of it's "parent" view, * this allows to kill the seda.type_listitem view, * seda.type_meta is kept because it's used from outside the context of list item content. IMO this makes things slightly easier to grasp. Fix base class used to build KeywordBusinessValueEntityView's selector along the way.
views/content.py
views/viewlib.py
--- a/views/content.py	Thu Jan 05 18:06:37 2017 +0100
+++ b/views/content.py	Fri Jan 06 12:35:08 2017 +0100
@@ -1,4 +1,4 @@
-# copyright 2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2016-2017 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
 #
 # This program is free software: you can redistribute it and/or modify it under
@@ -213,7 +213,6 @@
         ('seda_addressee_from', 'object', None),
         ('seda_recipient_from', 'object', None),
     ]
-    subvid = 'seda.type_listitem'
 
     _('creating SEDAWriter (SEDAWriter seda_writer_from SEDAContent %(linkto)s)')
     _('creating SEDAAddressee (SEDAAddressee seda_addressee_from SEDAContent %(linkto)s)')
@@ -229,13 +228,23 @@
     rtype_role_targets = [('seda_spatial', 'object', None),
                           ('seda_temporal', 'object', None),
                           ('seda_juridictional', 'object', None)]
-    subvid = 'seda.type_listitem'
 
     _('creating SEDASpatial (SEDASpatial seda_spatial SEDAContent %(linkto)s)')
     _('creating SEDATemporal (SEDATemporal seda_temporal SEDAContent %(linkto)s)')
     _('creating SEDAJuridictional (SEDAJuridictional seda_juridictional SEDAContent %(linkto)s)')
 
 
+class TypeListItemContentView(viewlib.ListItemContentView):
+    """Extended list item content view including the entity's type (for case where the list may
+    include entities of different types).
+    """
+    __select__ = is_instance('SEDAWriter', 'SEDAAddressee', 'SEDARecipient',
+                             'SEDASpatial', 'SEDATemporal', 'SEDAJuridictional')
+
+    def entity_call(self, entity):
+        entity.view('seda.type_meta', w=self.w)
+
+
 class ContentIndexationTab(viewlib.SubObjectsTab):
     """Display indexation (keywords and tags) about an archive unit content."""
 
@@ -311,9 +320,9 @@
             afs.tag_subject_of(('SEDAContent', rtype, '*'), 'main', 'hidden')
 
 
-class KeywordBusinessValueEntityView(viewlib.LinkMetaEntityView):
+class KeywordBusinessValueEntityView(viewlib.ListItemContentView):
 
-    __select__ = viewlib.BusinessValueEntityView.__select__ & is_instance('SEDAKeyword')
+    __select__ = viewlib.ListItemContentView.__select__ & is_instance('SEDAKeyword')
 
     def entity_call(self, entity):
         if entity.seda_keyword_content[0].keyword_content:
@@ -387,9 +396,9 @@
                                   ('seda_repository_archive_unit_pid', 'object')])
 
 
-class EventLinkMetaEntityView(viewlib.LinkMetaEntityView):
+class EventListItemContentView(viewlib.ListItemContentView):
 
-    __select__ = viewlib.LinkMetaEntityView.__select__ & is_instance('SEDAEvent')
+    __select__ = viewlib.ListItemContentView.__select__ & is_instance('SEDAEvent')
 
     def entity_call(self, entity):
         entity.view('seda.xsdmeta', w=self.w, skip_one_card=True, with_annotation=False)
@@ -424,12 +433,12 @@
                                     ('seda_event_detail', 'object')])
 
 
-class CustodialHistoryItemLinkMetaEntityView(viewlib.LinkMetaEntityView):
+class CustodialHistoryItemListItemContentView(viewlib.ListItemContentView):
 
-    __select__ = viewlib.LinkMetaEntityView.__select__ & is_instance('SEDACustodialHistoryItem')
+    __select__ = viewlib.ListItemContentView.__select__ & is_instance('SEDACustodialHistoryItem')
 
     def entity_call(self, entity):
-        super(CustodialHistoryItemLinkMetaEntityView, self).entity_call(entity)
+        super(CustodialHistoryItemListItemContentView, self).entity_call(entity)
         if entity.reverse_seda_when:
             when = entity.reverse_seda_when[0]
             if when.user_cardinality == '1':
--- a/views/viewlib.py	Thu Jan 05 18:06:37 2017 +0100
+++ b/views/viewlib.py	Fri Jan 06 12:35:08 2017 +0100
@@ -142,15 +142,6 @@
         return value
 
 
-class LinkMetaEntityView(EntityView):
-    """Glue seda.business and seda.xsdmeta views together, for use within list."""
-    __regid__ = 'seda.link_meta'
-
-    def entity_call(self, entity):
-        entity.view('seda.business', w=self.w)
-        entity.view('seda.xsdmeta', w=self.w, skip_one_card=True)
-
-
 class TypeAndMetaEntityView(EntityView):
     """Glue entity's type, seda.business and seda.xsdmeta views together, for use within alternative
     """
@@ -168,10 +159,9 @@
     """
     __regid__ = 'seda.listitem'
     __select__ = EntityView.__select__ & match_kwargs('parent', 'tabid')
-    business_vid = 'seda.link_meta'
 
     def entity_call(self, entity, parent, tabid, edit=True, delete=True):
-        entity.view(self.business_vid, w=self.w)
+        entity.view('seda.listitem.content', w=self.w)
         if entity.cw_has_perm('update'):
             self._cw.add_js(('cubicweb.ajax.js', 'cubes.seda.js'))
             editurlparams = {
@@ -189,10 +179,13 @@
                 self.w(u'</div>')
 
 
-class TypeListItemView(ListItemView):
-    """Extended 'oneline' view for entities with type."""
-    __regid__ = 'seda.type_listitem'
-    business_vid = 'seda.type_meta'
+class ListItemContentView(EntityView):
+    """Glue seda.business and seda.xsdmeta views together, for use within list."""
+    __regid__ = 'seda.listitem.content'
+
+    def entity_call(self, entity):
+        entity.view('seda.business', w=self.w)
+        entity.view('seda.xsdmeta', w=self.w, skip_one_card=True)
 
 
 class PrimaryTabWithoutBoxes(tabs.PrimaryTab):