[views] Redefine the QuestionnaireRun primary view to add the notion of ExternalResource
authorVincent Michel <vincent.michel@logilab.fr>
Thu, 27 Jun 2013 18:51:46 +0200
changeset 160 6452d3f56a14
parent 159 9f0aa4a7caed
child 161 f8396da98363
[views] Redefine the QuestionnaireRun primary view to add the notion of ExternalResource
views/primary.py
--- a/views/primary.py	Thu Jun 27 18:52:41 2013 +0200
+++ b/views/primary.py	Thu Jun 27 18:51:46 2013 +0200
@@ -16,3 +16,29 @@
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 
 """cubicweb-opencat views/forms/actions/components for web ui"""
+
+from cubes.questionnaire.views.primary import QuestionnaireRunPrimaryView
+
+
+class BrainomicsQuestionnaireRunPrimaryView(QuestionnaireRunPrimaryView):
+
+    def call(self, rset=None):
+        super(BrainomicsQuestionnaireRunPrimaryView, self).call(rset=rset)
+        # Add measures
+        rset = rset or self.cw_rset
+        rset = self._cw.execute('Any X WHERE X is ScoreValue, X measure Q, Q eid %(q)s',
+                                {'q': rset.get_entity(0, 0).eid})
+        if rset:
+            self.w(u'<h3>%s</h3>' % self._cw._('Additional scores'))
+            self.wview('list', rset=rset)
+        # Add external resources
+        rset = rset or self.cw_rset
+        rset = self._cw.execute('Any X WHERE X is ExternalResource, Q external_resources X, Q eid %(q)s',
+                                {'q': rset.get_entity(0, 0).eid})
+        if rset:
+            self.w(u'<h3>%s</h3>' % self._cw._('Additional resources'))
+            self.wview('list', rset=rset)
+
+
+def registration_callback(vreg):
+    vreg.register_and_replace(BrainomicsQuestionnaireRunPrimaryView, QuestionnaireRunPrimaryView)