redirect to the events list if nothing is scheduled yet

This commit is contained in:
Thomas Steen Rasmussen 2018-07-18 00:58:33 +02:00
parent d46ccc530b
commit 11a94b477c

View file

@ -672,6 +672,15 @@ class NoScriptScheduleView(CampViewMixin, TemplateView):
class ScheduleView(CampViewMixin, TemplateView): class ScheduleView(CampViewMixin, TemplateView):
template_name = 'schedule_overview.html' template_name = 'schedule_overview.html'
def dispatch(self, request, *args, **kwargs):
"""
If no events are scheduled redirect to the event page
"""
response = super().dispatch(request, *args, **kwargs)
if not models.EventInstance.objects.filter(event__track__camp=self.camp).exists():
return(redirect(reverse('program:event_index', kwargs={'camp_slug': self.camp.slug})))
return response
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(ScheduleView, self).get_context_data(**kwargs) context = super(ScheduleView, self).get_context_data(**kwargs)
context['schedule_midnight_offset_hours'] = settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS context['schedule_midnight_offset_hours'] = settings.SCHEDULE_MIDNIGHT_OFFSET_HOURS