[components] Add a box for the results files, see #3296292
authorVincent Michel <vincent.michel@logilab.fr>
Mon, 02 Dec 2013 16:58:01 +0100
changeset 534 568039a904f9
parent 516 66fd5f5693c6
child 535 2ebd52d7ff29
[components] Add a box for the results files, see #3296292
views/components.py
--- a/views/components.py	Tue Nov 26 10:31:04 2013 +0000
+++ b/views/components.py	Mon Dec 02 16:58:01 2013 +0100
@@ -21,7 +21,7 @@
 from cubicweb import tags
 from cubicweb.predicates import (none_rset, one_line_rset, is_instance, nonempty_rset,
                                  has_related_entities, match_view, match_user_groups,
-                                 anonymous_user)
+                                 anonymous_user, relation_possible)
 from cubicweb.web import component
 from cubicweb.web.views.boxes import SearchBox, EditBox
 from cubicweb.web.views.bookmark import BookmarksBox
@@ -227,6 +227,31 @@
 
 
 ###############################################################################
+### DATA BOXES ################################################################
+###############################################################################
+class BrainomicsResultsFileBox(component.CtxComponent):
+    __select__ = (component.CtxComponent.__select__ & nonempty_rset()
+                  & relation_possible('results_file') & one_line_rset())
+    context = 'left'
+    order = 2
+    __regid__ = 'ctx-data-box'
+
+    def render(self, w, **kwargs):
+        entity = self.cw_rset.get_entity(0, 0)
+        if not entity.results_file:
+            return
+        w(u'<div class="well">')
+        w(u'<h4>%s</h4>' % self._cw._('Results files'))
+        w(u'<ul>')
+        for _file in entity.results_file:
+            w(u'<li>%s<a href="%s" title="%s">%s</a></li>'
+              % (_file.view('icon'), _file.absolute_url(),
+                 xml_escape(_file.dc_title()), xml_escape(_file.dc_title()[:20]+'...')))
+        w(u'</ul>')
+        w(u'</div>')
+
+
+###############################################################################
 ### REGISTRATION CALLBACK #####################################################
 ###############################################################################
 BookmarksBox.__select__ = BookmarksBox.__select__ & match_user_groups('users', 'managers')