Skip to content

Commit 7384c03

Browse files
committed
Merged in ^/personal/jennifer/7.17.1.dev0 from jennifer@painless-security.com:
This adds support for the simpler show/hide filtering to the ical agenda views. It also significantly rearranges (and, I hope, improves the organization of) the tests. In particular, it specifically tests that the ical and HTML views include equivalent sets of events. Finally, the agenda_filter.html template is reworked to be more modular. - Legacy-Id: 18631
2 parents 517ebfa + d67b298 commit 7384c03

12 files changed

Lines changed: 1172 additions & 864 deletions

File tree

ietf/meeting/helpers.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,30 @@ def preprocess_assignments_for_agenda(assignments_queryset, meeting, extra_prefe
240240

241241
return assignments
242242

243+
def tag_assignments_with_filter_keywords(assignments):
244+
"""Add keywords for agenda filtering
245+
246+
Keywords are all lower case.
247+
"""
248+
for a in assignments:
249+
a.filter_keywords = {a.timeslot.type.slug.lower()}
250+
a.filter_keywords.update(filter_keywords_for_session(a.session))
251+
252+
def filter_keywords_for_session(session):
253+
keywords = {session.type.slug.lower()}
254+
group = getattr(session, 'historic_group', session.group)
255+
if group is not None:
256+
if group.state_id == 'bof':
257+
keywords.add('bof')
258+
keywords.add(group.acronym.lower())
259+
area = getattr(group, 'historic_parent', group.parent)
260+
if area is not None:
261+
keywords.add(area.acronym.lower())
262+
office_hours_match = re.match(r'^ *\w+(?: +\w+)* +office hours *$', session.name, re.IGNORECASE)
263+
if office_hours_match is not None:
264+
keywords.update(['officehours', session.name.lower().replace(' ', '')])
265+
return keywords
266+
243267
def read_session_file(type, num, doc):
244268
# XXXX FIXME: the path fragment in the code below should be moved to
245269
# settings.py. The *_PATH settings should be generalized to format()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
4+
"""Custom tags for the agenda filter template"""
5+
6+
from django import template
7+
8+
register = template.Library()
9+
10+
@register.filter
11+
def agenda_width_scale(filter_categories, spacer_scale):
12+
"""Compute the width scale for the agenda filter button table
13+
14+
Button columns are spacer_scale times as wide as the spacer columns between
15+
categories. There is one fewer spacer column than categories.
16+
"""
17+
category_count = len(filter_categories)
18+
column_count = sum([len(cat) for cat in filter_categories])
19+
# Refuse to return less than 1 to avoid width calculation problems.
20+
return max(spacer_scale * column_count + category_count - 1, 1)

ietf/meeting/tests_helpers.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Copyright The IETF Trust 2020, All Rights Reserved
2+
# -*- coding: utf-8 -*-
3+
from ietf.group.factories import GroupFactory
4+
from ietf.meeting.factories import SessionFactory, MeetingFactory
5+
from ietf.meeting.helpers import tag_assignments_with_filter_keywords
6+
from ietf.utils.test_utils import TestCase
7+
8+
9+
class HelpersTests(TestCase):
10+
def do_test_tag_assignments_with_filter_keywords(self, bof=False, historic=None):
11+
"""Assignments should be tagged properly
12+
13+
The historic param can be None, group, or parent, to specify whether to test
14+
with no historic_group, a historic_group but no historic_parent, or both.
15+
"""
16+
meeting_types = ['regular', 'plenary']
17+
group_state_id = 'bof' if bof else 'active'
18+
group = GroupFactory(state_id=group_state_id)
19+
historic_group = GroupFactory(state_id=group_state_id)
20+
historic_parent = GroupFactory(type_id='area')
21+
22+
if historic == 'parent':
23+
historic_group.historic_parent = historic_parent
24+
25+
# Create meeting and sessions
26+
meeting = MeetingFactory()
27+
for meeting_type in meeting_types:
28+
sess = SessionFactory(group=group, meeting=meeting, type_id=meeting_type)
29+
ts = sess.timeslotassignments.first().timeslot
30+
ts.type = sess.type
31+
ts.save()
32+
33+
# Create an office hours session in the group's area (i.e., parent). This is not
34+
# currently really needed, but will protect against areas and groups diverging
35+
# in a way that breaks keywording.
36+
office_hours = SessionFactory(
37+
name='some office hours',
38+
group=group.parent,
39+
meeting=meeting,
40+
type_id='other'
41+
)
42+
ts = office_hours.timeslotassignments.first().timeslot
43+
ts.type = office_hours.type
44+
ts.save()
45+
46+
assignments = meeting.schedule.assignments.all()
47+
orig_num_assignments = len(assignments)
48+
49+
# Set up historic groups if needed
50+
if historic:
51+
for a in assignments:
52+
if a.session != office_hours:
53+
a.session.historic_group = historic_group
54+
55+
# Execute the method under test
56+
tag_assignments_with_filter_keywords(assignments)
57+
58+
# Assert expected results
59+
self.assertEqual(len(assignments), orig_num_assignments, 'Should not change number of assignments')
60+
61+
if historic:
62+
expected_group = historic_group
63+
expected_area = historic_parent if historic == 'parent' else historic_group.parent
64+
else:
65+
expected_group = group
66+
expected_area = group.parent
67+
68+
for assignment in assignments:
69+
expected_filter_keywords = {assignment.timeslot.type.slug, assignment.session.type.slug}
70+
71+
if assignment.session == office_hours:
72+
expected_filter_keywords.update([
73+
group.parent.acronym,
74+
'officehours',
75+
'someofficehours',
76+
])
77+
else:
78+
expected_filter_keywords.update([
79+
expected_group.acronym,
80+
expected_area.acronym
81+
])
82+
if bof:
83+
expected_filter_keywords.add('bof')
84+
85+
self.assertCountEqual(
86+
assignment.filter_keywords,
87+
expected_filter_keywords,
88+
'Assignment has incorrect filter keywords'
89+
)
90+
91+
def test_tag_assignments_with_filter_keywords(self):
92+
self.do_test_tag_assignments_with_filter_keywords()
93+
self.do_test_tag_assignments_with_filter_keywords(historic='group')
94+
self.do_test_tag_assignments_with_filter_keywords(historic='parent')
95+
self.do_test_tag_assignments_with_filter_keywords(bof=True)
96+
self.do_test_tag_assignments_with_filter_keywords(bof=True, historic='group')
97+
self.do_test_tag_assignments_with_filter_keywords(bof=True, historic='parent')

0 commit comments

Comments
 (0)