diff --git a/AKDashboard/templates/AKDashboard/dashboard_row.html b/AKDashboard/templates/AKDashboard/dashboard_row.html index 36b32af5c175ba9389dcf29253af0df293464947..4b3e40c53f1ece45df17a6253e7547e6b0ca31e5 100644 --- a/AKDashboard/templates/AKDashboard/dashboard_row.html +++ b/AKDashboard/templates/AKDashboard/dashboard_row.html @@ -40,7 +40,7 @@ </a> {% endif %} {% endif %} - {% if 'AKSubmission'|check_app_installed %} + {% if 'AKSubmission'|check_app_installed and event.active %} <a class="dashboard-box btn btn-primary" href="{% url 'submit:submission_overview' event_slug=event.slug %}"> <div class="col-sm-12 col-md-3 col-lg-2 dashboard-button"> diff --git a/AKSubmission/templates/AKSubmission/ak_list.html b/AKSubmission/templates/AKSubmission/ak_list.html index 3e4098bc2d536e96aab49229c8be07011b8e2da5..ac774bd771433385b685c464e68a6ad36a48b31d 100644 --- a/AKSubmission/templates/AKSubmission/ak_list.html +++ b/AKSubmission/templates/AKSubmission/ak_list.html @@ -1,49 +1,46 @@ -{% extends 'AKSubmission/submission_base.html' %} - {% load i18n %} -{% load fontawesome_5 %} - -{% load tags_AKSubmission %} - -{% block title %}{% trans "AKs" %}: {{ event.name }} - {% trans "AKs" %}{% endblock %} - -{% block imports %} - <style> - /* Prevent wrapping of buttons in AK table */ - .table td:nth-child(5) { - white-space: nowrap; - } - </style> -{% endblock %} - -{% block breadcrumbs %} - {% include "AKSubmission/submission_breadcrumbs.html" %} - <li class="breadcrumb-item"><a - href="{% url 'submit:submission_overview' event_slug=event.slug %}">{% trans "AK Submission" %}</a></li> - <li class="breadcrumb-item active">{% trans "AK List" %}</li> -{% endblock %} - -{% block content %} - <h1>{{ event.name }}: {% trans "AK List" %}</h1> - - {% if categories.count > 0 %} - <b>{% trans 'Categories' %}:</b> - {% category_list categories event.slug %} - {% endif %} - - <br><br> - - {% if tracks.count > 0 %} - <b>{% trans 'Tracks' %}:</b> - {% track_list tracks event.slug %} - {% endif %} - - <br><br> - - {% if filter_condition_string != "" %} - <h2 class="text-secondary">{{ filter_condition_string }}</h2> - {% endif %} - - {% include "AKSubmission/ak_list_table.html" %} -{% endblock %} +<div class="float-right"> + <ul class="nav nav-pills"> + <li class="nav-item"> + <a class="nav-link" href="{% url 'submit:ak_list' event_slug=event.slug %}">{% trans "All AKs" %}</a> + </li> + {% if event.aktrack_set.count > 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" style=""> + {% for track in event.aktrack_set.all %} + <a class="dropdown-item" + href="{% url 'submit:ak_list_by_track' event_slug=event.slug track_pk=track.pk %}"> + {{ track }}</a> + {% endfor %} + </div> + </li> + {% endif %} + </ul> +</div> + +<h2>{{ table_title }}</h2> + +<noscript> + {% include "AKSubmission/ak_table.html" %} +</noscript> + +<ul class="nav nav-tabs" style="margin-bottom:15px"> + {% for category, _ in categories_with_aks %} + <li class="nav-item"> + <a class="nav-link {% if category.name == active_category %}active{% endif %}" data-toggle="tab" + href="#category_{{ category.pk }}">{{ category.name }}</a> + </li> + {% endfor %} +</ul> + +<div id="akListTabbed" class="tab-content"> + {% for category, AKs in categories_with_aks %} + <div class="tab-pane fade {% if category.name == active_category %}show active{% endif %}" id="category_{{ category.pk }}"> + <p><b>{{ category.name }}:</b> {{ category.description }}</p> + {% include "AKSubmission/ak_table.html" %} + </div> + {% endfor %} +</div> diff --git a/AKSubmission/templates/AKSubmission/ak_overview.html b/AKSubmission/templates/AKSubmission/ak_overview.html new file mode 100644 index 0000000000000000000000000000000000000000..45342420bd27d939b48d581cc65ab1687308f3c9 --- /dev/null +++ b/AKSubmission/templates/AKSubmission/ak_overview.html @@ -0,0 +1,30 @@ +{% extends 'AKSubmission/submission_base.html' %} + +{% load i18n %} +{% load fontawesome_5 %} + +{% load tags_AKSubmission %} + +{% block title %}{% trans "AKs" %}: {{ event.name }} - {% trans "AKs" %}{% endblock %} + +{% block imports %} + <style> + /* Prevent wrapping of buttons in AK table */ + .table td:nth-child(5) { + white-space: nowrap; + } + </style> +{% endblock %} + +{% block breadcrumbs %} + {% include "AKSubmission/submission_breadcrumbs.html" %} + <li class="breadcrumb-item"><a + href="{% url 'submit:submission_overview' event_slug=event.slug %}">{% trans "AK Submission" %}</a></li> + <li class="breadcrumb-item active">{% trans "AK List" %}</li> +{% endblock %} + +{% block content %} + <h1>{% trans "AKs" %}: {{ event.name }}</h1> + + {% include "AKSubmission/ak_list.html" %} +{% endblock %} diff --git a/AKSubmission/templates/AKSubmission/ak_list_table.html b/AKSubmission/templates/AKSubmission/ak_table.html similarity index 94% rename from AKSubmission/templates/AKSubmission/ak_list_table.html rename to AKSubmission/templates/AKSubmission/ak_table.html index 0f22739663c4f8228f944e69e749c1d73a16cb6e..485c982ecc3a29be9e5b84ca7d09c969048966ce 100644 --- a/AKSubmission/templates/AKSubmission/ak_list_table.html +++ b/AKSubmission/templates/AKSubmission/ak_table.html @@ -58,6 +58,10 @@ <tr> <td colspan="5" class="small">{{ ak.description }}</td> </tr> + {% empty %} + <tr> + <td colspan="5" class="small">{% trans "There are no AKs in this category yet" %}</td> + </tr> {% endfor %} </tbody> </table> diff --git a/AKSubmission/templates/AKSubmission/submission_overview.html b/AKSubmission/templates/AKSubmission/submission_overview.html index 5c4ab1d017769c80f1afc1b88d93709136dd1efd..dd09c528306b5f956dbdd6fa72ebc5a02f1e7e61 100644 --- a/AKSubmission/templates/AKSubmission/submission_overview.html +++ b/AKSubmission/templates/AKSubmission/submission_overview.html @@ -63,28 +63,5 @@ </div> {% endif %} - <h2>{% trans "Current AKs" %}</h2> - - <noscript> - {% include "AKSubmission/ak_list_table.html" %} - </noscript> - - <ul class="nav nav-tabs" style="margin-bottom:15px"> - {% 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> - </li> - {% endfor %} - </ul> - - <div id="akListTabbed" class="tab-content"> - {% 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" %} - </div> - {% endfor %} - </div> - + {% include "AKSubmission/ak_list.html" %} {% endblock %} diff --git a/AKSubmission/urls.py b/AKSubmission/urls.py index 3528b45d09e7486d9fc6b56363bc86dce56a8dd0..982db8a7130b065a5992022be6b3ae36c248da9d 100644 --- a/AKSubmission/urls.py +++ b/AKSubmission/urls.py @@ -16,7 +16,7 @@ urlpatterns = [ path('ak/<int:pk>/add_slot/', views.AKSlotAddView.as_view(), name='akslot_add'), path('akslot/<int:pk>/edit/', views.AKSlotEditView.as_view(), name='akslot_edit'), path('akslot/<int:pk>/delete/', views.AKSlotDeleteView.as_view(), name='akslot_delete'), - path('aks/', views.AKListView.as_view(), name='ak_list'), + path('aks/', views.AKOverviewView.as_view(), name='ak_list'), path('aks/category/<int:category_pk>/', views.AKListByCategoryView.as_view(), name='ak_list_by_category'), path('aks/tag/<int:tag_pk>/', views.AKListByTagView.as_view(), name='ak_list_by_tag'), path('aks/track/<int:track_pk>/', views.AKListByTrackView.as_view(), name='ak_list_by_track'), diff --git a/AKSubmission/views.py b/AKSubmission/views.py index 78c2fcde1cb5ef512b53f1180145c51037e7459b..662d038d113c6fb1f85e7461845c4407792860a4 100644 --- a/AKSubmission/views.py +++ b/AKSubmission/views.py @@ -13,10 +13,20 @@ from AKModel.views import FilterByEventSlugMixin from AKSubmission.forms import AKWishForm, AKOwnerForm, AKEditForm, AKSubmissionForm, AKDurationForm -class SubmissionOverviewView(FilterByEventSlugMixin, ListView): +class AKOverviewView(FilterByEventSlugMixin, ListView): model = AKCategory context_object_name = "categories" - template_name = "AKSubmission/submission_overview.html" + template_name = "AKSubmission/ak_overview.html" + wishes_as_category = False + + def filter_aks(self, context, category): + return category.ak_set.all() + + def get_active_category_name(self, context): + return context["categories_with_aks"][0][0].name + + def get_table_title(self, context): + return _("All AKs") def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) @@ -27,17 +37,35 @@ class SubmissionOverviewView(FilterByEventSlugMixin, ListView): for category in context["categories"]: aks_for_category = [] - for ak in category.ak_set.all(): - if settings.WISHES_AS_CATEGORY and ak.wish: + for ak in self.filter_aks(context, category): + if self.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: + if self.wishes_as_category: categories_with_aks.append( ({"name": _("Wishes"), "pk": "wish", "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) + context['table_title'] = self.get_table_title(context) + + return context + + +class SubmissionOverviewView(AKOverviewView): + model = AKCategory + context_object_name = "categories" + template_name = "AKSubmission/submission_overview.html" + wishes_as_category = settings.WISHES_AS_CATEGORY + + def get_table_title(self, context): + return _("Currently planned AKs") + + def get_context_data(self, *, object_list=None, **kwargs): + context = super().get_context_data(object_list=object_list, **kwargs) # Get list of existing owners for event (for AK submission start) context["existingOwners"] = AKOwner.objects.filter(event=self.event) @@ -45,6 +73,39 @@ class SubmissionOverviewView(FilterByEventSlugMixin, ListView): return context +class AKListByCategoryView(AKOverviewView): + def dispatch(self, request, *args, **kwargs): + self.category = get_object_or_404(AKCategory, pk=kwargs['category_pk']) + return super().dispatch(request, *args, **kwargs) + + def get_active_category_name(self, context): + return self.category.name + + +class AKListByTagView(AKOverviewView): + def dispatch(self, request, *args, **kwargs): + self.tag = get_object_or_404(AKTag, pk=kwargs['tag_pk']) + return super().dispatch(request, *args, **kwargs) + + def filter_aks(self, context, category): + return self.tag.ak_set.filter(event=self.event, category=category) + + def get_table_title(self, context): + return f"{_('AKs with Tag')} = {self.tag.name}" + + +class AKListByTrackView(AKOverviewView): + def dispatch(self, request, *args, **kwargs): + self.track = get_object_or_404(AKTrack, pk=kwargs['track_pk']) + return super().dispatch(request, *args, **kwargs) + + def filter_aks(self, context, category): + return category.ak_set.filter(track=self.track) + + def get_table_title(self, context): + return f"{_('AKs with Track')} = {self.track.name}" + + class AKDetailView(EventSlugMixin, DetailView): model = AK context_object_name = "ak" @@ -60,56 +121,16 @@ class AKHistoryView(EventSlugMixin, DetailView): class AKListView(FilterByEventSlugMixin, ListView): model = AK context_object_name = "AKs" - template_name = "AKSubmission/ak_list.html" - filter_condition_string = "" + template_name = "AKSubmission/ak_overview.html" + table_title = "" def get_context_data(self, *, object_list=None, **kwargs): context = super().get_context_data(object_list=object_list, **kwargs) context['categories'] = AKCategory.objects.filter(event=self.event) context['tracks'] = AKTrack.objects.filter(event=self.event) - context['filter_condition_string'] = self.filter_condition_string return context -class AKListByCategoryView(AKListView): - category = None - - def get_queryset(self): - # Find category based on event slug - try: - self.category = AKCategory.objects.get(pk=self.kwargs['category_pk']) - self.filter_condition_string = f"{_('Category')} = {self.category.name}" - except AKCategory.DoesNotExist: - raise Http404 - return super().get_queryset().filter(category=self.category) - - -class AKListByTagView(AKListView): - tag = None - - def get_queryset(self): - # Find tag based on event slug - try: - self.tag = AKTag.objects.get(pk=self.kwargs['tag_pk']) - self.filter_condition_string = f"{_('Tag')} = {self.tag.name}" - except AKTag.DoesNotExist: - raise Http404 - return super().get_queryset().filter(tags=self.tag) - - -class AKListByTrackView(AKListView): - track = None - - def get_queryset(self): - # Find track based on event slug - try: - self.track = AKTrack.objects.get(pk=self.kwargs['track_pk']) - self.filter_condition_string = f"{_('Track')} = {self.track.name}" - except AKTrack.DoesNotExist: - raise Http404 - return super().get_queryset().filter(track=self.track) - - class EventInactiveRedirectMixin: def get_error_message(self): return _("Event inactive. Cannot create or update.")