[views] Factorize view of results file across different measures
authorVincent Michel <vincent.michel@logilab.fr>
Fri, 20 Sep 2013 12:37:14 +0000
changeset 386 64421be0d75b
parent 385 e637f05706e8
child 387 1fadd043e96c
[views] Factorize view of results file across different measures
views/primary.py
views/secondary.py
--- a/views/primary.py	Fri Sep 20 12:59:47 2013 +0000
+++ b/views/primary.py	Fri Sep 20 12:37:14 2013 +0000
@@ -114,20 +114,13 @@
         fields = [(self._cw._('Type'), entity.type),
                   (self._cw._('Format'), entity.format),
                   (self._cw._('Chip S/N'), entity.formatted_chip_serialnum)]
-                  
         if entity.platform:
             fields.append((self._cw._('Platform'), entity.platform[0].identifier))
         return fields
 
     def display_main_col(self, entity):
-        # Display results file:
-        self.w(u'<div class="span3">')
-        rset = self._cw.execute('(Any F LIMIT 1 WHERE X results_file F, X eid %(e)s)',
-                                {'e': entity.eid})
-        if rset:
-            self.w(u'<h3>%s</h3>' % self._cw._('Results file'))
-            self.wview('downloadlink', rset=rset)
-    
+        self.w(entity.view('results-view'))
+
 
 ###############################################################################
 ### SUBJECT ###################################################################
@@ -472,6 +465,8 @@
 
     def display_main_col(self, entity):
         w = self.w
+        # Results file
+        w(entity.view('results-view'))
         # Answers
         w(u'<h3>%s</h3>' % self._cw._('Answers'))
         rset = self._cw.execute('Any Q, A, AV, AD ORDERBY QP '
@@ -518,6 +513,8 @@
         return data
 
     def display_main_col(self, entity):
+        # Results file
+        self.w(entity.view('results-view'))
         # Questions
         w = self.w
         rset = self._cw.execute('Any Q, QI, QP, QT, QTY, QPA ORDERBY QP '
@@ -631,6 +628,8 @@
         w(u'</div>')
 
     def display_main_col(self, entity):
+        # Results file
+        self.w(entity.view('results-view'))
         # Related external resources
         rset = self._cw.execute('(Any E WHERE X external_resources E, X eid %(e)s) '
                                 'UNION (Any E WHERE A generates X, A external_resources E, X eid %(e)s)',
--- a/views/secondary.py	Fri Sep 20 12:59:47 2013 +0000
+++ b/views/secondary.py	Fri Sep 20 12:37:14 2013 +0000
@@ -52,6 +52,27 @@
                 w(entity.content)
         w(u'</div>')
 
+
+###############################################################################
+### RESOURCES VIEW ############################################################
+###############################################################################
+class BrainomicsResultFile(ListView):
+    __regid__ = 'results-view'
+    __select__ = EntityView.__select__ & is_instance('Questionnaire', 'QuestionnaireRun',
+                                                     'GenomicMeasure', 'Scan')
+
+    def entity_call(self, entity):
+        # Display results file
+        w = self.w
+        w(u'<div class="span3">')
+        rset = self._cw.execute('(Any F LIMIT 1 WHERE X results_file F, X eid %(e)s)',
+                                {'e': entity.eid})
+        if rset:
+            w(u'<h3>%s</h3>' % self._cw._('Results file'))
+            self.wview('downloadlink', rset=rset)
+        w(u'</div>')
+
+
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__, (BrainomicsListView,))
     vreg.register_and_replace(BrainomicsListView, ListView)