[ADD,IMP] added filters for display, filterd textbox, free_text and date on basis of filter and some exception handling
bzr revid: pga@tinyerp.com-20140207113309-5o91de9jed2670qd
This commit is contained in:
parent
34f14e357c
commit
3b395dab1a
|
@ -286,35 +286,54 @@ class WebsiteSurvey(http.Controller):
|
||||||
@http.route(['/survey/results/<model("survey.survey"):survey>'],type='http', auth='user', multilang=True, website=True)
|
@http.route(['/survey/results/<model("survey.survey"):survey>'],type='http', auth='user', multilang=True, website=True)
|
||||||
def survey_reporting(self, survey, token=None, **post):
|
def survey_reporting(self, survey, token=None, **post):
|
||||||
'''Display an survey Results & Statistics for given survey.'''
|
'''Display an survey Results & Statistics for given survey.'''
|
||||||
result_tamplate = 'survey.result'
|
result_tamplate,current_filters,filter_display_data = 'survey.result',[],[]
|
||||||
if not survey.user_input_ids or not [input_id.id for input_id in survey.user_input_ids if input_id.state != 'new']:
|
if not survey.user_input_ids or not [input_id.id for input_id in survey.user_input_ids if input_id.state != 'new']:
|
||||||
result_tamplate = 'survey.no_result'
|
result_tamplate = 'survey.no_result'
|
||||||
|
if post:
|
||||||
|
current_filters, filter_display_data = self.filter_input_ids(post)
|
||||||
return request.website.render(result_tamplate,
|
return request.website.render(result_tamplate,
|
||||||
{'survey': survey,
|
{'survey': survey,
|
||||||
'prepare_result':self.prepare_result,
|
'prepare_result':self.prepare_result,
|
||||||
'get_input_summary':self.get_input_summary,
|
'get_input_summary':self.get_input_summary,
|
||||||
'get_graph_data':self.get_graph_data,
|
'get_graph_data':self.get_graph_data,
|
||||||
'page_range':self.page_range,
|
'page_range':self.page_range,
|
||||||
'current_filters':post and self.filter_input_ids(post)
|
'current_filters':current_filters,
|
||||||
|
'filter_display_data':filter_display_data
|
||||||
})
|
})
|
||||||
def filter_input_ids(self,post):
|
|
||||||
|
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'''
|
||||||
cr, uid, context = request.cr, request.uid, request.context
|
cr, uid, context = request.cr, request.uid, request.context
|
||||||
input_line_obj = request.registry['survey.user_input_line']
|
question_obj = request.registry['survey.question']
|
||||||
input_obj = request.registry['survey.user_input_line']
|
input_obj = request.registry['survey.user_input_line']
|
||||||
domain_filter,choice = [],[]
|
input_line_obj = request.registry['survey.user_input_line']
|
||||||
for ids in post:
|
label_obj = request.registry['survey.label']
|
||||||
row_id,answer_id = ids.split(',')
|
domain_filter,choice,filter_display_data = [],[],[]
|
||||||
if row_id == '0':
|
|
||||||
choice.append(int(answer_id))
|
#if user add some random data in query URI
|
||||||
|
try:
|
||||||
|
for ids in filters:
|
||||||
|
row_id,answer_id = ids.split(',')
|
||||||
|
question_id = filters[ids]
|
||||||
|
question = question_obj.browse(cr, uid, int(question_id),context=context)
|
||||||
|
if row_id == '0':
|
||||||
|
choice.append(int(answer_id))
|
||||||
|
labels = label_obj.browse(cr, uid, [int(answer_id)], context=context)
|
||||||
|
else:
|
||||||
|
domain_filter.extend(['|',('value_suggested_row.id','=',int(row_id)),('value_suggested.id','=',int(answer_id))])
|
||||||
|
labels = label_obj.browse(cr, uid, [int(row_id),int(answer_id)], context=context)
|
||||||
|
filter_display_data.append({'question_text': question.question,'labels':[ label.value for label in labels]})
|
||||||
|
if choice:
|
||||||
|
domain_filter.insert(0,('value_suggested.id','in',choice))
|
||||||
else:
|
else:
|
||||||
domain_filter.extend(['|',('value_suggested_row.id','=',int(row_id)),('value_suggested.id','=',int(answer_id))])
|
domain_filter = domain_filter[1:]
|
||||||
if choice:
|
except:
|
||||||
domain_filter.insert(0,('value_suggested.id','in',choice))
|
#if user add some random data in query URI
|
||||||
else:
|
return([],[])
|
||||||
domain_filter = domain_filter[1:]
|
|
||||||
line_ids = input_line_obj.search(cr, uid, domain_filter, context=context)
|
line_ids = input_line_obj.search(cr, uid, domain_filter, context=context)
|
||||||
filtered_input_ids = [input.user_input_id.id for input in input_obj.browse(cr, uid, line_ids, context=context)]
|
filtered_input_ids = [input.user_input_id.id for input in input_obj.browse(cr, uid, line_ids, context=context)]
|
||||||
return filtered_input_ids
|
return (filtered_input_ids,filter_display_data)
|
||||||
|
|
||||||
def page_range(self, total_record, limit):
|
def page_range(self, total_record, limit):
|
||||||
'''Returns number of pages required for pagination'''
|
'''Returns number of pages required for pagination'''
|
||||||
|
@ -322,7 +341,9 @@ class WebsiteSurvey(http.Controller):
|
||||||
return range(1, int( total+1 ))
|
return range(1, int( total+1 ))
|
||||||
|
|
||||||
def prepare_result(self, question, current_filters=[]):
|
def prepare_result(self, question, current_filters=[]):
|
||||||
'''Prepare statistical data for questions by counting number of vote per choice'''
|
'''Prepare statistical data for questions by counting number of vote per choice on basis of filter'''
|
||||||
|
|
||||||
|
#Calculate and return statistics for choice
|
||||||
if question.type in ['simple_choice', 'multiple_choice'] :
|
if question.type in ['simple_choice', 'multiple_choice'] :
|
||||||
result_summary = {}
|
result_summary = {}
|
||||||
[ result_summary.update({ label.id : {'text':label.value, 'count':0, 'answer_id':label.id} }) for label in question.labels_ids ]
|
[ result_summary.update({ label.id : {'text':label.value, 'count':0, 'answer_id':label.id} }) for label in question.labels_ids ]
|
||||||
|
@ -330,6 +351,8 @@ class WebsiteSurvey(http.Controller):
|
||||||
if result_summary.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters):
|
if result_summary.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters):
|
||||||
result_summary[input_line.value_suggested.id]['count'] += 1
|
result_summary[input_line.value_suggested.id]['count'] += 1
|
||||||
result_summary = result_summary.values()
|
result_summary = result_summary.values()
|
||||||
|
|
||||||
|
#Calculate and return statistics for matrix
|
||||||
if question.type == 'matrix':
|
if question.type == 'matrix':
|
||||||
rows, answers, res = {}, {}, {}
|
rows, answers, res = {}, {}, {}
|
||||||
[ rows.update({ label.id : label.value}) for label in question.labels_ids_2 ]
|
[ rows.update({ label.id : label.value}) for label in question.labels_ids_2 ]
|
||||||
|
@ -340,23 +363,34 @@ class WebsiteSurvey(http.Controller):
|
||||||
if not(current_filters) or input_line.user_input_id.id in current_filters:
|
if not(current_filters) or input_line.user_input_id.id in current_filters:
|
||||||
res[(input_line.value_suggested_row.id,input_line.value_suggested.id)] += 1
|
res[(input_line.value_suggested_row.id,input_line.value_suggested.id)] += 1
|
||||||
result_summary= {'answers':answers,'rows':rows,'result':res}
|
result_summary= {'answers':answers,'rows':rows,'result':res}
|
||||||
|
|
||||||
|
#Calculate and return statistics for free_text, textbox, datetime
|
||||||
|
if question.type in ['free_text','textbox','datetime']:
|
||||||
|
result_summary = []
|
||||||
|
for input_line in question.user_input_line_ids:
|
||||||
|
if not(current_filters) or input_line.user_input_id.id in current_filters:
|
||||||
|
result_summary.append(input_line)
|
||||||
|
|
||||||
|
#Calculate and return statistics for numerical_box
|
||||||
if question.type == 'numerical_box':
|
if question.type == 'numerical_box':
|
||||||
result_summary = {}
|
result_summary = {'input_lines':[]}
|
||||||
all_inputs = []
|
all_inputs = []
|
||||||
for input_line in question.user_input_line_ids:
|
for input_line in question.user_input_line_ids:
|
||||||
if not input_line.skipped:
|
if not(current_filters) or input_line.user_input_id.id in current_filters:
|
||||||
all_inputs.append(input_line.value_number)
|
all_inputs.append(input_line.value_number)
|
||||||
|
result_summary['input_lines'].append(input_line)
|
||||||
result_summary.update({
|
result_summary.update({
|
||||||
'average':round(sum(all_inputs)/len(all_inputs),2),
|
'average':round(sum(all_inputs)/len(all_inputs),2),
|
||||||
'max':round(max(all_inputs),2),
|
'max':round(max(all_inputs),2),
|
||||||
'min':round(min(all_inputs),2),
|
'min':round(min(all_inputs),2),
|
||||||
'most_comman':Counter(all_inputs).most_common(5),
|
'most_comman':Counter(all_inputs).most_common(5),
|
||||||
})
|
})
|
||||||
|
|
||||||
return result_summary
|
return result_summary
|
||||||
|
|
||||||
@http.route(['/survey/results/graph/<model("survey.question"):question>'],type='http', auth='user', multilang=True, website=True)
|
@http.route(['/survey/results/graph/<model("survey.question"):question>'],type='http', auth='user', multilang=True, website=True)
|
||||||
def get_graph_data(self, question, **post):
|
def get_graph_data(self, question, **post):
|
||||||
'''Returns appropriate formated data required by graph library'''
|
'''Returns appropriate formated data required by graph library on basis of filter'''
|
||||||
current_filters = eval(post.get('current_filters','[]'))
|
current_filters = eval(post.get('current_filters','[]'))
|
||||||
result = []
|
result = []
|
||||||
if question.type in ['simple_choice', 'multiple_choice']:
|
if question.type in ['simple_choice', 'multiple_choice']:
|
||||||
|
@ -372,16 +406,17 @@ class WebsiteSurvey(http.Controller):
|
||||||
result.append({'key':data['answers'].get(answer),'values':values})
|
result.append({'key':data['answers'].get(answer),'values':values})
|
||||||
return json.dumps(result)
|
return json.dumps(result)
|
||||||
|
|
||||||
def get_input_summary(self, question):
|
def get_input_summary(self, question, current_filters=[]):
|
||||||
'''Returns overall summary of question e.g. answered, skipped, total_inputs'''
|
'''Returns overall summary of question e.g. answered, skipped, total_inputs on basis of filter'''
|
||||||
result = {}
|
result = {}
|
||||||
if question.survey_id.user_input_ids:
|
if question.survey_id.user_input_ids:
|
||||||
result['total_inputs'] = len([input_id.id for input_id in question.survey_id.user_input_ids if input_id.state != 'new'])
|
total_input_ids = current_filters or [input_id.id for input_id in question.survey_id.user_input_ids if input_id.state != 'new']
|
||||||
|
result['total_inputs'] = len(total_input_ids)
|
||||||
question_input_ids = []
|
question_input_ids = []
|
||||||
for user_input in question.user_input_line_ids:
|
for user_input in question.user_input_line_ids:
|
||||||
if not user_input.skipped:
|
if not user_input.skipped:
|
||||||
question_input_ids.append(user_input.user_input_id.id)
|
question_input_ids.append(user_input.user_input_id.id)
|
||||||
result['answered'] = len(set(question_input_ids))
|
result['answered'] = len(set(question_input_ids) & set(total_input_ids))
|
||||||
result['skipped'] = result['total_inputs'] - result['answered']
|
result['skipped'] = result['total_inputs'] - result['answered']
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,24 @@
|
||||||
.only_left_radius{
|
.only_right_radius{
|
||||||
border-top-right-radius:2em;
|
border-top-right-radius:2em;
|
||||||
border-bottom-right-radius:2em;
|
border-bottom-right-radius:2em;
|
||||||
|
border-top-left-radius:0em;
|
||||||
|
border-bottom-left-radius:0em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.only_right_radius{
|
.only_left_radius{
|
||||||
|
border-top-right-radius:0em;
|
||||||
|
border-bottom-right-radius:0em;
|
||||||
border-top-left-radius:2em;
|
border-top-left-radius:2em;
|
||||||
border-bottom-left-radius:2em;
|
border-bottom-left-radius:2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no_radius{
|
||||||
|
border-radius:0em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clear_survey_filter{
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
.nvtooltip h5 {
|
.nvtooltip h5 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
|
|
|
@ -27,9 +27,9 @@ $(document).ready(function () {
|
||||||
|
|
||||||
//Script For Pagination
|
//Script For Pagination
|
||||||
var survey_pagination = $('.pagination');
|
var survey_pagination = $('.pagination');
|
||||||
var limit = 5; //Number of Record Par Page. If you change value here, make change in pagination template also.
|
|
||||||
$.each(survey_pagination, function(index, pagination){
|
$.each(survey_pagination, function(index, pagination){
|
||||||
var question_id = $(pagination).attr("data-question_id");
|
var question_id = $(pagination).attr("data-question_id");
|
||||||
|
var limit = $(pagination).attr("data-record_limit"); //Number of Record Par Page. If you want to change number of record per page, change record_limit in pagination template.
|
||||||
$('#table_question_'+ question_id +' tbody tr:lt('+limit+')').removeClass('hidden');
|
$('#table_question_'+ question_id +' tbody tr:lt('+limit+')').removeClass('hidden');
|
||||||
$('#pagination_'+question_id+' li:first').addClass('active');
|
$('#pagination_'+question_id+' li:first').addClass('active');
|
||||||
$('#pagination_'+question_id+' li a').click(function(event){
|
$('#pagination_'+question_id+' li a').click(function(event){
|
||||||
|
@ -131,14 +131,17 @@ $(document).ready(function () {
|
||||||
var question_id = cell.attr('data-question_id');
|
var question_id = cell.attr('data-question_id');
|
||||||
var row_id = cell.attr('data-row_id') | 0;
|
var row_id = cell.attr('data-row_id') | 0;
|
||||||
var answer_id = cell.attr('data-answer_id');
|
var answer_id = cell.attr('data-answer_id');
|
||||||
if(document.URL.indexOf("?") == -1)
|
if(document.URL.indexOf("?") == -1){
|
||||||
{
|
window.location.href = document.URL+'?' + encodeURI(row_id + ','+answer_id + '=' + question_id);
|
||||||
window.location.href = document.URL+'?' + encodeURI(row_id + ','+answer_id + '=' + question_id);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
window.location.href = document.URL+'&' + encodeURI(row_id + ','+answer_id + '=' + question_id);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
window.location.href = document.URL+'&' + encodeURI(row_id + ','+answer_id + '=' + question_id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// for clear all filters
|
||||||
|
$('.clear_survey_filter').click(function(){
|
||||||
|
window.location.href = document.URL.substring(0,document.URL.indexOf("?"));
|
||||||
});
|
});
|
||||||
|
|
||||||
console.debug("[survey] Survey Result JS loaded!");
|
console.debug("[survey] Survey Result JS loaded!");
|
||||||
|
|
|
@ -15,11 +15,17 @@
|
||||||
<h1><span t-field="survey.title"></span> <span style="font-size:1.5em;" class="glyphicon glyphicon-stats pull-right "/></h1>
|
<h1><span t-field="survey.title"></span> <span style="font-size:1.5em;" class="glyphicon glyphicon-stats pull-right "/></h1>
|
||||||
<h2><span t-field="survey.description"></span></h2>
|
<h2><span t-field="survey.description"></span></h2>
|
||||||
</div>
|
</div>
|
||||||
|
<div t-if="filter_display_data" class="filteres">
|
||||||
|
<span><h3><span class="glyphicon glyphicon-filter"></span> Filters <small class="pull-right clear_survey_filter"> <i class="fa fa-times"></i> Clear All Filters</small></h3></span>
|
||||||
|
<span t-foreach="filter_display_data" t-as="filter_data">
|
||||||
|
<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.page_ids' t-as='page'>
|
||||||
<h1 class="mt16" t-field='page.title'></h1>
|
<h1 class="mt16" t-field='page.title'></h1>
|
||||||
<hr/>
|
<hr/>
|
||||||
<div t-foreach='page.question_ids' t-as='question' class="mt16">
|
<div t-foreach='page.question_ids' t-as='question' class="mt16">
|
||||||
<t t-set="input_summary" t-value="get_input_summary(question)"/>
|
<t t-set="input_summary" t-value="get_input_summary(question, current_filters)"/>
|
||||||
<h4>
|
<h4>
|
||||||
<b>Question </b>
|
<b>Question </b>
|
||||||
<span t-field='question.question'></span>
|
<span t-field='question.question'></span>
|
||||||
|
@ -60,7 +66,8 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="hidden" t-foreach="question.user_input_line_ids" t-as="user_input">
|
<t t-set="text_result" t-value="prepare_result(question, current_filters)"></t>
|
||||||
|
<tr class="hidden" t-foreach="text_result" t-as="user_input">
|
||||||
<td><t t-esc="user_input_index+1"></t></td>
|
<td><t t-esc="user_input_index+1"></t></td>
|
||||||
<t t-if="question.type == 'free_text'">
|
<t t-if="question.type == 'free_text'">
|
||||||
<td>
|
<td>
|
||||||
|
@ -92,7 +99,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<t t-call="survey.pagination"/>
|
<t t-call="survey.pagination" />
|
||||||
</t>
|
</t>
|
||||||
<t t-if="input_summary['answered'] == 0">
|
<t t-if="input_summary['answered'] == 0">
|
||||||
<h2 style="padding-top:30px;padding-bottom:30px;text-align:center;" class="text-muted">Sorry, No one answered this question.</h2>
|
<h2 style="padding-top:30px;padding-bottom:30px;text-align:center;" class="text-muted">Sorry, No one answered this question.</h2>
|
||||||
|
@ -199,9 +206,9 @@
|
||||||
<template id="result_number" name="Number Result">
|
<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(question, current_filters)" />
|
||||||
<span class="pull-right mt8">
|
<span class="pull-right mt8">
|
||||||
<span class="label label-default only_right_radius">Maximum </span> <span class="label label-success only_left_radius" t-esc="number_result['max']"></span>
|
<span class="label label-default only_left_radius">Maximum </span> <span class="label label-success only_right_radius" t-esc="number_result['max']"></span>
|
||||||
<span class="label label-default only_right_radius">Minimum </span> <span class="label label-danger only_left_radius" t-esc="number_result['min']"></span>
|
<span class="label label-default only_left_radius">Minimum </span> <span class="label label-danger only_right_radius" t-esc="number_result['min']"></span>
|
||||||
<span class="label label-default only_right_radius">Average </span> <span class="label label-warning only_left_radius" t-esc="number_result['average']"></span>
|
<span class="label label-default only_left_radius">Average </span> <span class="label label-warning only_right_radius" t-esc="number_result['average']"></span>
|
||||||
</span>
|
</span>
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active">
|
<li class="active">
|
||||||
|
@ -247,7 +254,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr class="hidden" t-foreach="question.user_input_line_ids" t-as="user_input">
|
<tr class="hidden" t-foreach="number_result['input_lines']" t-as="user_input">
|
||||||
<td><t t-esc="user_input_index+1"></t></td>
|
<td><t t-esc="user_input_index+1"></t></td>
|
||||||
<td>
|
<td>
|
||||||
<span t-field="user_input.value_number"></span><br/>
|
<span t-field="user_input.value_number"></span><br/>
|
||||||
|
@ -277,9 +284,10 @@
|
||||||
</template>
|
</template>
|
||||||
<!-- Pagination Element -->
|
<!-- Pagination Element -->
|
||||||
<template id="pagination" name="Survey Result">
|
<template id="pagination" name="Survey Result">
|
||||||
<ul t-att-id="'pagination_'+str(question.id)" class="pagination" t-att-data-question_id= "question.id">
|
<t t-set="record_limit" t-value="5"/><!-- Change This record_limit to change number of record per page-->
|
||||||
<t t-if="len(question.user_input_line_ids) > 5">
|
<ul t-att-id="'pagination_'+str(question.id)" class="pagination" t-att-data-question_id="question.id" t-att-data-record_limit= "record_limit">
|
||||||
<li t-foreach="page_range(len(question.user_input_line_ids), 5)" t-as="num">
|
<t t-if="len(text_result) > record_limit">
|
||||||
|
<li t-foreach="page_range(len(text_result), record_limit)" t-as="num">
|
||||||
<a href="#" t-esc="num"></a>
|
<a href="#" t-esc="num"></a>
|
||||||
</li>
|
</li>
|
||||||
</t>
|
</t>
|
||||||
|
|
Loading…
Reference in New Issue