Commit 207ad3bb37a96ba32ca58776c9822cbf49c61aa2
1 parent
eb2147d9
Exists in
master
and in
39 other branches
Making pizza-chart reusable for different charts
Showing
5 changed files
with
20 additions
and
17 deletions
Show diff stats
src/accounts/templates/accounts/user_detail.html
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | {% load i18n gravatar %} |
| 3 | 3 | |
| 4 | 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 | 6 | {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %} |
| 7 | 7 | {% endblock %} |
| 8 | 8 | ... | ... |
src/accounts/views.py
| ... | ... | @@ -3,6 +3,8 @@ |
| 3 | 3 | |
| 4 | 4 | import datetime |
| 5 | 5 | |
| 6 | +from collections import OrderedDict | |
| 7 | + | |
| 6 | 8 | from django.contrib import messages |
| 7 | 9 | |
| 8 | 10 | from django.contrib.auth import get_user_model |
| ... | ... | @@ -17,6 +19,7 @@ from haystack.query import SearchQuerySet |
| 17 | 19 | |
| 18 | 20 | from super_archives.models import EmailAddress, Message |
| 19 | 21 | from super_archives.utils.email import send_email_lists |
| 22 | +from search.utils import trans | |
| 20 | 23 | from .forms import UserCreationForm, ListsForm, UserUpdateForm |
| 21 | 24 | |
| 22 | 25 | |
| ... | ... | @@ -48,7 +51,7 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): |
| 48 | 51 | user = self.object |
| 49 | 52 | context = {} |
| 50 | 53 | |
| 51 | - count_types = {} | |
| 54 | + count_types = OrderedDict() | |
| 52 | 55 | six_months = timezone.now() - datetime.timedelta(days=180) |
| 53 | 56 | |
| 54 | 57 | fields_or_lookup = ( |
| ... | ... | @@ -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 | 65 | sqs = SearchQuerySet().filter( |
| 63 | 66 | type=type, |
| 64 | 67 | modified__gte=six_months, |
| 65 | 68 | ) |
| 66 | 69 | for filter_or in fields_or_lookup: |
| 67 | 70 | sqs = sqs.filter_or(**filter_or) |
| 68 | - count_types[type] = sqs.count() | |
| 71 | + count_types[trans(type)] = sqs.count() | |
| 69 | 72 | |
| 70 | 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 | 5 | from django.utils import timezone |
| 4 | 6 | |
| 5 | 7 | from haystack.query import SearchQuerySet |
| 6 | 8 | from super_archives import queries |
| 9 | +from search.utils import trans | |
| 7 | 10 | |
| 8 | 11 | |
| 9 | 12 | def index(request): |
| ... | ... | @@ -12,10 +15,10 @@ def index(request): |
| 12 | 15 | latest_threads = queries.get_latest_threads() |
| 13 | 16 | hottest_threads = queries.get_hottest_threads() |
| 14 | 17 | |
| 15 | - count_types = {} | |
| 18 | + count_types = OrderedDict() | |
| 16 | 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 | 22 | type=type, |
| 20 | 23 | modified__gte=six_months, |
| 21 | 24 | ).count() | ... | ... |
src/templates/home.html
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | {% load i18n %} |
| 3 | 3 | |
| 4 | 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 | 6 | {% endblock %} |
| 7 | 7 | |
| 8 | 8 | {% block header %} | ... | ... |
src/templates/pizza-chart.html
| ... | ... | @@ -20,14 +20,11 @@ |
| 20 | 20 | data.addColumn('string', 'Topping'); |
| 21 | 21 | data.addColumn('number', 'Slices'); |
| 22 | 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 | 30 | // Set chart options | ... | ... |