feat: Add totals to nominee feedback page (#5977)

* feat: Add totals to nominee feedback page (#4727)

* test: Add a unit test for feedback totals

Also remember to wrap the totals in a <tr> tag.
This commit is contained in:
Paul Selkirk 2023-07-18 10:17:06 -04:00 committed by GitHub
parent bd9d3285b5
commit 3f228c788d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 3 deletions

View file

@ -1,8 +1,10 @@
# Copyright The IETF Trust 2013-2019, All Rights Reserved
# Copyright The IETF Trust 2013-2023, All Rights Reserved
import os
import tempfile
import re
from collections import defaultdict
from django import template
from django.conf import settings
from django.template.defaultfilters import linebreaksbr, force_escape
@ -84,3 +86,11 @@ def decrypt(string, request, year, plain=False):
if not plain:
return force_escape(linebreaksbr(out))
return mark_safe(force_escape(out))
@register.filter
def feedback_totals(staterank_list):
totals = defaultdict(lambda: 0)
for fb_dict in staterank_list:
for fbtype_name, fbtype_count, _ in fb_dict['feedback']:
totals[fbtype_name] += fbtype_count
return totals.values()

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2012-2022, All Rights Reserved
# Copyright The IETF Trust 2012-2023, All Rights Reserved
# -*- coding: utf-8 -*-
@ -1423,6 +1423,35 @@ class InactiveNomcomTests(TestCase):
q = PyQuery(response.content)
self.assertFalse( q('#templateform') )
class FeedbackIndexTests(TestCase):
def setUp(self):
super().setUp()
setup_test_public_keys_dir(self)
self.nc = NomComFactory.create(**nomcom_kwargs_for_year())
self.author = PersonFactory.create().email_set.first().address
self.member = self.nc.group.role_set.filter(name='member').first().person
self.nominee = self.nc.nominee_set.order_by('pk').first()
self.position = self.nc.position_set.first()
for type_id in ['comment','nomina','questio']:
f = FeedbackFactory.create(author=self.author,nomcom=self.nc,type_id=type_id)
f.positions.add(self.position)
f.nominees.add(self.nominee)
def tearDown(self):
teardown_test_public_keys_dir(self)
super().tearDown()
def test_feedback_index_totals(self):
url = reverse('ietf.nomcom.views.view_feedback',kwargs={'year':self.nc.year()})
login_testing_unauthorized(self, self.member.user.username, url)
provide_private_key_to_test_client(self)
response = self.client.get(url)
self.assertEqual(response.status_code,200)
q = PyQuery(response.content)
r = q('tfoot').eq(0).find('td').contents()
self.assertEqual([a.strip() for a in r], ['1', '1', '1'])
class FeedbackLastSeenTests(TestCase):
def setUp(self):

View file

@ -1,5 +1,5 @@
{% extends "nomcom/nomcom_private_base.html" %}
{# Copyright The IETF Trust 2015, All Rights Reserved #}
{# Copyright The IETF Trust 2015-2023, All Rights Reserved #}
{% load origin static %}
{% load nomcom_tags %}
{% block subtitle %}- View feedback{% endblock %}
@ -54,6 +54,18 @@
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th scope="row">Totals</th>
<td></td>
<td></td>
{% for fbtype_count in staterank.list|feedback_totals %}
<td>
{{ fbtype_count }}
</td>
{% endfor %}
</tr>
</tfoot>
</table>
{% endfor %}
<h2 class="mt-5" id="topics">Feedback related to topics</h2>