improvement that makes only one counting query
- Legacy-Id: 10526
This commit is contained in:
parent
f4f67425bf
commit
a4561f55f2
|
@ -13,6 +13,8 @@ from ietf.person.models import Person
|
|||
from ietf.nomcom.models import Feedback
|
||||
from ietf.nomcom.utils import get_nomcom_by_year, get_user_email, retrieve_nomcom_private_key
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
@ -31,8 +33,10 @@ def has_publickey(nomcom):
|
|||
|
||||
|
||||
@register.simple_tag
|
||||
def add_num_nominations(user_comments, position, nominee):
|
||||
count = user_comments.filter(positions=position, nominees=nominee).count()
|
||||
def add_num_nominations(counts, position, nominee):
|
||||
count = 0
|
||||
if position.id in counts and nominee.id in counts[position.id]:
|
||||
count = counts[position.id][nominee.id]
|
||||
if count:
|
||||
return '<span class="badge" title="%s earlier comments from you on %s as %s">%s</span> ' % (count , nominee.email.address, position, count)
|
||||
else:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import datetime
|
||||
import re
|
||||
from collections import OrderedDict
|
||||
from collections import OrderedDict, Counter
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
@ -392,8 +392,10 @@ def feedback(request, year, public):
|
|||
user_comments = Feedback.objects.filter(nomcom=nomcom,
|
||||
type='comment',
|
||||
author__in=request.user.person.email_set.filter(active='True'))
|
||||
|
||||
|
||||
counter = Counter(user_comments.values_list('positions','nominees'))
|
||||
counts = dict()
|
||||
for pos,nom in counter:
|
||||
counts.setdefault(pos,dict())[nom] = counter[(pos,nom)]
|
||||
|
||||
if public:
|
||||
base_template = "nomcom/nomcom_public_base.html"
|
||||
|
@ -407,7 +409,7 @@ def feedback(request, year, public):
|
|||
'nomcom': nomcom,
|
||||
'year': year,
|
||||
'selected': 'feedback',
|
||||
'user_comments' : user_comments,
|
||||
'counts' : counts,
|
||||
'base_template': base_template
|
||||
})
|
||||
|
||||
|
@ -434,7 +436,7 @@ def feedback(request, year, public):
|
|||
'year': year,
|
||||
'positions': positions,
|
||||
'selected': 'feedback',
|
||||
'user_comments' : user_comments,
|
||||
'counts': counts,
|
||||
'base_template': base_template
|
||||
})
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
{% for np in p.nomineeposition_set.accepted.not_duplicated %}
|
||||
<a class="btn btn-default btn-xs" {% if nomcom.group.state_id != 'conclude' %}href="?nominee={{np.nominee.id}}&position={{ np.position.id}}"{% endif %}>
|
||||
{{ np.nominee.name }}
|
||||
{% add_num_nominations user_comments np.position np.nominee %}
|
||||
{% add_num_nominations counts np.position np.nominee %}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue