Skip to content

Commit

Permalink
feat: Add totals to nominee feedback page (#5977)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
pselkirk authored Jul 18, 2023
1 parent bd9d328 commit 3f228c7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
12 changes: 11 additions & 1 deletion ietf/nomcom/templatetags/nomcom_tags.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
31 changes: 30 additions & 1 deletion ietf/nomcom/tests.py
Original file line number Diff line number Diff line change
@@ -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 -*-


Expand Down Expand Up @@ -1423,6 +1423,35 @@ def test_can_view_but_not_edit_templates(self):
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):
Expand Down
14 changes: 13 additions & 1 deletion ietf/templates/nomcom/view_feedback.html
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down Expand Up @@ -54,6 +54,18 @@ <h3 class="mt-5" id="declined">Declined each nominated position</h3>
</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>
Expand Down

0 comments on commit 3f228c7

Please sign in to comment.