Commit 207ad3bb37a96ba32ca58776c9822cbf49c61aa2

Authored by Sergio Oliveira
1 parent eb2147d9

Making pizza-chart reusable for different charts

src/accounts/templates/accounts/user_detail.html
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 {% load i18n gravatar %} 2 {% load i18n gravatar %}
3 3
4 {% block head_js %} 4 {% block head_js %}
5 - {% include "pizza-chart.html" with chart_div="collabs" chart_height=300 %} 5 + {% include "pizza-chart.html" with chart_data=count_types chart_div="collabs" chart_height=300 %}
6 {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %} 6 {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %}
7 {% endblock %} 7 {% endblock %}
8 8
src/accounts/views.py
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 3
4 import datetime 4 import datetime
5 5
  6 +from collections import OrderedDict
  7 +
6 from django.contrib import messages 8 from django.contrib import messages
7 9
8 from django.contrib.auth import get_user_model 10 from django.contrib.auth import get_user_model
@@ -17,6 +19,7 @@ from haystack.query import SearchQuerySet @@ -17,6 +19,7 @@ from haystack.query import SearchQuerySet
17 19
18 from super_archives.models import EmailAddress, Message 20 from super_archives.models import EmailAddress, Message
19 from super_archives.utils.email import send_email_lists 21 from super_archives.utils.email import send_email_lists
  22 +from search.utils import trans
20 from .forms import UserCreationForm, ListsForm, UserUpdateForm 23 from .forms import UserCreationForm, ListsForm, UserUpdateForm
21 24
22 25
@@ -48,7 +51,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): @@ -48,7 +51,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView):
48 user = self.object 51 user = self.object
49 context = {} 52 context = {}
50 53
51 - count_types = {} 54 + count_types = OrderedDict()
52 six_months = timezone.now() - datetime.timedelta(days=180) 55 six_months = timezone.now() - datetime.timedelta(days=180)
53 56
54 fields_or_lookup = ( 57 fields_or_lookup = (
@@ -58,14 +61,14 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): @@ -58,14 +61,14 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView):
58 ) 61 )
59 62
60 63
61 - for type in ['wiki', 'thread', 'changeset', 'ticket']: 64 + for type in ['thread', 'ticket', 'wiki', 'changeset']:
62 sqs = SearchQuerySet().filter( 65 sqs = SearchQuerySet().filter(
63 type=type, 66 type=type,
64 modified__gte=six_months, 67 modified__gte=six_months,
65 ) 68 )
66 for filter_or in fields_or_lookup: 69 for filter_or in fields_or_lookup:
67 sqs = sqs.filter_or(**filter_or) 70 sqs = sqs.filter_or(**filter_or)
68 - count_types[type] = sqs.count() 71 + count_types[trans(type)] = sqs.count()
69 72
70 context['type_count'] = count_types 73 context['type_count'] = count_types
71 74
src/home/views.py
1 -from django.shortcuts import render  
2 1
  2 +from collections import OrderedDict
  3 +
  4 +from django.shortcuts import render
3 from django.utils import timezone 5 from django.utils import timezone
4 6
5 from haystack.query import SearchQuerySet 7 from haystack.query import SearchQuerySet
6 from super_archives import queries 8 from super_archives import queries
  9 +from search.utils import trans
7 10
8 11
9 def index(request): 12 def index(request):
@@ -12,10 +15,10 @@ def index(request): @@ -12,10 +15,10 @@ def index(request):
12 latest_threads = queries.get_latest_threads() 15 latest_threads = queries.get_latest_threads()
13 hottest_threads = queries.get_hottest_threads() 16 hottest_threads = queries.get_hottest_threads()
14 17
15 - count_types = {} 18 + count_types = OrderedDict()
16 six_months = timezone.now() - timezone.timedelta(days=180) 19 six_months = timezone.now() - timezone.timedelta(days=180)
17 - for type in ['wiki', 'thread', 'changeset', 'ticket']:  
18 - count_types[type] = SearchQuerySet().filter( 20 + for type in ['thread', 'ticket', 'wiki', 'changeset']:
  21 + count_types[trans(type)] = SearchQuerySet().filter(
19 type=type, 22 type=type,
20 modified__gte=six_months, 23 modified__gte=six_months,
21 ).count() 24 ).count()
src/templates/home.html
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 {% load i18n %} 2 {% load i18n %}
3 3
4 {% block head_js %} 4 {% block head_js %}
5 - {% include "pizza-chart.html" with chart_div="collabs" chart_height=330 %} 5 + {% include "pizza-chart.html" with chart_data=type_count chart_div="collabs" chart_height=330 %}
6 {% endblock %} 6 {% endblock %}
7 7
8 {% block header %} 8 {% block header %}
src/templates/pizza-chart.html
@@ -20,14 +20,11 @@ @@ -20,14 +20,11 @@
20 data.addColumn('string', 'Topping'); 20 data.addColumn('string', 'Topping');
21 data.addColumn('number', 'Slices'); 21 data.addColumn('number', 'Slices');
22 data.addRows([ 22 data.addRows([
23 - {% if type_count %}  
24 - ['{% trans "Emails"%}', {% firstof type_count.thread '0' %}],  
25 - ['{% trans "Tickets"%}', {% firstof type_count.ticket '0' %}],  
26 - ['{% trans "Wiki"%}', {% firstof type_count.wiki '0' %}],  
27 - ['{% trans "Code"%}', {% firstof type_count.changeset '0' %}],  
28 - {% else %}  
29 - ['{% trans "Willing to help" %}', 100],  
30 - {% endif %} 23 + {% for key, value in chart_data.items %}
  24 + ['{{ key }}', {{ value }} ],
  25 + {% empty %}
  26 + ['{% trans "Willing to help" %}', 100],
  27 + {% endfor %}
31 ]); 28 ]);
32 29
33 // Set chart options 30 // Set chart options