From 6f468f3b2a473ee454cb55e9b55bbb69d516bdc2 Mon Sep 17 00:00:00 2001 From: Sergio Oliveira Date: Fri, 18 Oct 2013 18:36:35 -0300 Subject: [PATCH] Adding new chart on user profile --- src/accounts/templates/accounts/user_detail.html | 2 +- src/accounts/views.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/accounts/templates/accounts/user_detail.html b/src/accounts/templates/accounts/user_detail.html index 1761e1e..adbfcad 100644 --- a/src/accounts/templates/accounts/user_detail.html +++ b/src/accounts/templates/accounts/user_detail.html @@ -3,7 +3,7 @@ {% block head_js %} {% include "pizza-chart.html" with chart_data=type_count chart_div="collabs" chart_height=300 %} - {% include "pizza-chart.html" with chart_div="collabs2" chart_height=300 %} + {% include "pizza-chart.html" with chart_data=list_activity chart_div="collabs2" chart_height=300 %} {% endblock %} {% block main-content %} diff --git a/src/accounts/views.py b/src/accounts/views.py index 0214478..0c60341 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -6,7 +6,7 @@ import datetime from collections import OrderedDict from django.contrib import messages - +from django.db.models import Count from django.contrib.auth import get_user_model from django.views.generic import DetailView, UpdateView from django.utils import timezone @@ -83,6 +83,12 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): query = query.order_by('-received_time') context['emails'] = query[:10] + count_by = 'thread__mailinglist__name' + messages = Message.objects.filter(from_address__user__pk=user.pk) + context['list_activity'] = dict(messages.values_list(count_by)\ + .annotate(Count(count_by))\ + .order_by(count_by)) + context.update(kwargs) return super(UserProfileDetailView, self).get_context_data(**context) -- libgit2 0.21.2