[views] Add Question table view, to be used in the Question primary view (related to #3323338)
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Tue, 17 Dec 2013 17:29:14 +0100
changeset 647 de3c857db0e6
parent 646 ee961cbb4c07
child 648 ca8a5168d561
[views] Add Question table view, to be used in the Question primary view (related to #3323338)
views/tableviews.py
views/uicfg.py
--- a/views/tableviews.py	Mon Jan 20 14:34:11 2014 +0000
+++ b/views/tableviews.py	Tue Dec 17 17:29:14 2013 +0100
@@ -176,3 +176,22 @@
 
     column_renderers = {'question': EntityTableColRenderer(renderfunc=render_question),
                         'text': EntityTableColRenderer(renderfunc=AnswerInContextTableView.render_text)}
+
+
+###############################################################################
+### QUESTIONS #################################################################
+###############################################################################
+class QuestionTableView(EntityTableView):
+    __select__ = EntityTableView.__select__ & is_instance('Question')
+    __regid__ = 'question-table-view'
+    columns = ['question', 'text', 'type', 'possible_answers', 'answers']
+
+    def render_question(w, entity):
+        w(u'%s'% xml_escape(entity.dc_title()))
+
+    def render_answers(w, entity):
+        w(u'<a href="%s">%s</a>' % (xml_escape(entity.absolute_url()),
+                                    _('See detailed question')))
+    
+    column_renderers = {'question': EntityTableColRenderer(renderfunc=render_question),
+                        'answers': EntityTableColRenderer(renderfunc=render_answers)}
--- a/views/uicfg.py	Mon Jan 20 14:34:11 2014 +0000
+++ b/views/uicfg.py	Tue Dec 17 17:29:14 2013 +0100
@@ -255,7 +255,7 @@
 _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'})
+_pvdc.tag_object_of(('*', 'questionnaire', 'Questionnaire'), {'vid': 'question-table-view'})
 
 
 ###############################################################################