diff --git a/src/accounts/templates/accounts/user_detail.html b/src/accounts/templates/accounts/user_detail.html index 7cf3103..44b93fc 100644 --- a/src/accounts/templates/accounts/user_detail.html +++ b/src/accounts/templates/accounts/user_detail.html @@ -2,7 +2,7 @@ {% load i18n gravatar %} {% block head_js %} - {% include "pizza-chart.html" with chart_div="collabs" chart_height=300 %} + {% include "pizza-chart.html" with chart_data=count_types chart_div="collabs" chart_height=300 %} {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %} {% endblock %} diff --git a/src/accounts/views.py b/src/accounts/views.py index 8b219a0..0214478 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -3,6 +3,8 @@ import datetime +from collections import OrderedDict + from django.contrib import messages from django.contrib.auth import get_user_model @@ -17,6 +19,7 @@ from haystack.query import SearchQuerySet from super_archives.models import EmailAddress, Message from super_archives.utils.email import send_email_lists +from search.utils import trans from .forms import UserCreationForm, ListsForm, UserUpdateForm @@ -48,7 +51,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): user = self.object context = {} - count_types = {} + count_types = OrderedDict() six_months = timezone.now() - datetime.timedelta(days=180) fields_or_lookup = ( @@ -58,14 +61,14 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): ) - for type in ['wiki', 'thread', 'changeset', 'ticket']: + for type in ['thread', 'ticket', 'wiki', 'changeset']: sqs = SearchQuerySet().filter( type=type, modified__gte=six_months, ) for filter_or in fields_or_lookup: sqs = sqs.filter_or(**filter_or) - count_types[type] = sqs.count() + count_types[trans(type)] = sqs.count() context['type_count'] = count_types diff --git a/src/home/views.py b/src/home/views.py index 38c1e21..5417230 100644 --- a/src/home/views.py +++ b/src/home/views.py @@ -1,9 +1,12 @@ -from django.shortcuts import render +from collections import OrderedDict + +from django.shortcuts import render from django.utils import timezone from haystack.query import SearchQuerySet from super_archives import queries +from search.utils import trans def index(request): @@ -12,10 +15,10 @@ def index(request): latest_threads = queries.get_latest_threads() hottest_threads = queries.get_hottest_threads() - count_types = {} + count_types = OrderedDict() six_months = timezone.now() - timezone.timedelta(days=180) - for type in ['wiki', 'thread', 'changeset', 'ticket']: - count_types[type] = SearchQuerySet().filter( + for type in ['thread', 'ticket', 'wiki', 'changeset']: + count_types[trans(type)] = SearchQuerySet().filter( type=type, modified__gte=six_months, ).count() diff --git a/src/templates/home.html b/src/templates/home.html index 310b2d5..e6cb77d 100644 --- a/src/templates/home.html +++ b/src/templates/home.html @@ -2,7 +2,7 @@ {% load i18n %} {% block head_js %} - {% include "pizza-chart.html" with chart_div="collabs" chart_height=330 %} + {% include "pizza-chart.html" with chart_data=type_count chart_div="collabs" chart_height=330 %} {% endblock %} {% block header %} diff --git a/src/templates/pizza-chart.html b/src/templates/pizza-chart.html index c4c406c..17cb927 100644 --- a/src/templates/pizza-chart.html +++ b/src/templates/pizza-chart.html @@ -20,14 +20,11 @@ data.addColumn('string', 'Topping'); data.addColumn('number', 'Slices'); data.addRows([ - {% if type_count %} - ['{% trans "Emails"%}', {% firstof type_count.thread '0' %}], - ['{% trans "Tickets"%}', {% firstof type_count.ticket '0' %}], - ['{% trans "Wiki"%}', {% firstof type_count.wiki '0' %}], - ['{% trans "Code"%}', {% firstof type_count.changeset '0' %}], - {% else %} - ['{% trans "Willing to help" %}', 100], - {% endif %} + {% for key, value in chart_data.items %} + ['{{ key }}', {{ value }} ], + {% empty %} + ['{% trans "Willing to help" %}', 100], + {% endfor %} ]); // Set chart options -- libgit2 0.21.2