Skip to content
Snippets Groups Projects
Commit 7600e634 authored by Benjamin Hättasch's avatar Benjamin Hättasch
Browse files

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
parent e3e6e78d
No related branches found
No related tags found
1 merge request!34Introduce redirect to error page when no categories for event are configured
{% 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 %}
......@@ -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'),
])
),
]
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment