[views] Add components
authorVincent Michel <vincent.michel@logilab.fr>
Tue, 11 Dec 2012 18:50:13 +0100
changeset 16 e5e69c721f21
parent 15 0de462123b72
child 17 4c53799efd65
[views] Add components
views/components.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/components.py	Tue Dec 11 18:50:13 2012 +0100
@@ -0,0 +1,76 @@
+
+from logilab.mtconverter import xml_escape
+
+from cubicweb import tags
+from cubicweb.predicates import (none_rset, one_line_rset, is_instance,
+                                 has_related_entities, match_view)
+from cubicweb.web import component
+
+
+class ScanZipFileBox(component.CtxComponent):
+    __regid__ = 'scan.zipfile'
+    __select__ = component.CtxComponent.__select__  & is_instance('Scan', 'GenomicMeasure')
+    title = _('Download as a Zip file')
+    order = 0
+    context = 'left'
+
+    def render(self, w, **kwargs):
+        print self.cw_rset.printable_rql()
+        w(u'<div><a href="%s"><button class="btn btn-primary" '
+          'type="button"><i class="icon-download icon-white"></i>%s'
+          '</button></a></div></br>'
+          % (self._cw.build_url(vid='data-zip',
+                                rql=self.cw_rset.printable_rql()),
+             self._cw._('Download Zip')))
+
+class CsvFileBox(component.CtxComponent):
+    __regid__ = 'measure.csvfile'
+    __select__ = component.CtxComponent.__select__  & is_instance('Subject', 'Scan', 'QuestionnaireRun', 'Answer', 'GenomicMeasure', 'Snp')
+    title = _('Download as a CSV file')
+    order = 0
+    context = 'left'
+
+    def render(self, w, **kwargs):
+        w(u'<div><a href="%s"><button class="btn btn-primary" '
+          'type="button"><i class="icon-list-alt icon-white"></i>%s'
+          '</button></a></div></br>'
+          % (self._cw.build_url(vid='csvexport',
+                                rql=self.cw_rset.printable_rql()),
+             self._cw._('Download CSV')))
+
+
+class SeeSlicesBox(component.CtxComponent):
+    __regid__ = 'see-slices'
+    __select__ = component.CtxComponent.__select__  & is_instance('Scan')
+    title = _('View images')
+    order = 1
+    context = 'left'
+
+    def render(self, w, **kwargs):
+        w(u'<div><a href="%s"><button class="btn btn-primary" '
+          'type="button"><i class="icon-eye-open icon-white"></i>%s'
+          '</button></a></div></br>'
+          % (self._cw.build_url(vid='slices-view',
+                                rql=self.cw_rset.printable_rql()),
+             self._cw._('View images')))
+
+
+class RelatedSubjectsBox(component.CtxComponent):
+    __regid__ = 'related.subjects'
+    __select__ = component.CtxComponent.__select__  & is_instance('Scan',
+                                                                  'QuestionnaireRun','GenomicMeasure')
+    title = _('See the related subjects')
+    order = 1
+    context = 'left'
+
+    def render(self, w, **kwargs):
+        eids = [r[0] for r in self.cw_rset]
+        if not eids:
+            return
+        eids = ', '.join([str(e) for e in eids])
+        query = 'DISTINCT Any S WHERE X concerns S, X eid IN (%s)'  % eids
+        w(u'<div><a href="%s"><button class="btn btn-primary" '
+          'type="button"><i class="icon-user icon-white"></i>%s'
+          '</button></a></div></br>'
+          % (self._cw.build_url(vid='list', rql=query),
+             self._cw._('Related subjects')))