[IMP] improved code so that template calls minimum function
bzr revid: dizzy.zala@gmail.com-20140325130848-w96dwzhu6kktw428
This commit is contained in:
@@ -291,15 +291,22 @@ class WebsiteSurvey(http.Controller):
|
||||
if post:
|
||||
current_filters, filter_display_data = self.filter_input_ids(post)
|
||||
return request.website.render(result_template,
|
||||
{'survey': survey,
|
||||
'prepare_result': self.prepare_result,
|
||||
'get_input_summary': self.get_input_summary,
|
||||
'get_graph_data': self.get_graph_data,
|
||||
{'survey_dict': self.prepare_result_dict(survey, current_filters),
|
||||
'page_range': self.page_range,
|
||||
'current_filters': current_filters,
|
||||
'filter_display_data': filter_display_data
|
||||
})
|
||||
|
||||
def prepare_result_dict(self,survey, current_filters=[]):
|
||||
result = {'survey':survey, 'page_ids': []}
|
||||
for page in survey.page_ids:
|
||||
page_dict = {'page': page, 'question_ids': []}
|
||||
for question in page.question_ids:
|
||||
question_dict = { 'question':question, 'input_summary':self.get_input_summary(question, current_filters),'prepare_result':self.prepare_result(question, current_filters)}
|
||||
page_dict['question_ids'].append(question_dict)
|
||||
result['page_ids'].append(page_dict)
|
||||
return result
|
||||
|
||||
def filter_input_ids(self, filters):
|
||||
'''If user applies any filters, then this function returns list of
|
||||
filtered user_input_id and label's strings for display data in web'''
|
||||
@@ -386,9 +393,10 @@ class WebsiteSurvey(http.Controller):
|
||||
|
||||
return result_summary
|
||||
|
||||
@http.route(['/survey/results/graph/<model("survey.question"):question>'],
|
||||
@http.route(['/survey/results/graph/<int:question>'],
|
||||
type='http', auth='user', multilang=True, website=True)
|
||||
def get_graph_data(self, question, **post):
|
||||
question = request.registry.get('survey.question').browse(request.cr, request.uid, question)
|
||||
'''Returns appropriate formated data required by graph library on basis of filter'''
|
||||
current_filters = safe_eval(post.get('current_filters', '[]'))
|
||||
result = []
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<div class="oe_structure" />
|
||||
<div class="container">
|
||||
<div class="jumbotron mt32">
|
||||
<t t-set="survey" t-value="survey_dict['survey']"/>
|
||||
<h1><span t-field="survey.title"></span> <span style="font-size:1.5em;" class="fa fa-bar-chart-o pull-right "/></h1>
|
||||
<h2><span t-field="survey.description"></span></h2>
|
||||
</div>
|
||||
@@ -22,11 +23,14 @@
|
||||
<span class="label label-primary only_left_radius"><i class="fa fa-filter"></i></span><span class="label label-primary no_radius" t-esc="filter_data['question_text']"></span><span class="label label-success only_right_radius" t-esc="' > '.join(filter_data['labels'])"></span>
|
||||
</span>
|
||||
</div>
|
||||
<div t-foreach='survey.page_ids' t-as='page'>
|
||||
<div t-foreach="survey_dict['page_ids']" t-as='page_ids'>
|
||||
<t t-set="page" t-value="page_ids['page']"/>
|
||||
<h1 class="mt16" t-field='page.title'></h1>
|
||||
<hr/>
|
||||
<div t-foreach='page.question_ids' t-as='question' class="mt16">
|
||||
<t t-set="input_summary" t-value="get_input_summary(question, current_filters)"/>
|
||||
<div t-foreach="page_ids['question_ids']" t-as='question_ids' class="mt16">
|
||||
<t t-set="input_summary" t-value="question_ids['input_summary']"/>
|
||||
<t t-set="question" t-value="question_ids['question']"/>
|
||||
<t t-set="prepare_result" t-value="question_ids['prepare_result']"/>
|
||||
<h4>
|
||||
<b>Question </b>
|
||||
<span t-field='question.question'></span>
|
||||
@@ -68,7 +72,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<t t-set="text_result" t-value="prepare_result(question, current_filters)"></t>
|
||||
<t t-set="text_result" t-value="prepare_result"/>
|
||||
<tr class="hidden" t-foreach="text_result" t-as="user_input">
|
||||
<td><t t-esc="user_input_index+1"></t></td>
|
||||
<t t-if="question.type == 'free_text'">
|
||||
@@ -120,7 +124,7 @@
|
||||
</li>
|
||||
<li class="active" t-if="question.type == 'simple_choice'">
|
||||
<a t-att-href="'#graph_question_'+str(question.id)" data-toggle="tab">
|
||||
<i class="fa fa-dot-circle-o"></i> Pie Chart
|
||||
<i class="fa fa-bar-chart-o"></i> Pie Chart
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
@@ -147,7 +151,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="prepare_result(question, current_filters)" t-as="user_input">
|
||||
<tr t-foreach="prepare_result" t-as="user_input">
|
||||
<td>
|
||||
<p t-esc="user_input['text']"></p>
|
||||
</td>
|
||||
@@ -166,7 +170,7 @@
|
||||
|
||||
<!-- Result for matrix -->
|
||||
<template id="result_matrix" name="Matrix Result">
|
||||
<t t-set="matrix_result" t-value="prepare_result(question, current_filters)" />
|
||||
<t t-set="matrix_result" t-value="prepare_result"/>
|
||||
<!-- Tabs -->
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active">
|
||||
@@ -215,7 +219,7 @@
|
||||
|
||||
<!-- Result for Numeric Data -->
|
||||
<template id="result_number" name="Number Result">
|
||||
<t t-set="number_result" t-value="prepare_result(question, current_filters)" />
|
||||
<t t-set="number_result" t-value="prepare_result"/>
|
||||
<t t-set="text_result" t-value="number_result['input_lines']" />
|
||||
<span class="pull-right mt8">
|
||||
<span class="label label-default only_left_radius">Maximum </span> <span class="label label-success only_right_radius" t-esc="number_result['max']"></span>
|
||||
|
||||
Reference in New Issue
Block a user