def test_union(avails, expected): actual = Availability.union(avails) assert len(actual) == len(expected) for act, exp in zip(actual, expected): assert act.start == exp.start assert act.end == exp.end
def get_talk_warnings( self, talk, with_speakers=True, room_avails=None, speaker_avails=None, ) -> list: """A list of warnings that apply to this slot. Warnings are dictionaries with a ``type`` (``room`` or ``speaker``, for now) and a ``message`` fit for public display. This property only shows availability based warnings. """ from pretalx.schedule.models import Availability, TalkSlot if not talk.start or not talk.submission: return [] warnings = [] availability = talk.as_availability if talk.room: if room_avails is None: room_avails = talk.room.availabilities.all() if not any( room_availability.contains(availability) for room_availability in Availability.union(room_avails)): warnings.append({ "type": "room", "message": _("The room is not available at the scheduled time."), }) for speaker in talk.submission.speakers.all(): if with_speakers: profile = speaker.event_profile(event=self.event) if speaker_avails is not None: profile_availabilities = speaker_avails.get(profile.pk) else: profile_availabilities = list(profile.availabilities.all()) if profile_availabilities and not any( speaker_availability.contains(availability) for speaker_availability in Availability.union( profile_availabilities)): warnings.append({ "type": "speaker", "speaker": { "name": speaker.get_display_name(), "id": speaker.pk, }, "message": _("A speaker is not available at the scheduled time."), }) overlaps = (TalkSlot.objects.filter( schedule=self, submission__speakers__in=[speaker]).filter( models.Q(start__lt=talk.start, end__gt=talk.start) | models.Q(start__lt=talk.real_end, end__gt=talk.real_end) | models.Q(start__gt=talk.start, end__lt=talk.real_end)). exists()) if overlaps: warnings.append({ "type": "speaker", "speaker": { "name": speaker.get_display_name(), "id": speaker.pk, }, "message": _("A speaker is holding another session at the scheduled time." ), }) return warnings