diff --git a/AKSubmission/templates/AKSubmission/submission_overview.html b/AKSubmission/templates/AKSubmission/submission_overview.html index 15748b2ad5c96fbc2e5ceca1d131825d7b9d12d3..5c4ab1d017769c80f1afc1b88d93709136dd1efd 100644 --- a/AKSubmission/templates/AKSubmission/submission_overview.html +++ b/AKSubmission/templates/AKSubmission/submission_overview.html @@ -70,7 +70,7 @@ </noscript> <ul class="nav nav-tabs" style="margin-bottom:15px"> - {% for category, _ in categories %} + {% for category, _ in categories_with_aks %} <li class="nav-item"> <a class="nav-link {% if forloop.first %}active{% endif %}" data-toggle="tab" href="#category_{{ category.pk }}">{{ category.name }}</a> @@ -79,7 +79,7 @@ </ul> <div id="akListTabbed" class="tab-content"> - {% for category, AKs in categories %} + {% for category, AKs in categories_with_aks %} <div class="tab-pane fade {% if forloop.first %}show active{% endif %}" id="category_{{ category.pk }}"> <p><b>{{ category.name }}:</b> {{ category.description }}</p> {% include "AKSubmission/ak_list_table.html" %} diff --git a/AKSubmission/views.py b/AKSubmission/views.py index dee7f16c93d95c53d885d252629c501e752da36e..122db18f12e958947f1496c6ac3cce2a360663d9 100644 --- a/AKSubmission/views.py +++ b/AKSubmission/views.py @@ -14,33 +14,30 @@ from AKSubmission.forms import AKWishForm, AKOwnerForm, AKEditForm, AKSubmission class SubmissionOverviewView(FilterByEventSlugMixin, ListView): - model = AK - context_object_name = "AKs" + model = AKCategory + context_object_name = "categories" template_name = "AKSubmission/submission_overview.html" - ordering = ['category'] def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) # Sort AKs into different lists (by their category) - categories = [] - aks_for_category = [] ak_wishes = [] - current_category = None - for ak in context["AKs"]: - if ak.category != current_category: - current_category = ak.category - aks_for_category = [] - categories.append((current_category, aks_for_category)) - if settings.WISHES_AS_CATEGORY and ak.wish: - ak_wishes.append(ak) - else: - aks_for_category.append(ak) + categories_with_aks = [] + + for category in context["categories"]: + aks_for_category = [] + for ak in category.ak_set.all(): + if settings.WISHES_AS_CATEGORY and ak.wish: + ak_wishes.append(ak) + else: + aks_for_category.append(ak) + categories_with_aks.append((category, aks_for_category)) if settings.WISHES_AS_CATEGORY: - categories.append( + categories_with_aks.append( ({"name": _("Wishes"), "pk": "wish", "description": _("AKs one would like to have")}, ak_wishes)) - context["categories"] = categories + context["categories_with_aks"] = categories_with_aks # Get list of existing owners for event (for AK submission start) context["existingOwners"] = AKOwner.objects.filter(event=self.event)