Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit 2c53034

Browse files
authored
Fix see in schedule button (#1439)
* Fix URL used in "See in schedule" button. Fixes #1438 * Add schedule string to "Show in schedule" button. See #1438 * Handle case where event is None * Add APIs to query UTC event datetimes. Fix broken tests.
1 parent bbaa21d commit 2c53034

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

conference/models.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import os.path
44
import uuid
5+
import pytz
56
from collections import defaultdict
67
from urllib.parse import urlencode
78

@@ -753,7 +754,7 @@ def get_schedule_url(self):
753754

754755
url = event.schedule.get_absolute_url()
755756
slug = urlencode({'selected': self.slug})
756-
time = event.start_time.strftime('%H:%M-UTC')
757+
time = event.get_utc_start_datetime().strftime('%H:%M-UTC')
757758
return f"{url}?{slug}#{time}"
758759

759760
def get_slides_url(self):
@@ -1182,11 +1183,45 @@ def get_duration(self):
11821183
return 0
11831184

11841185
def get_time_range(self):
1186+
1187+
""" Return time range of the event in local time.
1188+
1189+
"""
11851190
n = datetime.datetime.combine(self.schedule.date, self.start_time)
11861191
return (
11871192
n, (n + datetime.timedelta(seconds=self.get_duration() * 60))
11881193
)
11891194

1195+
def get_utc_start_datetime(self):
1196+
1197+
""" Return start time as datetime in UTC.
1198+
1199+
"""
1200+
dt = datetime.datetime.combine(self.schedule.date, self.start_time)
1201+
return dt.astimezone(datetime.timezone.utc)
1202+
1203+
def get_utc_end_datetime(self):
1204+
1205+
""" Return end time as datetime in UTC.
1206+
1207+
"""
1208+
return self.get_utc_start_datetime() + datetime.timedelta(
1209+
seconds=self.get_duration() * 60)
1210+
1211+
def get_schedule_string(self):
1212+
1213+
""" Return a text representation of the scheduled slot.
1214+
1215+
"""
1216+
(start, end) = self.get_time_range()
1217+
duration = self.get_duration()
1218+
tz = pytz.timezone(settings.TIME_ZONE)
1219+
end = tz.localize(end)
1220+
return (
1221+
f'{start.strftime("%a, %b %d, %H:%M")}-'
1222+
f'{end.strftime("%H:%M %Z")} ({duration} min)'
1223+
)
1224+
11901225
def get_description(self):
11911226
if self.talk:
11921227
return self.talk.title

conference/talks.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ def dump_relevant_talk_information_to_dict(talk: Talk, speaker_tickets=None):
145145
availability = talk.availability.split('|')
146146
event = talk.get_event()
147147
if event is not None:
148-
event = event.json_dump()
148+
event_json = event.json_dump()
149+
event_schedule = event.get_schedule_string()
150+
else:
151+
event_json = None
152+
event_schedule = ""
149153
output = {
150154
"title": talk.title,
151155
"uuid": talk.uuid,
@@ -164,8 +168,9 @@ def dump_relevant_talk_information_to_dict(talk: Talk, speaker_tickets=None):
164168
"status": talk.status,
165169
"tags": [t.name for t in talk.tags.all()],
166170
"speakers": [],
167-
"event": event,
171+
"event": event_json,
168172
"schedule_url": talk.get_schedule_url(),
173+
"schedule_string": event_schedule,
169174
"slides_url": talk.get_slides_url(),
170175
"availability": availability,
171176
}

pycon/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def _(x):
9595
USE_TZ = True
9696

9797
TIME_ZONE = 'Europe/Amsterdam'
98+
9899
LANGUAGE_CODE = 'en'
99100

100101
LANGUAGES = (

templates/conference/talks/talk.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h5>{% for speaker in talk_as_dict.speakers %}
4141
{% endfor %}
4242
</p>
4343
{% if talk_as_dict.schedule_url %}
44-
<a class="btn btn-primary" href="{{ talk_as_dict.schedule_url }}">See in schedule</a>
44+
<a class="btn btn-primary" href="{{ talk_as_dict.schedule_url }}">See in schedule: {{ talk_as_dict.schedule_string }}</a>
4545
{% endif %}
4646
{% if talk_as_dict.slides_url %}
4747
<a class="btn btn-primary" href="{{ talk_as_dict.slides_url }}">Download/View Slides</a>

tests/factories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,7 @@ class Meta:
427427

428428
schedule = factory.SubFactory(ScheduleFactory)
429429
talk = factory.SubFactory(TalkFactory)
430-
start_time = factory.LazyFunction(timezone.now)
431-
430+
start_time = factory.LazyAttribute(lambda _: timezone.now().time())
432431

433432
class EventTrackFactory(factory.django.DjangoModelFactory):
434433
class Meta:

tests/test_talks.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ def test_show_talk_link_in_schedule(client):
337337
url = talk.get_absolute_url()
338338

339339
response = client.get(url)
340+
html = response.content.decode()
340341

341-
start_time = event.start_time.strftime('%H:%M-UTC')
342-
assert f"{talk.slug}#{start_time}" in response.content.decode()
342+
time_range = event.get_time_range()
343+
344+
utc_start = event.get_utc_start_datetime()
345+
schedule_hash = utc_start.strftime('%H:%M-UTC')
346+
assert f"{talk.slug}#{schedule_hash}" in html
347+
348+
schedule_string = event.get_schedule_string()
349+
assert schedule_string in html

0 commit comments

Comments
 (0)