module
pretalx.schedule.domain.room
Functions 7
active_schedule_pks(event)source
def active_schedule_pks(event):
pks = [event.wip_schedule.pk]
if current_schedule := event.current_schedule:
pks.append(current_schedule.pk)
return pks
annotate_room_usage(queryset, event)source
def annotate_room_usage(queryset, event):
slots = TalkSlot.objects.filter(room_id=OuterRef("pk"))
return queryset.annotate(
has_slots=Exists(slots),
has_scheduled_slots=Exists(
slots.filter(schedule_id__in=active_schedule_pks(event))
),
)
delete_room(room, *, log_kwargs=None)sourceDelete room together with the activity log entries pointing at it.
Raises django.db.models.deletion.ProtectedError if the room is still referenced by a TalkSlot; callers translate that into a user-facing error.
def delete_room(room, *, log_kwargs=None):
"""Delete ``room`` together with the activity log entries pointing at it.
Raises ``django.db.models.deletion.ProtectedError`` if the room is still
referenced by a ``TalkSlot``; callers translate that into a user-facing
error.
"""
with transaction.atomic():
room.logged_actions().delete()
room.delete(log_kwargs=log_kwargs or {})
hide_room(room, *, log_kwargs=None)source
def hide_room(room, *, log_kwargs=None):
if room.is_in_use:
raise ValidationError(ROOM_IN_USE_ERROR)
room.hidden = True
room.save(update_fields=["hidden", "updated"])
room.log_action(".hide", **(log_kwargs or {}))
room_is_in_use(room) -> boolsourceTrue if the current or the WIP schedule contains a slot in room.
def room_is_in_use(room) -> bool:
"""True if the current or the WIP schedule contains a slot in ``room``."""
return room.talks.filter(schedule_id__in=active_schedule_pks(room.event)).exists()
rooms_for_schedule(schedule)source
def rooms_for_schedule(schedule):
return schedule.event.rooms.filter(
Q(hidden=False) | Q(talks__schedule=schedule)
).distinct()
unhide_room(room, *, log_kwargs=None)source
def unhide_room(room, *, log_kwargs=None):
room.hidden = False
room.save(update_fields=["hidden", "updated"])
room.log_action(".unhide", **(log_kwargs or {}))