Guard against None in agenda session buttons template / template tags. Commit ready for merge.

- Legacy-Id: 19647
This commit is contained in:
Jennifer Richards 2021-11-11 22:44:31 +00:00
parent 9e7cb302f7
commit fe2ce7f12a
2 changed files with 17 additions and 4 deletions

View file

@ -646,8 +646,11 @@ def is_regular_agenda_item(assignment):
>>> any(is_regular_agenda_item(factory(t)) for t in ['plenary', 'break', 'reg', 'other', 'officehours']) >>> any(is_regular_agenda_item(factory(t)) for t in ['plenary', 'break', 'reg', 'other', 'officehours'])
False False
>>> is_regular_agenda_item(None)
False
""" """
return assignment.slot_type().slug == 'regular' return assignment is not None and assignment.slot_type().slug == 'regular'
@register.filter @register.filter
def is_plenary_agenda_item(assignment): def is_plenary_agenda_item(assignment):
@ -664,8 +667,11 @@ def is_plenary_agenda_item(assignment):
>>> any(is_plenary_agenda_item(factory(t)) for t in ['regular', 'break', 'reg', 'other', 'officehours']) >>> any(is_plenary_agenda_item(factory(t)) for t in ['regular', 'break', 'reg', 'other', 'officehours'])
False False
>>> is_plenary_agenda_item(None)
False
""" """
return assignment.slot_type().slug == 'plenary' return assignment is not None and assignment.slot_type().slug == 'plenary'
@register.filter @register.filter
def is_special_agenda_item(assignment): def is_special_agenda_item(assignment):
@ -682,8 +688,11 @@ def is_special_agenda_item(assignment):
>>> any(is_special_agenda_item(factory(t)) for t in ['regular', 'plenary']) >>> any(is_special_agenda_item(factory(t)) for t in ['regular', 'plenary'])
False False
>>> is_special_agenda_item(None)
False
""" """
return assignment.slot_type().slug in [ return assignment is not None and assignment.slot_type().slug in [
'break', 'break',
'reg', 'reg',
'other', 'other',
@ -711,7 +720,11 @@ def should_show_agenda_session_buttons(assignment):
>>> test_cases.extend([('113', 'acme office hours'), ('150', 'acme office hours')]) >>> test_cases.extend([('113', 'acme office hours'), ('150', 'acme office hours')])
>>> all(should_show_agenda_session_buttons(factory(*tc)) for tc in test_cases) >>> all(should_show_agenda_session_buttons(factory(*tc)) for tc in test_cases)
True True
>>> should_show_agenda_session_buttons(None)
False
""" """
if assignment is None:
return False
num = assignment.meeting().number num = assignment.meeting().number
if num.isdigit() and int(num) <= settings.MEETING_LEGACY_OFFICE_HOURS_END: if num.isdigit() and int(num) <= settings.MEETING_LEGACY_OFFICE_HOURS_END:
return not assignment.session.name.lower().endswith(' office hours') return not assignment.session.name.lower().endswith(' office hours')

View file

@ -5,7 +5,7 @@
{% load ietf_filters %} {% load ietf_filters %}
{% origin %} {% origin %}
{% if item|should_show_agenda_session_buttons %} {% if item and item|should_show_agenda_session_buttons %}
{% with slug=item.slug %}{% with session=item.session %}{% with timeslot=item.timeslot %}{% with meeting=schedule.meeting %} {% with slug=item.slug %}{% with session=item.session %}{% with timeslot=item.timeslot %}{% with meeting=schedule.meeting %}
<div id="session-buttons-{{session.pk}}" class="text-nowrap"> <div id="session-buttons-{{session.pk}}" class="text-nowrap">
{% with acronym=session.historic_group.acronym %} {% with acronym=session.historic_group.acronym %}