Skip to content

Commit

Permalink
schedule.json extensions (#1538)
Browse files Browse the repository at this point in the history
Co-authored-by: Franziska Kunsmann <hi@kunsmann.eu>
  • Loading branch information
saerdnaer and Kunsi committed Feb 12, 2024
1 parent 79bacfe commit c252163
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/pretalx/person/models/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import random
import uuid
from contextlib import suppress
from hashlib import md5
from urllib.parse import urljoin
Expand Down Expand Up @@ -284,6 +285,10 @@ def shred(self):

shred.alters_data = True

@cached_property
def guid(self) -> str:
return uuid.uuid5(uuid.NAMESPACE_URL, f"acct:{self.email.strip()}").__str__()

@cached_property
def gravatar_parameter(self) -> str:
return md5(self.email.strip().encode()).hexdigest()
Expand Down
38 changes: 33 additions & 5 deletions src/pretalx/schedule/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def __init__(self, event, schedule=None, with_accepted=False, with_breaks=False)
def metadata(self):
if not self.schedule:
return []
return {"base_url": self.event.urls.schedule.full()}

return {
"url": self.event.urls.schedule.full(),
"base_url": get_base_url(self.event),
}

@cached_property
def data(self):
Expand Down Expand Up @@ -151,6 +155,7 @@ class FrabJsonExporter(ScheduleData):
def get_data(self, **kwargs):
schedule = self.schedule
return {
"url": self.metadata["url"],
"version": schedule.version,
"base_url": self.metadata["base_url"],
"conference": {
Expand All @@ -161,6 +166,8 @@ def get_data(self, **kwargs):
"daysCount": self.event.duration,
"timeslot_duration": "00:05",
"time_zone_name": self.event.timezone,
"colors": {"primary": self.event.primary_color},
# "url": self.event.urls.base.full(), # TODO this should be the URL of the conference website itself, but we do not have a field for this value yet
"rooms": [
{
"name": str(room.name),
Expand All @@ -170,6 +177,13 @@ def get_data(self, **kwargs):
}
for room in self.event.rooms.all()
],
"tracks": [
{
"name": str(track.name),
"color": track.color,
}
for track in self.event.tracks.all()
],
"days": [
{
"index": day["index"],
Expand All @@ -179,15 +193,19 @@ def get_data(self, **kwargs):
"rooms": {
str(room["name"]): [
{
"url": talk.submission.urls.public.full(),
"id": talk.submission.id,
"guid": talk.uuid,
"logo": talk.submission.urls.image,
"date": talk.local_start.isoformat(),
"start": talk.local_start.strftime("%H:%M"),
"logo": (
talk.submission.urls.image.full()
if talk.submission.image
else None
),
"duration": talk.export_duration,
"room": str(room["name"]),
"slug": talk.frab_slug,
"url": talk.submission.urls.public.full(),
"title": talk.submission.title,
"subtitle": "",
"track": (
Expand All @@ -203,9 +221,12 @@ def get_data(self, **kwargs):
"do_not_record": talk.submission.do_not_record,
"persons": [
{
"guid": person.guid,
"id": person.id,
"code": person.code,
"public_name": person.get_display_name(),
"avatar": person.get_avatar_url(self.event)
or None,
"biography": getattr(
person.profiles.filter(
event=self.event
Expand Down Expand Up @@ -262,9 +283,16 @@ def get_data(self, **kwargs):
def render(self, **kwargs):
content = self.get_data()
return (
f"{self.event.slug}.json".format(self.event.slug),
f"{self.event.slug}.json",
"application/json",
json.dumps({"schedule": content}, cls=I18nJSONEncoder),
json.dumps(
{
"$schema": "https://c3voc.de/schedule/schema.json",
"generator": {"name": "pretalx", "version": __version__},
"schedule": content,
},
cls=I18nJSONEncoder,
),
)


Expand Down

0 comments on commit c252163

Please sign in to comment.