[view] Add primary view
authorVincent Michel <vincent.michel@logilab.fr>
Tue, 11 Dec 2012 14:03:20 +0100
changeset 7 b790dac9b452
parent 6 d09e976ac97f
child 8 776e19aab816
[view] Add primary view
views/primary.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/primary.py	Tue Dec 11 14:03:20 2012 +0100
@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+# copyright 2012 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
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# 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/>.
+
+"""cubicweb-opencat views/forms/actions/components for web ui"""
+
+from cubicweb.selectors import is_instance
+from cubicweb.web.views.primary import PrimaryView
+
+
+class SubjectPrimaryView(PrimaryView):
+    __select__ = PrimaryView.__select__ & is_instance('Subject')
+
+    def call(self, rset=None):
+        entity = self.cw_rset.get_entity(0,0)
+        self.w(u'<div class="well">')
+        self.w(u'<div class="page-header">')
+        # Header
+        self.w(u'<h1>%s</h1>' % entity.dc_title())
+        self.w(u'</div>')
+        self.w(u'<dl class="dl-horizontal">')
+        self.w(u'<dt>%s</dt><dd>%s</dd>' % (self._cw._('Age'), entity.age))
+        self.w(u'<dt>%s</dt><dd>%s</dd>' % (self._cw._('Handedness'), entity.handedness))
+        self.w(u'<dt>%s</dt><dd>%s</dd>' % (self._cw._('Gender'), entity.gender))
+        self.w(u'</dl>')
+        # Resources
+        self.w(u'<div class="row-fluid">')
+        # Scans
+        self.w(u'<div class="span4">')
+        url = self._cw.build_url(rql='Any S WHERE S is Scan, S concerns X, X eid %s' % entity.eid)
+        self.w(u'<a href="%s"><button class="btn btn-info" type="button">%s</button></a>'
+               % (url, self._cw._('NeuroImaging')))
+        self.w(u'</div>')
+        self.w(u'<div class="span4">')
+        url = self._cw.build_url(rql='Any S WHERE S is GenomicMeasure, S concerns X, X eid %s' % entity.eid)
+        self.w(u'<a href="%s"><button class="btn btn-info" type="button">%s</button></a>'
+               % (url, self._cw._('Genetics')))
+        self.w(u'</div>')
+        self.w(u'<div class="span4">')
+        url = self._cw.build_url(rql='Any S WHERE S is QuestionnaireRun, S concerns X, X eid %s' % entity.eid)
+        self.w(u'<a href="%s"><button class="btn btn-info" type="button">%s</button></a>'
+               % (url, self._cw._('Questionnaire')))
+        self.w(u'</div>')
+        self.w(u'</div>')
+        self.w(u'</div>')
+        self.w(u'</div>')
+
+
+class CenterPrimaryView(PrimaryView):
+    __select__ = PrimaryView.__select__ & is_instance('Center')
+
+    def call(self, rset=None):
+        entity = self.cw_rset.get_entity(0,0)
+        self.w(u'<div class="page-header">')
+        # Header
+        self.w(u'<h1>%s</h1>' % entity.dc_title())
+        self.w(u'</div>')
+        self.w(u'<div class="row-fluid">')
+        # Attributes
+        self.w(u'<div class="span6">')
+        self.w(u'<h3>%s  <em>%s</em></h3>' % (self._cw._('Identifier'), entity.identifier))
+        self.w(u'<h3>%s  <em>%s</em></h3>' % (self._cw._('Department'), entity.department))
+        self.w(u'<h3>%s  <em>%s</em></h3>' % (self._cw._('City'), entity.city))
+        self.w(u'<h3>%s  <em>%s</em></h3>' % (self._cw._('Postal code'), entity.postal_code))
+        self.w(u'<h3>%s  <em>%s</em></h3>' % (self._cw._('Country'), entity.country))
+        self.w(u'</div>')
+        # Resources
+        self.w(u'</div>')
+        self.w(u'<div class="row-fluid">')
+        # Assessments
+        self.w(u'<div class="span6">')
+        self.w(u'<h3>Subjects assessment holded</h3>')
+        self.wview('list', rset=self._cw.execute('Any S WHERE S is Subject, '
+                                                 'X holds A,  S concerned_by A, '
+                                                 'X eid %(e)s', {'e': entity.eid}))
+        self.w(u'</div>')
+        # Devices
+        self.w(u'<div class="span6">')
+        self.w(u'<h3>Devices</h3>')
+        self.wview('list', rset=self._cw.execute('Any S WHERE S is Device, '
+                                                 'S hosted_by X, X eid %(e)s', {'e': entity.eid}))
+        self.w(u'</div>')
+        self.w(u'</div>')