From 7600e63409dbe864058fc7c2bf65e5e01d738fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=A4ttasch?= <benjamin.haettasch@fachschaft.informatik.tu-darmstadt.de> Date: Thu, 14 May 2020 00:59:18 +0200 Subject: [PATCH] Introduce redirect to error when no categories for event configured Trying to load the AK list or AK submission page will result in an error message when there are no categories configured yet. Additionally, the virtual Wishes category is now represented by a real category object instead of an dictionary --- .../submission_not_configured.html | 22 +++++++++++++++++++ AKSubmission/urls.py | 1 + AKSubmission/views.py | 21 +++++++++++++++--- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 AKSubmission/templates/AKSubmission/submission_not_configured.html diff --git a/AKSubmission/templates/AKSubmission/submission_not_configured.html b/AKSubmission/templates/AKSubmission/submission_not_configured.html new file mode 100644 index 00000000..48de5f60 --- /dev/null +++ b/AKSubmission/templates/AKSubmission/submission_not_configured.html @@ -0,0 +1,22 @@ +{% extends 'AKSubmission/submission_base.html' %} + +{% load i18n %} +{% load fontawesome_5 %} +{% load static %} + +{% block title %}{% trans "AKs" %}: {{ event.name }} - {% trans "AK Submission" %}{% endblock %} + +{% block breadcrumbs %} + {% include "AKSubmission/submission_breadcrumbs.html" %} + <li class="breadcrumb-item active">{% trans "AK Submission" %}</li> +{% endblock %} + +{% block content %} + <h1>{{ event.name }}</h1> + + {% include "AKSubmission/messages.html" %} + + <div class="alert alert-warning" style="margin-top:20px;margin-bottom: 20px;"> + {% trans "System is not yet configured for AK submission and listing. Please try again later." %} + </div> +{% endblock %} diff --git a/AKSubmission/urls.py b/AKSubmission/urls.py index 982db8a7..57dd16ef 100644 --- a/AKSubmission/urls.py +++ b/AKSubmission/urls.py @@ -26,6 +26,7 @@ urlpatterns = [ path('<slug:slug>/edit/', views.AKOwnerEditView.as_view(), name='akowner_edit'), path('<slug:owner_slug>/new/', views.AKSubmissionView.as_view(), name='submit_ak'), path('new_wish/', views.AKWishSubmissionView.as_view(), name='submit_ak_wish'), + path('error/', views.SubmissionErrorNotConfiguredView.as_view(), name='error_not_configured'), ]) ), ] diff --git a/AKSubmission/views.py b/AKSubmission/views.py index 662d038d..4678c840 100644 --- a/AKSubmission/views.py +++ b/AKSubmission/views.py @@ -1,11 +1,11 @@ from django.conf import settings from django.contrib import messages -from django.http import Http404, HttpResponseRedirect +from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy from django.utils.translation import gettext_lazy as _ from django.views import View -from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView, RedirectView +from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView, RedirectView, TemplateView from AKModel.models import AK, AKCategory, AKTag, AKOwner, AKSlot, AKTrack from AKModel.views import EventSlugMixin @@ -13,6 +13,10 @@ from AKModel.views import FilterByEventSlugMixin from AKSubmission.forms import AKWishForm, AKOwnerForm, AKEditForm, AKSubmissionForm, AKDurationForm +class SubmissionErrorNotConfiguredView(EventSlugMixin, TemplateView): + template_name = "AKSubmission/submission_not_configured.html" + + class AKOverviewView(FilterByEventSlugMixin, ListView): model = AKCategory context_object_name = "categories" @@ -28,6 +32,17 @@ class AKOverviewView(FilterByEventSlugMixin, ListView): def get_table_title(self, context): return _("All AKs") + def get(self, request, *args, **kwargs): + self._load_event() + self.object_list = self.get_queryset() + + # No categories yet? Redirect to configuration error page + if self.object_list.count() == 0: + return redirect(reverse_lazy("submit:error_not_configured", kwargs={'event_slug': self.event.slug})) + + context = self.get_context_data() + return self.render_to_response(context) + def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) @@ -46,7 +61,7 @@ class AKOverviewView(FilterByEventSlugMixin, ListView): if self.wishes_as_category: categories_with_aks.append( - ({"name": _("Wishes"), "pk": "wish", "description": _("AKs one would like to have")}, ak_wishes)) + (AKCategory(name=_("Wishes"), pk=0, description=_("AKs one would like to have")), ak_wishes)) context["categories_with_aks"] = categories_with_aks context["active_category"] = self.get_active_category_name(context) -- GitLab