From 54a524b124e7d9f508dc9433878f44293de5d025 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 31 Aug 2021 17:24:32 +0000 Subject: [PATCH] Include doc name in ballot popup anchors. Fixes #3351. Commit ready for merge. - Legacy-Id: 19308 --- ietf/doc/tests.py | 37 +++++++++++++++++++ .../doc/document_ballot_content.html | 6 +-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ietf/doc/tests.py b/ietf/doc/tests.py index b13cdea9e..f29ed73d9 100644 --- a/ietf/doc/tests.py +++ b/ietf/doc/tests.py @@ -22,6 +22,7 @@ from django.urls import reverse as urlreverse from django.conf import settings from django.forms import Form from django.utils.html import escape +from django.utils.text import slugify from tastypie.test import ResourceTestCaseMixin @@ -1548,6 +1549,42 @@ class DocTestCase(TestCase): self.assertContains(r, pos2.comment) self.assertContains(r, '(was %s)' % pos.pos) + def test_document_ballot_popup_unique_anchors_per_doc(self): + """Ballot popup anchors should be different for each document""" + ad = Person.objects.get(user__username="ad") + docs = IndividualDraftFactory.create_batch(2) + ballots = [create_ballot_if_not_open(None, doc, ad, 'approve') for doc in docs] + for doc, ballot in zip(docs, ballots): + BallotPositionDocEvent.objects.create( + doc=doc, + rev=doc.rev, + ballot=ballot, + type="changed_ballot_position", + pos_id="yes", + comment="Looks fine to me", + comment_time=datetime.datetime.now(), + balloter=Person.objects.get(user__username="ad"), + by=Person.objects.get(name="(System)")) + + anchors = set() + author_slug = slugify(ad.plain_name()) + for doc, ballot in zip(docs, ballots): + r = self.client.get(urlreverse( + "ietf.doc.views_doc.ballot_popup", + kwargs=dict(name=doc.name, ballot_id=ballot.pk) + )) + self.assertEqual(r.status_code, 200) + q = PyQuery(r.content) + href = q(f'div.balloter-name a[href$="{author_slug}"]').attr('href') + ids = [ + target.attr('id') + for target in q(f'h4.anchor-target[id$="{author_slug}"]').items() + ] + self.assertEqual(len(ids), 1, 'Should be exactly one link for the balloter') + self.assertEqual(href, f'#{ids[0]}', 'Anchor href should match ID') + anchors.add(href) + self.assertEqual(len(anchors), len(docs), 'Each doc should have a distinct anchor for the balloter') + def test_document_ballot_needed_positions(self): # draft doc = IndividualDraftFactory(intended_std_level_id='ps') diff --git a/ietf/templates/doc/document_ballot_content.html b/ietf/templates/doc/document_ballot_content.html index 3b0cd3f49..04c8c56ae 100644 --- a/ietf/templates/doc/document_ballot_content.html +++ b/ietf/templates/doc/document_ballot_content.html @@ -9,7 +9,7 @@

{{ n.name }}

{% for p in positions %}
- {% if p.is_old_pos %}({% endif %}{% if p.comment or p.discuss %}{% endif %}{{ p.balloter.plain_name }}{% if p.comment or p.discuss %}{% endif %}{% if p.is_old_pos %}){% endif %} + {% if p.is_old_pos %}({% endif %}{% if p.comment or p.discuss %}{% endif %}{{ p.balloter.plain_name }}{% if p.comment or p.discuss %}{% endif %}{% if p.is_old_pos %}){% endif %}
{% empty %} (None) @@ -73,7 +73,7 @@ {% for n, positions in position_groups %} {% for p in positions %} {% if not p.is_old_pos %} -

{{ p.balloter.plain_name }} +

{{ p.balloter.plain_name }} {% if p.old_positions %}(was {{ p.old_positions|join:", " }}){% endif %} {{p.pos}} @@ -126,7 +126,7 @@ {% for n, positions in position_groups %} {% for p in positions %} {% if p.is_old_pos %} -

+

({{ p.balloter.plain_name }}; former steering group member) {% if p.old_positions %}(was {{ p.old_positions|join:", " }}){% endif %}