Commit 22e9c9cd authored by Jelle Besseling's avatar Jelle Besseling Committed by Sébastiaan Versteeg
Browse files

Merge branch 'fix/statistics-script-tag' into 'master'

Fix usage of script tag on statistics page

See merge request !1048

(cherry picked from commit ed32d72c)

465fc032 Fix usage of script tag on statistics page
parent 1c2c3383
...@@ -39,6 +39,12 @@ $(function () { ...@@ -39,6 +39,12 @@ $(function () {
} }
}; };
var statistics = $('#members-statistics').data('statistics');
var cohortSizes = statistics.cohort_sizes;
var memberTypeDistribution = statistics.member_type_distribution;
var pizzaOrders = statistics.total_pizza_orders;
var currentPizzaOrders = statistics.current_pizza_orders;
// Apply the theme // Apply the theme
Highcharts.setOptions(Highcharts.theme); Highcharts.setOptions(Highcharts.theme);
...@@ -57,13 +63,13 @@ $(function () { ...@@ -57,13 +63,13 @@ $(function () {
colorByPoint: true, colorByPoint: true,
data : [{ data : [{
name: gettext('Members'), name: gettext('Members'),
y: total_stats_member_type.member y: memberTypeDistribution.member
},{ },{
name: gettext('Benefactors'), name: gettext('Benefactors'),
y: total_stats_member_type.supporter y: memberTypeDistribution.supporter
},{ },{
name: gettext('Honorary Members'), name: gettext('Honorary Members'),
y: total_stats_member_type.honorary y: memberTypeDistribution.honorary
}] }]
}] }]
}); });
...@@ -82,23 +88,23 @@ $(function () { ...@@ -82,23 +88,23 @@ $(function () {
name: gettext("People"), name: gettext("People"),
colorByPoint: true, colorByPoint: true,
data : [{ data : [{
name: total_stats_year[0].cohort, name: cohortSizes[0].cohort,
y: total_stats_year[0].member + total_stats_year[0].supporter + total_stats_year[0].honorary y: cohortSizes[0].member + cohortSizes[0].supporter + cohortSizes[0].honorary
},{ },{
name: total_stats_year[1].cohort, name: cohortSizes[1].cohort,
y: total_stats_year[1].member + total_stats_year[1].supporter + total_stats_year[1].honorary y: cohortSizes[1].member + cohortSizes[1].supporter + cohortSizes[1].honorary
},{ },{
name: total_stats_year[2].cohort, name: cohortSizes[2].cohort,
y: total_stats_year[2].member + total_stats_year[2].supporter + total_stats_year[2].honorary y: cohortSizes[2].member + cohortSizes[2].supporter + cohortSizes[2].honorary
},{ },{
name: total_stats_year[3].cohort, name: cohortSizes[3].cohort,
y: total_stats_year[3].member + total_stats_year[3].supporter + total_stats_year[3].honorary y: cohortSizes[3].member + cohortSizes[3].supporter + cohortSizes[3].honorary
},{ },{
name: total_stats_year[4].cohort, name: cohortSizes[4].cohort,
y: total_stats_year[4].member + total_stats_year[4].supporter + total_stats_year[4].honorary y: cohortSizes[4].member + cohortSizes[4].supporter + cohortSizes[4].honorary
},{ },{
name: total_stats_year[5].cohort, name: cohortSizes[5].cohort,
y: total_stats_year[5].member + total_stats_year[5].supporter + total_stats_year[5].honorary y: cohortSizes[5].member + cohortSizes[5].supporter + cohortSizes[5].honorary
}] }]
}] }]
}); });
...@@ -117,23 +123,23 @@ $(function () { ...@@ -117,23 +123,23 @@ $(function () {
name: gettext("Members"), name: gettext("Members"),
colorByPoint: true, colorByPoint: true,
data : [{ data : [{
name: total_stats_year[0].cohort, name: cohortSizes[0].cohort,
y: total_stats_year[0].member y: cohortSizes[0].member
},{ },{
name: total_stats_year[1].cohort, name: cohortSizes[1].cohort,
y: total_stats_year[1].member y: cohortSizes[1].member
},{ },{
name: total_stats_year[2].cohort, name: cohortSizes[2].cohort,
y: total_stats_year[2].member y: cohortSizes[2].member
},{ },{
name: total_stats_year[3].cohort, name: cohortSizes[3].cohort,
y: total_stats_year[3].member y: cohortSizes[3].member
},{ },{
name: total_stats_year[4].cohort, name: cohortSizes[4].cohort,
y: total_stats_year[4].member y: cohortSizes[4].member
},{ },{
name: total_stats_year[5].cohort, name: cohortSizes[5].cohort,
y: total_stats_year[5].member y: cohortSizes[5].member
}] }]
}] }]
}); });
...@@ -153,23 +159,23 @@ $(function () { ...@@ -153,23 +159,23 @@ $(function () {
name: gettext("Benefactors"), name: gettext("Benefactors"),
colorByPoint: true, colorByPoint: true,
data : [{ data : [{
name: total_stats_year[0].cohort, name: cohortSizes[0].cohort,
y: total_stats_year[0].supporter y: cohortSizes[0].supporter
},{ },{
name: total_stats_year[1].cohort, name: cohortSizes[1].cohort,
y: total_stats_year[1].supporter y: cohortSizes[1].supporter
},{ },{
name: total_stats_year[2].cohort, name: cohortSizes[2].cohort,
y: total_stats_year[2].supporter y: cohortSizes[2].supporter
},{ },{
name: total_stats_year[3].cohort, name: cohortSizes[3].cohort,
y: total_stats_year[3].supporter y: cohortSizes[3].supporter
},{ },{
name: total_stats_year[4].cohort, name: cohortSizes[4].cohort,
y: total_stats_year[4].supporter y: cohortSizes[4].supporter
},{ },{
name: total_stats_year[5].cohort, name: cohortSizes[5].cohort,
y: total_stats_year[5].supporter y: cohortSizes[5].supporter
}] }]
}] }]
}); });
...@@ -188,28 +194,28 @@ $(function () { ...@@ -188,28 +194,28 @@ $(function () {
name: 'Pizzas', name: 'Pizzas',
colorByPoint: true, colorByPoint: true,
data : [{ data : [{
name: total_pizza_orders[0].name, name: pizzaOrders[0].name,
y: total_pizza_orders[0].total y: pizzaOrders[0].total
},{ },{
name: total_pizza_orders[1].name, name: pizzaOrders[1].name,
y: total_pizza_orders[1].total y: pizzaOrders[1].total
},{ },{
name: total_pizza_orders[2].name, name: pizzaOrders[2].name,
y: total_pizza_orders[2].total y: pizzaOrders[2].total
},{ },{
name: total_pizza_orders[3].name, name: pizzaOrders[3].name,
y: total_pizza_orders[3].total y: pizzaOrders[3].total
},{ },{
name: total_pizza_orders[4].name, name: pizzaOrders[4].name,
y: total_pizza_orders[4].total y: pizzaOrders[4].total
},{ },{
name: total_pizza_orders[5].name, name: pizzaOrders[5].name,
y: total_pizza_orders[5].total y: pizzaOrders[5].total
}] }]
}] }]
}); });
if (current_pizza_orders != null) { if (currentPizzaOrders != null) {
$('#pizzaCurrentTypeChart').highcharts({ $('#pizzaCurrentTypeChart').highcharts({
chart: { chart: {
type: 'pie' type: 'pie'
...@@ -224,23 +230,23 @@ $(function () { ...@@ -224,23 +230,23 @@ $(function () {
name: 'Pizzas', name: 'Pizzas',
colorByPoint: true, colorByPoint: true,
data : [{ data : [{
name: current_pizza_orders[0].name, name: currentPizzaOrders[0].name,
y: current_pizza_orders[0].total y: currentPizzaOrders[0].total
},{ },{
name: current_pizza_orders[1].name, name: currentPizzaOrders[1].name,
y: current_pizza_orders[1].total y: currentPizzaOrders[1].total
},{ },{
name: current_pizza_orders[2].name, name: currentPizzaOrders[2].name,
y: current_pizza_orders[2].total y: currentPizzaOrders[2].total
},{ },{
name: current_pizza_orders[3].name, name: currentPizzaOrders[3].name,
y: current_pizza_orders[3].total y: currentPizzaOrders[3].total
},{ },{
name: current_pizza_orders[4].name, name: currentPizzaOrders[4].name,
y: current_pizza_orders[4].total y: currentPizzaOrders[4].total
},{ },{
name: current_pizza_orders[5].name, name: currentPizzaOrders[5].name,
y: current_pizza_orders[5].total y: currentPizzaOrders[5].total
}] }]
}] }]
}); });
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
{% block opengraph_title %}{% trans "Statistics" %} — {{ block.super }}{% endblock %} {% block opengraph_title %}{% trans "Statistics" %} — {{ block.super }}{% endblock %}
{% block body %} {% block body %}
<section class="page-section"> <section class="page-section" id="members-statistics" data-statistics="{{ statistics }}">
<div class="container"> <div class="container">
<h1 class="text-center section-title">{% trans "Statistics" %}</h1> <h1 class="text-center section-title">{% trans "Statistics" %}</h1>
...@@ -27,17 +27,7 @@ ...@@ -27,17 +27,7 @@
{% block js_body %} {% block js_body %}
{{ block.super }} {{ block.super }}
{% compress js %} {% compress js %}
<script type="text/javascript">
{% autoescape off %}
var total_stats_year = {{ total_stats_year }};
var total_stats_member_type = {{ total_stats_member_type }};
var total_pizza_orders = {{ total_pizza_orders }};
var current_pizza_orders = {{ current_pizza_orders }};
{% endautoescape %}
</script>
<script type="text/javascript" src="{% static 'members/js/highcharts.js' %}"></script> <script type="text/javascript" src="{% static 'members/js/highcharts.js' %}"></script>
<script type="text/javascript" src="{% static 'members/js/statistics.js' %}"></script> <script type="text/javascript" src="{% static 'members/js/statistics.js' %}"></script>
{% endcompress %} {% endcompress %}
......
...@@ -226,13 +226,14 @@ def statistics(request): ...@@ -226,13 +226,14 @@ def statistics(request):
context = { context = {
"total_members": total, "total_members": total,
"total_stats_year": json.dumps(services.gen_stats_year(member_types)), "statistics": json.dumps({
"total_stats_member_type": json.dumps( "cohort_sizes": services.gen_stats_year(member_types),
services.gen_stats_member_type(member_types)), "member_type_distribution":
"total_pizza_orders": json.dumps( services.gen_stats_member_type(member_types),
pizzas.services.gen_stats_pizza_orders()), "total_pizza_orders": pizzas.services.gen_stats_pizza_orders(),
"current_pizza_orders": json.dumps( "current_pizza_orders":
pizzas.services.gen_stats_current_pizza_orders()), pizzas.services.gen_stats_current_pizza_orders(),
})
} }
return render(request, 'members/statistics.html', context) return render(request, 'members/statistics.html', context)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment