Skip to content

Commit b77e662

Browse files
Guard against null timeslot location in agenda.html and add test of location_anchor tag
- Legacy-Id: 19665
1 parent 3846996 commit b77e662

3 files changed

Lines changed: 31 additions & 7 deletions

File tree

ietf/meeting/factories.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ class Meta:
179179
def location(obj, create, extracted, **kwargs): # pylint: disable=no-self-argument
180180
if create:
181181
if extracted:
182-
obj.location = extracted
182+
# accept the string "none" to set location to null
183+
obj.location = None if extracted == 'none' else extracted
183184
else:
184185
obj.location = RoomFactory(meeting=obj.meeting)
185186
obj.save()

ietf/meeting/templatetags/tests.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Copyright The IETF Trust 2009-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

4+
from django.template import Context, Template
5+
6+
from ietf.meeting.factories import TimeSlotFactory
47
from ietf.meeting.templatetags.agenda_custom_tags import AnchorNode
58
from ietf.utils.test_utils import TestCase
69

@@ -18,3 +21,23 @@ def test_anchor_node_subclasses_implement_resolve_url(self):
1821
self.fail(f'{subclass.__name__} must implement resolve_url() method')
1922
except:
2023
pass # any other failure ok since we used garbage inputs
24+
25+
def test_location_anchor_node(self):
26+
context = Context({
27+
'no_location': TimeSlotFactory(location='none'),
28+
'no_show_location': TimeSlotFactory(show_location=False),
29+
'show_location': TimeSlotFactory(location__name='My Location'),
30+
})
31+
template = Template("""
32+
{% load agenda_custom_tags %}
33+
<span>{% location_anchor no_location %}no_location{% end_location_anchor %}</span>
34+
<span>{% location_anchor no_show_location %}no_show_location{% end_location_anchor %}</span>
35+
<span>{% location_anchor show_location %}show_location{% end_location_anchor %}</span>
36+
""")
37+
result = template.render(context)
38+
self.assertInHTML('<span>no_location</span>', result)
39+
self.assertInHTML('<span>no_show_location</span>', result)
40+
self.assertInHTML(
41+
f'<span><a href="{context["show_location"].location.floorplan_url()}">show_location</a></span>',
42+
result,
43+
)

ietf/templates/meeting/agenda.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ <h2>
157157
<div class="hidden-sm hidden-md hidden-lg">
158158
{% include "meeting/timeslot_start_end.html" %}
159159
</div>
160-
{% location_anchor item.timeslot %}
160+
{% if item.timeslot.show_location and item.timeslot.location %}{% location_anchor item.timeslot %}
161161
{{ item.timeslot.get_html_location }}
162-
{% end_location_anchor %}
162+
{% end_location_anchor %}{% endif %}
163163
{% if item.timeslot.show_location and item.timeslot.get_html_location %}
164164
{% with item.timeslot.location.floorplan as floor %}
165165
{% if item.timeslot.location.floorplan %}
@@ -238,9 +238,9 @@ <h2>
238238
<div class="hidden-sm hidden-md hidden-lg">
239239
{% include "meeting/timeslot_start_end.html" %}
240240
</div>
241-
{% location_anchor item.timeslot %}
241+
{% if item.timeslot.show_location and item.timeslot.location %}{% location_anchor item.timeslot %}
242242
{{ item.timeslot.get_html_location }}
243-
{% end_location_anchor %}
243+
{% end_location_anchor %}{% endif %}
244244
</td>
245245

246246
{% else %}
@@ -255,9 +255,9 @@ <h2>
255255
{% endwith %}
256256
</td>
257257
<td>
258-
{% location_anchor item.timeslot %}
258+
{% if item.timeslot.show_location and item.timeslot.location %}{% location_anchor item.timeslot %}
259259
{{ item.timeslot.get_html_location }}
260-
{% end_location_anchor %}
260+
{% end_location_anchor %}{% endif %}
261261
</td>
262262

263263
<td><div class="hidden-xs">{{item.session.historic_group.historic_parent.acronym}}</div></td>

0 commit comments

Comments
 (0)