[views] Warm scores in scoredefinition primary view
authorVincent Michel <vincent.michel@logilab.fr>
Wed, 17 Jul 2013 09:38:27 +0200
changeset 307 d4526f95d55e
parent 306 3e489173f8c3
child 308 0d353676690c
[views] Warm scores in scoredefinition primary view
views/primary.py
--- a/views/primary.py	Wed Jul 17 13:28:44 2013 +0200
+++ b/views/primary.py	Wed Jul 17 09:38:27 2013 +0200
@@ -302,9 +302,24 @@
           % (self._cw._('Subject'), self._cw._('value'), self._cw._('datetime')))
         rset = self._cw.execute('Any S,V,T,DA WHERE S is ScoreValue, S value V, S text T, '
                                 'S datetime DA, S definition D, D eid %(e)s', {'e': entity.eid})
+        # Warm subjects
+        score = rset.get_entity(0, 0)
+        if score.reverse_related_infos:
+            subjects_rset = self._cw.execute('Any SB, S, I WHERE S is ScoreValue, '
+                                             'SB related_infos S, SB identifier I, '
+                                             'S definition D, D eid %(e)s', {'e': entity.eid})
+        else:
+            # Measure/concerns
+            subjects_rset = self._cw.execute('Any SB, S, I WHERE S is ScoreValue, '
+                                             'S measure M, M concerns SB, SB identifier I, '
+                                             'S definition D, D eid %(e)s', {'e': entity.eid})
+        subjects = {}
+        for ind, e in enumerate(subjects_rset.entities()):
+            subjects[subjects_rset[ind][1]] = e
+        # Plot results
         for ind in range(len(rset)):
             score = rset.get_entity(ind, 0)
-            subj = score.subject
+            subj = subjects[score.eid]
             if subj:
                 subject = u'<a href="%s">%s</a>' % (subj.absolute_url(), subj.identifier)
             else: