Skip to content

Commit

Permalink
Add fallback value for room guid (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
saerdnaer committed Feb 12, 2024
1 parent 7f3f4c1 commit a26219f
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/pretalx/agenda/templates/agenda/schedule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% endfor %}
</conference>
{% for day in data %}<day index='{{ day.index }}' date='{{ day.start.date|date:"c" }}' start='{{ day.start|date:"c" }}' end='{{ day.end|date:"c" }}'>
{% for room in day.rooms %}<room name='{{ room.name|xmlescape }}'{% if room.guid %} guid='{{ room.guid }}'{% endif %}>
{% for room in day.rooms %}<room name='{{ room.name|xmlescape }}' guid='{{ room.guid }}'>
{% for talk in room.talks %}<event guid='{{ talk.uuid }}' id='{{ talk.submission.id }}'>
<room>{{ room.name|xmlescape }}</room>
<title>{{ talk.submission.title|xmlescape }}</title>
Expand Down
13 changes: 11 additions & 2 deletions src/pretalx/api/serializers/room.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from i18nfield.rest_framework import I18nAwareModelSerializer
from rest_framework.serializers import ModelSerializer, SerializerMethodField
from rest_framework.serializers import CharField, ModelSerializer, SerializerMethodField

from pretalx.schedule.models import Availability, Room

Expand All @@ -17,13 +17,22 @@ class Meta:

class RoomSerializer(I18nAwareModelSerializer):
url = SerializerMethodField()
guid = CharField(source="uuid")

def get_url(self, obj):
return obj.urls.edit

class Meta:
model = Room
fields = ("id", "guid", "name", "description", "capacity", "position", "url")
fields = (
"id",
"guid",
"name",
"description",
"capacity",
"position",
"url",
)


class RoomOrgaSerializer(RoomSerializer):
Expand Down
2 changes: 1 addition & 1 deletion src/pretalx/locale/de_DE/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7985,7 +7985,7 @@ msgstr ""
msgid "GUID"
msgstr "GUID"

#: pretalx/schedule/models/room.py:25
#: pretalx/schedule/models/room.py:32
msgid "Unique identifier (UUID) to help external tools identify the room."
msgstr ""
"Eindeutiger Bezeichner (UUID), der externen Anwendungen hilft, diesen Raum "
Expand Down
2 changes: 1 addition & 1 deletion src/pretalx/locale/django.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7042,7 +7042,7 @@ msgstr ""
msgid "GUID"
msgstr ""

#: pretalx/schedule/models/room.py:25
#: pretalx/schedule/models/room.py:32
msgid "Unique identifier (UUID) to help external tools identify the room."
msgstr ""

Expand Down
4 changes: 2 additions & 2 deletions src/pretalx/schedule/exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def data(self):
if str(talk.room.name) not in day_data["rooms"]:
day_data["rooms"][str(talk.room.name)] = {
"id": talk.room.id,
"guid": talk.room.guid,
"guid": talk.room.uuid,
"name": talk.room.name,
"description": talk.room.description,
"position": talk.room.position,
Expand Down Expand Up @@ -164,7 +164,7 @@ def get_data(self, **kwargs):
"rooms": [
{
"name": str(room.name),
"guid": room.guid,
"guid": room.uuid,
"description": str(room.description) or None,
"capacity": room.capacity,
}
Expand Down
1 change: 1 addition & 0 deletions src/pretalx/schedule/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def __init__(self, *args, **kwargs):
"Information for speakers, e.g.: Projector has only HDMI input."
)
self.fields["capacity"].widget.attrs["placeholder"] = "300"
self.fields["guid"].widget.attrs["placeholder"] = self.instance.uuid or ""

class Meta:
model = Room
Expand Down
16 changes: 16 additions & 0 deletions src/pretalx/schedule/models/room.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import uuid
from functools import cached_property

from django.db import models
from django.utils.translation import gettext_lazy as _
from i18nfield.fields import I18nCharField

from pretalx.common.mixins.models import OrderedModel, PretalxModel
from pretalx.common.models.settings import GlobalSettings
from pretalx.common.urls import EventUrls


Expand Down Expand Up @@ -65,3 +69,15 @@ def __str__(self) -> str:
@staticmethod
def get_order_queryset(event):
return event.rooms.all()

@cached_property
def uuid(self):
"""Either a UUID5 calculated from the submission code and the instance identifier;
or GUID value of the room, if it was imported or set manually."""
if self.guid:
return self.guid

if not self.pk:
return ""

return uuid.uuid5(GlobalSettings().get_instance_identifier(), f"room:{self.pk}")

0 comments on commit a26219f

Please sign in to comment.