Skip to content

Commit

Permalink
Merge pull request #614 from CTPUG/static-ids
Browse files Browse the repository at this point in the history
Use static GUIDs in the frab schedule, when possible
  • Loading branch information
stefanor committed Sep 24, 2021
2 parents 9d3d0f7 + de7b296 commit 108c0c8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
13 changes: 11 additions & 2 deletions wafer/schedule/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,17 @@ def get_duration_minutes(self):

@property
def guid(self):
"""Return a GUID for the ScheduleItem (for frab xml)"""
hmac = salted_hmac('wafer-event-uuid', str(self.pk))
"""Return a GUID for the ScheduleItem (for frab xml)
We return static GUIDs across re-scheduling, when possible.
"""
if self.talk:
id_ = 'talk:' + str(self.talk.pk)
elif self.page and self.page.scheduleitem_set.count() == 1:
id_ = 'page:' + str(self.page.pk)
else:
id_ = 'schedule_item:' + str(self.pk)
hmac = salted_hmac('wafer-event-uuid', id_)
return UUID(bytes=hmac.digest()[:16])


Expand Down
4 changes: 3 additions & 1 deletion wafer/schedule/templates/wafer.schedule/penta_schedule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
{# this is more than a little horrible, but will do for testing #}
{% for row_venue, items in row.items.items %}
{% if row_venue == venue and items.item %}
{# The event id is the ScheduleItem pk, which should be unique enough #}
{# The event id is the ScheduleItem pk, which should be unique #}
{# enough, but changes if the event is rescheduled. #}
{# Talks' guid will be stable across re-scheduling. #}
<event id="{{ items.item.pk }}" guid="{{ items.item.guid }}">
<date>{{ row.start_time.isoformat }}</date>
<start>{{ row.start_time|time:"H:i" }}</start>
Expand Down
31 changes: 31 additions & 0 deletions wafer/schedule/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,34 @@ def test_slot_save_prev_next(self):
# No other items should have changed, as time changes don't
# cascade that way
self.assertEqual(item.last_updated, update_times[item.pk])


class ScheduleItemGUIDTests(TestCase):
def setUp(self):
venue1 = Venue.objects.create(order=1, name='Venue 1')
self.venues = [venue1]

def test_unique_guid(self):
"""Test that the all guids are unique."""
pages = make_pages(2)
items = make_items(self.venues * 2, pages)

guids = set(item.guid for item in items)
self.assertEqual(len(guids), len(items))

def test_rescheduled_page_keeps_guid(self):
"""A page that's in the schedule once keeps its guid when rescheduled"""
pages = make_pages(2)
items = make_items(self.venues * 2, pages)
guid = items[0].guid
# Reschedule
for item in items:
item.delete()
items = make_items(self.venues, pages)
self.assertEqual(guid, items[0].guid)

def test_double_scheduled_page_has_unique_guid(self):
"""A page that's in the schedule twice has a unique GUID per instance"""
pages = make_pages(1)
items = make_items(self.venues * 2, pages * 2)
self.assertNotEqual(items[0].guid, items[1].guid)

0 comments on commit 108c0c8

Please sign in to comment.