@@ -50,6 +50,7 @@ def person_link(person, **kwargs): | |||
| 50 | 50 | title = kwargs.get("title", "") | |
| 51 | 51 | cls = kwargs.get("class", "") | |
| 52 | 52 | with_email = kwargs.get("with_email", True) | |
| 53 | + titlepage_name = kwargs.get("titlepage_name", None) | ||
| 53 | 54 | if person is not None: | |
| 54 | 55 | plain_name = person.plain_name() | |
| 55 | 56 | name = ( | |
@@ -61,6 +62,7 @@ def person_link(person, **kwargs): | |||
| 61 | 62 | return { | |
| 62 | 63 | "name": name, | |
| 63 | 64 | "plain_name": plain_name, | |
| 65 | + "titlepage_name": titlepage_name, | ||
| 64 | 66 | "email": email, | |
| 65 | 67 | "title": title, | |
| 66 | 68 | "class": cls, | |
@@ -1,4 +1,6 @@ | |||
| 1 | 1 | # Copyright The IETF Trust 2022, All Rights Reserved | |
| 2 | + from django.template.loader import render_to_string | ||
| 3 | + | ||
| 2 | 4 | from ietf.person.factories import PersonFactory | |
| 3 | 5 | from ietf.utils.test_utils import TestCase | |
| 4 | 6 | ||
@@ -8,14 +10,14 @@ | |||
| 8 | 10 | class PersonLinkTests(TestCase): | |
| 9 | 11 | # Tests of the person_link template tag. These assume it is implemented as an | |
| 10 | 12 | # inclusion tag. | |
| 11 | - # TODO test that the template actually renders the data in the dict | ||
| 12 | 13 | def test_person_link(self): | |
| 13 | 14 | person = PersonFactory() | |
| 14 | 15 | self.assertEqual( | |
| 15 | 16 | person_link(person), | |
| 16 | 17 | { | |
| 17 | 18 | 'name': person.name, | |
| 18 | 19 | 'plain_name': person.plain_name(), | |
| 20 | + 'titlepage_name': None, | ||
| 19 | 21 | 'email': person.email_address(), | |
| 20 | 22 | 'title': '', | |
| 21 | 23 | 'class': '', | |
@@ -27,6 +29,7 @@ def test_person_link(self): | |||
| 27 | 29 | { | |
| 28 | 30 | 'name': person.name, | |
| 29 | 31 | 'plain_name': person.plain_name(), | |
| 32 | + 'titlepage_name': None, | ||
| 30 | 33 | 'email': person.email_address(), | |
| 31 | 34 | 'title': '', | |
| 32 | 35 | 'class': '', | |
@@ -38,6 +41,7 @@ def test_person_link(self): | |||
| 38 | 41 | { | |
| 39 | 42 | 'name': person.name, | |
| 40 | 43 | 'plain_name': person.plain_name(), | |
| 44 | + 'titlepage_name': None, | ||
| 41 | 45 | 'email': person.email_address(), | |
| 42 | 46 | 'title': 'Random Title', | |
| 43 | 47 | 'class': '', | |
@@ -50,12 +54,71 @@ def test_person_link(self): | |||
| 50 | 54 | { | |
| 51 | 55 | 'name': person.name, | |
| 52 | 56 | 'plain_name': person.plain_name(), | |
| 57 | + 'titlepage_name': None, | ||
| 53 | 58 | 'email': person.email_address(), | |
| 54 | 59 | 'title': '', | |
| 55 | 60 | 'class': 'some-class', | |
| 56 | 61 | 'with_email': True, | |
| 57 | 62 | } | |
| 58 | 63 | ) | |
| 64 | + self.assertEqual( | ||
| 65 | + person_link(person, titlepage_name='G. Surname'), | ||
| 66 | + { | ||
| 67 | + 'name': person.name, | ||
| 68 | + 'plain_name': person.plain_name(), | ||
| 69 | + 'titlepage_name': 'G. Surname', | ||
| 70 | + 'email': person.email_address(), | ||
| 71 | + 'title': '', | ||
| 72 | + 'class': '', | ||
| 73 | + 'with_email': True, | ||
| 74 | + } | ||
| 75 | + ) | ||
| 76 | + | ||
| 77 | + def test_person_link_renders(self): | ||
| 78 | + """Verifies person/person_link.html renders context dict values correctly.""" | ||
| 79 | + person = PersonFactory() | ||
| 80 | + name = person.name | ||
| 81 | + email = person.email_address() | ||
| 82 | + base_context = { | ||
| 83 | + 'name': name, | ||
| 84 | + 'plain_name': person.plain_name(), | ||
| 85 | + 'titlepage_name': None, | ||
| 86 | + 'email': email, | ||
| 87 | + 'title': '', | ||
| 88 | + 'class': '', | ||
| 89 | + 'with_email': True, | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + # Default: name is used as link text with default title attribute | ||
| 93 | + html = render_to_string('person/person_link.html', base_context) | ||
| 94 | + self.assertIn(f'>{name}</a>', html) | ||
| 95 | + self.assertIn(f'Datatracker profile of {name}', html) | ||
| 96 | + self.assertIn('bi-envelope', html) | ||
| 97 | + | ||
| 98 | + # titlepage_name overrides name as link text | ||
| 99 | + html = render_to_string('person/person_link.html', {**base_context, 'titlepage_name': 'G. Surname'}) | ||
| 100 | + self.assertIn('>G. Surname</a>', html) | ||
| 101 | + self.assertNotIn(f'>{name}</a>', html) | ||
| 102 | + | ||
| 103 | + # with_email=False suppresses the envelope link | ||
| 104 | + html = render_to_string('person/person_link.html', {**base_context, 'with_email': False}) | ||
| 105 | + self.assertNotIn('bi-envelope', html) | ||
| 106 | + | ||
| 107 | + # Custom title appears in the anchor title attribute | ||
| 108 | + html = render_to_string('person/person_link.html', {**base_context, 'title': 'Special Title'}) | ||
| 109 | + self.assertIn('title="Special Title"', html) | ||
| 110 | + | ||
| 111 | + # Empty context (None person) renders (None) | ||
| 112 | + self.assertInHTML( | ||
| 113 | + '<span class="text-body-secondary">(None)</span>', | ||
| 114 | + render_to_string('person/person_link.html', {}), | ||
| 115 | + ) | ||
| 116 | + | ||
| 117 | + # System email renders (System) | ||
| 118 | + self.assertInHTML( | ||
| 119 | + '<span class="text-body-secondary">(System)</span>', | ||
| 120 | + render_to_string('person/person_link.html', {'email': 'system@datatracker.ietf.org', 'name': ''}), | ||
| 121 | + ) | ||
| 59 | 122 | ||
| 60 | 123 | def test_invalid_person(self): | |
| 61 | 124 | """Generates correct context dict when input is invalid/missing""" | |
@@ -97,7 +97,7 @@ | |||
| 97 | 97 | <td> | |
| 98 | 98 | {# Implementation that uses the current primary email for each author #} | |
| 99 | 99 | {% if doc.pk %}{% for author in doc.author_persons_or_names %} | |
| 100 | - {% if author.person %}{% person_link author.person %}{% else %}{{ author.titlepage_name }}{% endif %}{% if not forloop.last %},{% endif %} | ||
| 100 | + {% if author.person %}{% person_link author.person titlepage_name=author.titlepage_name %}{% else %}{{ author.titlepage_name }}{% endif %}{% if not forloop.last %},{% endif %} | ||
| 101 | 101 | {% endfor %}{% endif %} | |
| 102 | 102 | {% if document_html and not snapshot or document_html and doc.rev == latest_rev%} | |
| 103 | 103 | <br> | |
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | {% if email and email == "system@datatracker.ietf.org" or name and name == "(System)" %}<span class="text-body-secondary">(System)</span>{% else %}<span {% if class %}class="{{ class }}" | |
| 2 | 2 | {% endif %}>{% if email or name %}<a {% if class %}class="text-reset"{% endif %} | |
| 3 | 3 | title="{% if title %}{{ title }}{% else %}Datatracker profile of {{ name }}{% endif %}" | |
| 4 | - {% if email %} href="{% url 'ietf.person.views.profile' email_or_name=email %}" {% else %} href="{% url 'ietf.person.views.profile' email_or_name=name %}" {% endif %}>{{ name }}</a>{% if email and with_email %} <a {% if class %}class="text-reset"{% endif %} | ||
| 4 | + {% if email %} href="{% url 'ietf.person.views.profile' email_or_name=email %}" {% else %} href="{% url 'ietf.person.views.profile' email_or_name=name %}" {% endif %}>{% if titlepage_name %}{{ titlepage_name }}{% else %}{{ name }}{% endif %}</a>{% if email and with_email %} <a {% if class %}class="text-reset"{% endif %} | ||
| 5 | 5 | href="mailto:{{ email|urlencode }}" | |
| 6 | 6 | aria-label="Compose email to {{ email }}" | |
| 7 | 7 | title="Compose email to {{ email }}"> | |
0 commit comments