diff --git a/news/models.py b/news/models.py index f25809b79..34941e2f9 100644 --- a/news/models.py +++ b/news/models.py @@ -146,7 +146,11 @@ def standalone(self): return self.event_type == self.Type.STANDALONE def can_register(self, user: User, *, fail_if_not_standalone): - # Admins should always be allowed + # Registering for an event with no time places should never be allowed - no matter the `event_type` + if not self.timeplaces.exists(): + return False + + # Admins should always be allowed (except for the above case) if user.has_perm('news.cancel_ticket'): return True diff --git a/news/views.py b/news/views.py index 49ef76ed3..06610eabf 100644 --- a/news/views.py +++ b/news/views.py @@ -519,6 +519,10 @@ def setup(self, request, *args, **kwargs): time_place_pk = self.kwargs.get('time_place_pk') if time_place_pk is None: self.ticket_time_place = None + # Raise an error if the event has no time places (see the first `timeplaces` check in `Event.can_register()`) + if not self.event.timeplaces.exists(): + raise Http404("Cannot register for an event with no time places") + self.ticket_event = self.event else: self.ticket_time_place = get_object_or_404(TimePlace, pk=time_place_pk, event=self.event)