Skip to content

Commit 54a524b

Browse files
Include doc name in ballot popup anchors. Fixes ietf-tools#3351. Commit ready for merge.
- Legacy-Id: 19308
1 parent 2060173 commit 54a524b

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

ietf/doc/tests.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from django.conf import settings
2323
from django.forms import Form
2424
from django.utils.html import escape
25+
from django.utils.text import slugify
2526

2627
from tastypie.test import ResourceTestCaseMixin
2728

@@ -1548,6 +1549,42 @@ def test_document_ballot(self):
15481549
self.assertContains(r, pos2.comment)
15491550
self.assertContains(r, '(was %s)' % pos.pos)
15501551

1552+
def test_document_ballot_popup_unique_anchors_per_doc(self):
1553+
"""Ballot popup anchors should be different for each document"""
1554+
ad = Person.objects.get(user__username="ad")
1555+
docs = IndividualDraftFactory.create_batch(2)
1556+
ballots = [create_ballot_if_not_open(None, doc, ad, 'approve') for doc in docs]
1557+
for doc, ballot in zip(docs, ballots):
1558+
BallotPositionDocEvent.objects.create(
1559+
doc=doc,
1560+
rev=doc.rev,
1561+
ballot=ballot,
1562+
type="changed_ballot_position",
1563+
pos_id="yes",
1564+
comment="Looks fine to me",
1565+
comment_time=datetime.datetime.now(),
1566+
balloter=Person.objects.get(user__username="ad"),
1567+
by=Person.objects.get(name="(System)"))
1568+
1569+
anchors = set()
1570+
author_slug = slugify(ad.plain_name())
1571+
for doc, ballot in zip(docs, ballots):
1572+
r = self.client.get(urlreverse(
1573+
"ietf.doc.views_doc.ballot_popup",
1574+
kwargs=dict(name=doc.name, ballot_id=ballot.pk)
1575+
))
1576+
self.assertEqual(r.status_code, 200)
1577+
q = PyQuery(r.content)
1578+
href = q(f'div.balloter-name a[href$="{author_slug}"]').attr('href')
1579+
ids = [
1580+
target.attr('id')
1581+
for target in q(f'h4.anchor-target[id$="{author_slug}"]').items()
1582+
]
1583+
self.assertEqual(len(ids), 1, 'Should be exactly one link for the balloter')
1584+
self.assertEqual(href, f'#{ids[0]}', 'Anchor href should match ID')
1585+
anchors.add(href)
1586+
self.assertEqual(len(anchors), len(docs), 'Each doc should have a distinct anchor for the balloter')
1587+
15511588
def test_document_ballot_needed_positions(self):
15521589
# draft
15531590
doc = IndividualDraftFactory(intended_std_level_id='ps')

ietf/templates/doc/document_ballot_content.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<h4><span class="label label-{{ n|pos_to_label }}"> {{ n.name }}</span></h4>
1010
{% for p in positions %}
1111
<div class="balloter-name">
12-
{% if p.is_old_pos %}<span class="text-muted">({% endif %}{% if p.comment or p.discuss %}<a href="#{{ p.balloter.plain_name|slugify }}">{% endif %}{{ p.balloter.plain_name }}{% if p.comment or p.discuss %}</a>{% endif %}{% if p.is_old_pos %})</span>{% endif %}
12+
{% if p.is_old_pos %}<span class="text-muted">({% endif %}{% if p.comment or p.discuss %}<a href="#{{ doc.name|slugify }}_{{ p.balloter.plain_name|slugify }}">{% endif %}{{ p.balloter.plain_name }}{% if p.comment or p.discuss %}</a>{% endif %}{% if p.is_old_pos %})</span>{% endif %}
1313
</div>
1414
{% empty %}
1515
(None)
@@ -73,7 +73,7 @@ <h4><span class="label label-{{ n|pos_to_label }}"> {{ n.name }}</span></h4>
7373
{% for n, positions in position_groups %}
7474
{% for p in positions %}
7575
{% if not p.is_old_pos %}
76-
<h4 class="anchor-target" id="{{ p.balloter.plain_name|slugify }}">{{ p.balloter.plain_name }}
76+
<h4 class="anchor-target" id="{{ doc.name|slugify }}_{{ p.balloter.plain_name|slugify }}">{{ p.balloter.plain_name }}
7777
<span class="pull-right">
7878
{% if p.old_positions %}<span class="text-muted small">(was {{ p.old_positions|join:", " }})</span>{% endif %}
7979
<span class="label label-{{ p.pos|pos_to_label }}">{{p.pos}}</span>
@@ -126,7 +126,7 @@ <h5 class="panel-title"><b>Comment</b> ({{ p.comment_time|date:"Y-m-d" }}{% if n
126126
{% for n, positions in position_groups %}
127127
{% for p in positions %}
128128
{% if p.is_old_pos %}
129-
<h4 class="anchor-target" id="{{ p.balloter.plain_name|slugify }}">
129+
<h4 class="anchor-target" id="{{ doc.name|slugify }}_{{ p.balloter.plain_name|slugify }}">
130130
<span class="text-muted">({{ p.balloter.plain_name }}; former steering group member)</span>
131131
<span class="pull-right">
132132
{% if p.old_positions %}<span class="text-muted small">(was {{ p.old_positions|join:", " }})</span>{% endif %}

0 commit comments

Comments
 (0)