diff --git a/AKModel/views.py b/AKModel/views.py index 8374cb41f6377ba7bb09d68af5c14055dffbf0d8..539c4f43d23c4dee5cccfc11903bf34559f4ade7 100644 --- a/AKModel/views.py +++ b/AKModel/views.py @@ -25,7 +25,8 @@ class EventSlugMixin: def _load_event(self): # Find event based on event slug - self.event = get_object_or_404(Event, slug=self.kwargs.get("event_slug", None)) + if self.event is None: + self.event = get_object_or_404(Event, slug=self.kwargs.get("event_slug", None)) def get(self, request, *args, **kwargs): self._load_event() diff --git a/AKPlan/templates/AKPlan/plan_index.html b/AKPlan/templates/AKPlan/plan_index.html index c7a5460bcb880a64face98b5f60ad244b6dc0d40..4fdbc700a7c929d2d1dc26067f88edf1e60c8126 100644 --- a/AKPlan/templates/AKPlan/plan_index.html +++ b/AKPlan/templates/AKPlan/plan_index.html @@ -81,7 +81,7 @@ {% block content %} <div class="float-right"> <ul class="nav nav-pills"> - {% if event.room_set.count > 0 %} + {% if rooms|length > 0 %} <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" @@ -94,13 +94,13 @@ </div> </li> {% endif %} - {% if event.aktrack_set.count > 0 %} + {% if tracks|length > 0 %} <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">{% trans "Tracks" %}</a> <div class="dropdown-menu"> - {% for t in event.aktrack_set.all %} + {% for t in tracks %} <a class="dropdown-item" href="{% url "plan:plan_track" event_slug=event.slug pk=t.pk %}">{{ t }}</a> {% endfor %} diff --git a/AKPlan/templates/AKPlan/plan_room.html b/AKPlan/templates/AKPlan/plan_room.html index 7a7e62ed4076c3432075e48fad51efdf30831909..8acd1fe7bfaea8859df35750c061a8e6d69de26b 100644 --- a/AKPlan/templates/AKPlan/plan_room.html +++ b/AKPlan/templates/AKPlan/plan_room.html @@ -16,7 +16,7 @@ {% block encode %} [ - {% for slot in room.akslot_set.all %} + {% for slot in slots %} {% if slot.start %} {'title': '{{ slot.ak }}', 'start': '{{ slot.start | timezone:event.timezone | date:"Y-m-d H:i:s" }}', diff --git a/AKPlan/views.py b/AKPlan/views.py index 2c9c6d2b19d5f011962d2b9db7d5537da8a0d5d7..828e5e584e2646443e40f9dff623ca8b0a4d6391 100644 --- a/AKPlan/views.py +++ b/AKPlan/views.py @@ -18,7 +18,7 @@ class PlanIndexView(FilterByEventSlugMixin, ListView): def get_queryset(self): # Ignore slots not scheduled yet - return super().get_queryset().filter(start__isnull=False) + return super().get_queryset().filter(start__isnull=False).select_related('ak', 'room', 'ak__category') def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) @@ -54,6 +54,8 @@ class PlanIndexView(FilterByEventSlugMixin, ListView): if settings.PLAN_SHOW_HIERARCHY: context["buildings"] = sorted(buildings) + context["tracks"] = self.event.aktrack_set.all() + return context @@ -94,6 +96,11 @@ class PlanRoomView(FilterByEventSlugMixin, DetailView): model = Room context_object_name = "room" + def get_context_data(self, *, object_list=None, **kwargs): + context = super().get_context_data(object_list=object_list, **kwargs) + context["slots"] = AKSlot.objects.filter(room=context['room']).select_related('ak', 'ak__category', 'ak__track') + return context + class PlanTrackView(FilterByEventSlugMixin, DetailView): template_name = "AKPlan/plan_track.html" @@ -102,9 +109,5 @@ class PlanTrackView(FilterByEventSlugMixin, DetailView): def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) - - context["slots"] = [] - for ak in context["track"].ak_set.all(): - context["slots"].extend(ak.akslot_set.all()) - + context["slots"] = AKSlot.objects.filter(event=self.event, ak__track=context['track']).select_related('ak', 'room', 'ak__category') return context