[views] Create a secondary view for documentation card
authorVincent Michel <vincent.michel@logilab.fr>
Wed, 17 Jul 2013 11:41:08 +0200
changeset 276 8425e2b8e2b2
parent 275 e52dd8d14a58
child 277 60eba9b3800b
[views] Create a secondary view for documentation card
views/secondary.py
--- a/views/secondary.py	Wed Jul 17 12:07:51 2013 +0200
+++ b/views/secondary.py	Wed Jul 17 11:41:08 2013 +0200
@@ -15,16 +15,44 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
+from logilab.mtconverter import xml_escape
 
-
+from cubicweb.predicates import is_instance
+from cubicweb.view import EntityView
 from cubicweb.web.views.baseviews import ListView
 
-class OrbuiListView(ListView):
+
+###############################################################################
+### LIST VIEW #################################################################
+###############################################################################
+class BrainomicsListView(ListView):
 
     def call(self, klass=None, title=None, subvid=None, listid=None, **kwargs):
-        super(OrbuiListView, self).call(klass="unstyled stripped",
-                                        title=title, subvid=subvid, listid=listid, **kwargs)
+        super(BrainomicsListView, self).call(klass="unstyled stripped",
+                                             title=title, subvid=subvid,
+                                             listid=listid, **kwargs)
+
+
+###############################################################################
+### CARD VIEW #################################################################
+###############################################################################
+class BrainomicsCardDocumentation(EntityView):
+    __regid__ = 'documentation_card'
+    __select__ = EntityView.__select__ & is_instance('Card')
+
+    def call(self, rset=None, **kwargs):
+        rset = rset or self.cw_rset
+        w = self.w
+        w(u'<div>')
+        for entity in rset.entities():
+            w(u'<h2>%s</h2>' % xml_escape(entity.title))
+            if entity.synopsis:
+                w(u'<blockquote><p>%s</p></blockquote>' % xml_escape(entity.synopsis))
+            if entity.content:
+                w(entity.content)
+        w(u'</div>')
 
 
 def registration_callback(vreg):
-    vreg.register_and_replace(OrbuiListView, ListView)
+    vreg.register_all(globals().values(), __name__, (BrainomicsListView,))
+    vreg.register_and_replace(BrainomicsListView, ListView)