Commit b8efb2ccbb888f2457d534892a335e62e0959c4d

Authored by Sergio Oliveira
1 parent 9adb7d0d

Generating chart and badges using count from view

Showing 2 changed files with 25 additions and 15 deletions   Show diff stats
src/accounts/views.py
@@ -23,6 +23,7 @@ from haystack.query import SearchQuerySet @@ -23,6 +23,7 @@ from haystack.query import SearchQuerySet
23 from super_archives.models import EmailAddress, Message 23 from super_archives.models import EmailAddress, Message
24 from super_archives.utils.email import send_email_lists 24 from super_archives.utils.email import send_email_lists
25 from search.utils import trans 25 from search.utils import trans
  26 +from proxy.models import WikiCollabCount, TicketCollabCount
26 from .forms import (UserCreationForm, ListsForm, UserUpdateForm, 27 from .forms import (UserCreationForm, ListsForm, UserUpdateForm,
27 ChangeXMPPPasswordForm) 28 ChangeXMPPPasswordForm)
28 from .errors import XMPPChangePwdException 29 from .errors import XMPPChangePwdException
@@ -65,11 +66,25 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView): @@ -65,11 +66,25 @@ class UserProfileDetailView(UserProfileBaseMixin, DetailView):
65 {'fullname_and_username__contains': user.username}, 66 {'fullname_and_username__contains': user.username},
66 ) 67 )
67 68
  69 + counter_class = {
  70 + 'wiki': WikiCollabCount,
  71 + 'ticket': TicketCollabCount,
  72 + }
  73 +
68 for type in ['thread', 'ticket', 'wiki', 'changeset', 'attachment']: 74 for type in ['thread', 'ticket', 'wiki', 'changeset', 'attachment']:
69 - sqs = SearchQuerySet()  
70 - for filter_or in fields_or_lookup:  
71 - sqs = sqs.filter_or(type=type, **filter_or)  
72 - count_types[trans(type)] = sqs.count() 75 + CounterClass = counter_class.get(type)
  76 + if CounterClass:
  77 + try:
  78 + counter = CounterClass.objects.get(username=user.username)
  79 + except CounterClass.DoesNotExist:
  80 + count_types[trans(type)] = 0
  81 + else:
  82 + count_types[trans(type)] = counter.count
  83 + else:
  84 + sqs = SearchQuerySet()
  85 + for filter_or in fields_or_lookup:
  86 + sqs = sqs.filter_or(type=type, **filter_or)
  87 + count_types[trans(type)] = sqs.count()
73 88
74 context['type_count'] = count_types 89 context['type_count'] = count_types
75 90
src/badger/utils.py
@@ -2,16 +2,14 @@ @@ -2,16 +2,14 @@
2 2
3 from django.db.models import Count 3 from django.db.models import Count
4 4
5 -from proxy.models import Revision, Ticket, Wiki 5 +from proxy.models import (Revision, Ticket, Wiki,
  6 + WikiCollabCount, TicketCollabCount)
6 from accounts.models import User 7 from accounts.models import User
7 8
8 9
9 def get_wiki_counters(): 10 def get_wiki_counters():
10 - return {  
11 - author: count for author, count in Wiki.objects.values_list(  
12 - 'author'  
13 - ).annotate(count=Count('author'))  
14 - } 11 + return {author: count for author, count in
  12 + WikiCollabCount.objects.values_list()}
15 13
16 14
17 def get_revision_counters(): 15 def get_revision_counters():
@@ -23,11 +21,8 @@ def get_revision_counters(): @@ -23,11 +21,8 @@ def get_revision_counters():
23 21
24 22
25 def get_ticket_counters(): 23 def get_ticket_counters():
26 - return {  
27 - author: count for author, count in Ticket.objects.values_list(  
28 - 'author'  
29 - ).annotate(count=Count('author'))  
30 - } 24 + return {author: count for author, count in
  25 + TicketCollabCount.objects.values_list()}
31 26
32 27
33 def get_users_counters(): 28 def get_users_counters():