[views] Discard the QuestionnaireRun, Questionnaire and Question primary views. Provide uicfg Brainomics primary view customizations instead (related to #3340591)
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Mon, 16 Dec 2013 18:54:56 +0100
changeset 644 66e70b99068c
parent 643 17e951f21e26
child 645 f4014875a284
[views] Discard the QuestionnaireRun, Questionnaire and Question primary views. Provide uicfg Brainomics primary view customizations instead (related to #3340591)
views/primary.py
views/uicfg.py
--- a/views/primary.py	Thu Dec 12 11:08:55 2013 +0100
+++ b/views/primary.py	Mon Dec 16 18:54:56 2013 +0100
@@ -103,158 +103,6 @@
 
 
 ###############################################################################
-### QUESTIONNAIRERUN ##########################################################
-###############################################################################
-class QuestionnaireRunPrimaryView(BrainomicsPrimaryView):
-    __select__ = BrainomicsPrimaryView.__select__ & is_instance('QuestionnaireRun')
-
-    def render_entity_attributes(self, entity):
-        questionnaire = entity.instance_of[0]
-        questionnaire = u'<a href="%s">%s</a>' % (questionnaire.absolute_url(), questionnaire.dc_title())
-        subject = entity.concerns[0]
-        subject = u'<a href="%s">%s</a>' % (subject.absolute_url(), subject.dc_title())
-        assessment = entity.reverse_generates[0]
-        assessment = u'<a href="%s">%s</a>' % (assessment.absolute_url(), assessment.dc_title())
-        return [(self._cw._('Date'), entity.datetime),
-                (self._cw._('Instance of'), questionnaire),
-                (self._cw._('Subject'), subject),
-                (self._cw._('Assessment'), assessment),
-               ]
-
-
-    def display_additional_header(self, entity):
-        w = self.w
-        # Scores and External resources
-        rset = self._cw.execute('Any X WHERE X is ScoreValue, X measure Q, Q eid %(q)s',
-                                {'q': entity.eid})
-        if rset:
-            w(u'<h3>%s</h3>' % self._cw._('Additional scores'))
-            self.wview('list', rset=rset)
-        rset = self._cw.execute('Any X WHERE X is ExternalResource, Q external_resources X, Q eid %(q)s',
-                                {'q': entity.eid})
-        if rset:
-            w(u'<h3>%s</h3>' % self._cw._('Additional resources'))
-            self.wview('list', rset=rset)
-
-    def render_entity_relations(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 '
-                                'WHERE QR is QuestionnaireRun, QR eid %(e)s, '
-                                'A questionnaire_run QR, A question Q, '
-                                'A value AV, A datetime AD, '
-                                'Q identifier QI, Q position QP, Q text QT, '
-                                'Q type QTY, Q possible_answers QPA',
-                                {'e': entity.eid})
-        w(u'<table class="table table-striped table-bordered table-condensed">')
-        w(u'<tr>')
-        for label in ('question', 'text', 'value', 'datetime'):
-            w(u'<th>%s</th>' % self._cw._(label))
-        w(u'</tr>')
-        for ind, question in enumerate(rset.entities()):
-            w(u'<tr>')
-            w(u'<th><a href="%s">%s</a></th>' % (question.absolute_url(), question.identifier))
-            w(u'<th>%s</th>' % question.text)
-            answer = rset.get_entity(ind, 1)
-            w(u'<th>%s</th>' % answer.computed_value)
-            w(u'<th>%s</th>' % (answer.datetime or self._cw._(u'unknown')))
-            w(u'</tr>')
-        w(u'</table>')
-
-
-###############################################################################
-### QUESTIONNAIRE #############################################################
-###############################################################################
-class QuestionnairePrimaryView(BrainomicsPrimaryView):
-    __select__ = BrainomicsPrimaryView.__select__ & is_instance('Questionnaire')
-
-    def render_entity_attributes(self, entity):
-        return [(self._cw._('Name'), entity.name),
-                (self._cw._('Type'), entity.type),
-                (self._cw._('Version'), entity.version),
-                (self._cw._('Language'), entity.language),
-                (self._cw._('Note'), entity.note),
-               ]
-
-    def iterate_data(self, entity):
-        data = []
-        rql = 'Any S WHERE S is QuestionnaireRun, S instance_of X, X eid %s' % entity.eid
-        data = self._build_data(data, rql, self._cw._('Related runs'))
-        return data
-
-    def render_entity_relations(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 '
-                                'WHERE QR is Questionnaire, QR eid %(e)s, '
-                                'Q questionnaire QR, '
-                                'Q identifier QI, Q position QP, Q text QT, '
-                                'Q type QTY, Q possible_answers QPA',
-                                {'e': entity.eid})
-        w(u'<table class="table table-striped table-bordered table-condensed">')
-        w(u'<tr>')
-        for label in ('question', 'text', 'type', 'possible_answers', 'Answers'):
-            w(u'<th>%s</th>' % self._cw._(label))
-        w(u'</tr>')
-        for question in rset.entities():
-            w(u'<tr>')
-            possible_answers = question.displayable_possible_answers
-            for value in (question.identifier, question.text, question.type, possible_answers):
-                w(u'<th>%s</th>' % value)
-            w(u'<th><a href="%s">%s</a></th>' % tuple(map(xml_escape,
-                                                          (question.absolute_url(), self._cw._('See detailed question')))))
-            w(u'</tr>')
-        w(u'</table>')
-
-
-###############################################################################
-### QUESTION ##################################################################
-###############################################################################
-class QuestionPrimaryView(BrainomicsPrimaryView):
-    __select__ = BrainomicsPrimaryView.__select__ & is_instance('Question')
-
-    def render_entity_attributes(self, entity):
-        questionnaire = entity.questionnaire[0]
-        questionnaire = u'<a href="%s">%s</a>' % (questionnaire.absolute_url(), questionnaire.dc_title())
-        return [(self._cw._('Questionnaire'), questionnaire),
-                (self._cw._('Position'), entity.position),
-                (self._cw._('Text'), entity.text),
-                (self._cw._('Type'), entity.type),
-                (self._cw._('Possible answers'), entity.possible_answers),
-               ]
-
-    def render_entity_relations(self, entity):
-        # Answers
-        w = self.w
-        rset = self._cw.execute('Any A, AQ, S, Q, AV, AD, AI, I, QT, QPA WHERE A is Answer, '
-                                'A question Q, Q eid %(e)s, Q type QT, Q possible_answers QPA, '
-                                'A value AV, A datetime AD, AQ identifier AI, '
-                                'A questionnaire_run AQ, AQ concerns S, S identifier I',
-                                {'e': entity.eid})
-        w(u'<table class="table table-striped table-bordered table-condensed">')
-        w(u'<tr>')
-        for label in ('answer',  'value', 'datetime'):
-            w(u'<th>%s</th>' % self._cw._(label))
-        w(u'</tr>')
-        for ind, answer in enumerate(rset.entities()):
-            # XXX WARM CACHE ?
-            qrun = rset.get_entity(ind, 1)
-            subject = rset.get_entity(ind, 2)
-            question = rset.get_entity(ind, 3)
-            w(u'<tr>')
-            w(u'<th><a href="%s">%s</a></th>' % (answer.absolute_url(), answer.dc_title()))
-            w(u'<th>%s</th>' % answer.computed_value)
-            w(u'<th>%s</th>' % (answer.datetime or self._cw._(u'unknown')))
-            w(u'</tr>')
-        w(u'</table>')
-
-
-###############################################################################
 ### SCAN ######################################################################
 ###############################################################################
 class ScanPrimaryView(BrainomicsPrimaryView):
--- a/views/uicfg.py	Thu Dec 12 11:08:55 2013 +0100
+++ b/views/uicfg.py	Mon Dec 16 18:54:56 2013 +0100
@@ -27,7 +27,7 @@
 ###############################################################################
 ### SUBJECT ###################################################################
 ###############################################################################
-# XXX : For Subject, could not handle:
+# TODO : For Subject, could not handle:
 #       - age_for_assessments(),
 #       - external_resources (Subject concerned_by X X external_resources E),
 #       - order of the attributes / relations.
@@ -65,7 +65,7 @@
 ###############################################################################
 ### CENTER ####################################################################
 ###############################################################################
-# XXX : For Center: cannot:
+# TODO : For Center: cannot:
 #       - display indirectly linked entities, viz. Subjects where
 #         Subject -- concerned_by -- Assessment and Center -- holds -- Assessment
 # Name
@@ -80,7 +80,7 @@
 ###############################################################################
 ### DEVICE ####################################################################
 ###############################################################################
-# XXX : for Device: cannot:
+# TODO : for Device: cannot:
 #       - enable the DISTINCT on the generated measures which use the device
 # Name
 _pvs.tag_attribute(('Device', 'name'), 'hidden')
@@ -94,7 +94,7 @@
 ###############################################################################
 ### ASSESSMENT ################################################################
 ###############################################################################
-# XXX : for Assessment: cannot:
+# TODO : for Assessment: cannot:
 #       - get the object type and put it into the 'label'
 #       - make synthetic counted table, via COUNT
 # Protocol
@@ -139,7 +139,7 @@
 ###############################################################################
 ### GENERICTERUN ##############################################################
 ###############################################################################
-# XXX : for GenericTestRun : could not:
+# TODO : for GenericTestRun : could not:
 #       - handle ScoreDefinition, ScoreValue tuples in the same rset
 #       - handle indirect external_resources, i.e. A -- generates -- GenericTestRun and
 #         A -- external_resources -- E
@@ -185,7 +185,7 @@
 ###############################################################################
 ### GENE ######################################################################
 ###############################################################################
-# XXX for Gene: could not:
+# TODO for Gene: could not:
 #     - properly reach CghResults; we reach GenomicRegion instead
 # Chromosomes
 _pvs.tag_subject_of(('Gene', 'chromosomes', '*'), 'attributes')
@@ -205,7 +205,7 @@
 ###############################################################################
 ### GENOMICREGION #############################################################
 ###############################################################################
-# XXX for GenomicRegion: could not:
+# TODO for GenomicRegion: could not:
 #     - use build_url to build custom RQL-defined URL to a set of entities
 # Genes
 _pvs.tag_subject_of(('GenomicRegion', 'genes', '*'), 'attributes')
@@ -214,3 +214,59 @@
 _pvdc.tag_object_of(('*', 'genomic_region', 'GenomicRegion'),
                     {'label': _('CGH results'),
                      'vid': 'region-genmeas-table-view'})
+
+
+###############################################################################
+### QUESTIONNAIRERUN ##########################################################
+###############################################################################
+# TODO for QuestionnaireRun, could not:
+#     - directly apply a view on an entity itself, e.g. self.w(entity.view('vid'))
+#     - have a fine-grained control over various entities related to the Subject
+#       (viz. the Assessment, in this case)
+# Instance of
+_pvs.tag_subject_of(('QuestionnaireRun', 'instance_of', '*'), 'attributes')
+_pvdc.tag_subject_of(('QuestionnaireRun', 'instance_of', '*'), {'vid': 'incontext'})
+# Subjects
+_pvs.tag_subject_of(('QuestionnaireRun', 'concerns', '*'), 'attributes')
+_pvdc.tag_subject_of(('QuestionnaireRun', 'concerns', '*'), {'vid': 'incontext'})
+# Assessment
+_pvs.tag_object_of(('*', 'generates', 'QuestionnaireRun'), 'attributes')
+_pvdc.tag_object_of(('*', 'generates', 'QuestionnaireRun'), {'vid': 'incontext'})
+# Additional scores
+_pvs.tag_object_of(('*', 'measure', 'QuestionnaireRun'), 'relations')
+_pvdc.tag_object_of(('*', 'measure', 'QuestionnaireRun'), {'vid': 'list'})
+# Additional resources
+_pvs.tag_subject_of(('QuestionnaireRun', 'external_resources', '*'), 'relations')
+_pvdc.tag_subject_of(('QuestionnaireRun', 'external_resources', '*'), {'vid': 'list'})
+# Answers
+_pvs.tag_object_of(('*', 'questionnaire_run', 'QuestionnaireRun'), 'relations')
+_pvdc.tag_object_of(('*', 'questionnaire_run', 'QuestionnaireRun'), {'vid': 'table'})
+
+
+###############################################################################
+### QUESTIONNAIRE #############################################################
+###############################################################################
+# TODO for Questionnaire, could not:
+#     - directly call a specific view (viz. 'results-view') on the entity
+#     - have a fine-grained control over what we display from related entities
+# Questionnaire runs
+_pvs.tag_object_of(('*', 'instance_of', 'Questionnaire'), 'relations')
+_pvdc.tag_object_of(('*', 'instance_of', 'Questionnaire'), {'vid': 'table'})
+# Questions
+_pvs.tag_object_of(('*', 'questionnaire', 'Questionnaire'), 'relations')
+_pvdc.tag_object_of(('*', 'questionnaire', 'Questionnaire'), {'vid': 'table'})
+
+
+###############################################################################
+### QUESTION ##################################################################
+###############################################################################
+# TODO for Question, could not:
+#     - have access to ScoreValue's computed_value property
+#     - same as above, provide fine-grained control over the
+#       various related entities
+# Questionnaire
+_pvs.tag_subject_of(('Question', 'questionnaire', '*'), 'attributes')
+_pvdc.tag_subject_of(('Question', 'questionnaire', '*'), {'vid': 'incontext'})
+# Answers
+_pvs.tag_object_of(('*', 'question', 'Question'), 'relations')
+_pvdc.tag_object_of(('*', 'question', 'Question'), {'vid': 'table'})