From 15a14a0db0713ae33b969551eabe926386e27a56 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Mon, 17 Jul 2023 12:38:49 -0400 Subject: [PATCH 1/2] feat: Add totals to nominee feedback page (#4727) --- ietf/nomcom/templatetags/nomcom_tags.py | 12 +++++++++++- ietf/templates/nomcom/view_feedback.html | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ietf/nomcom/templatetags/nomcom_tags.py b/ietf/nomcom/templatetags/nomcom_tags.py index 38dfc61b9e..8f795be80e 100644 --- a/ietf/nomcom/templatetags/nomcom_tags.py +++ b/ietf/nomcom/templatetags/nomcom_tags.py @@ -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() diff --git a/ietf/templates/nomcom/view_feedback.html b/ietf/templates/nomcom/view_feedback.html index 9215d3c82c..93b66dae6e 100644 --- a/ietf/templates/nomcom/view_feedback.html +++ b/ietf/templates/nomcom/view_feedback.html @@ -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,16 @@

Declined each nominated position

{% endfor %} + + Totals + + + {% for fbtype_count in staterank.list|feedback_totals %} + + {{ fbtype_count }} + + {% endfor %} + {% endfor %}

Feedback related to topics

From ad71d61b45ba8998d104185e978f9376b67903f9 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Mon, 17 Jul 2023 17:34:41 -0400 Subject: [PATCH 2/2] test: Add a unit test for feedback totals Also remember to wrap the totals in a tag. --- ietf/nomcom/tests.py | 31 +++++++++++++++++++++++- ietf/templates/nomcom/view_feedback.html | 18 ++++++++------ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/ietf/nomcom/tests.py b/ietf/nomcom/tests.py index 216984776c..bce7e5a214 100644 --- a/ietf/nomcom/tests.py +++ b/ietf/nomcom/tests.py @@ -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 @@ 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): diff --git a/ietf/templates/nomcom/view_feedback.html b/ietf/templates/nomcom/view_feedback.html index 93b66dae6e..d1b7f77e4c 100644 --- a/ietf/templates/nomcom/view_feedback.html +++ b/ietf/templates/nomcom/view_feedback.html @@ -55,14 +55,16 @@

Declined each nominated position

{% endfor %} - Totals - - - {% for fbtype_count in staterank.list|feedback_totals %} - - {{ fbtype_count }} - - {% endfor %} + + Totals + + + {% for fbtype_count in staterank.list|feedback_totals %} + + {{ fbtype_count }} + + {% endfor %} + {% endfor %}