From 18ea80024b32cafce54fb67fbe503b05ed7c81b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?N=2EGeisler=20=26=20B=2E=20H=C3=A4ttasch?= <ak@kif.rocks>
Date: Thu, 9 Jan 2020 01:11:56 +0100
Subject: [PATCH] create first version of dashboard

deploy dashboard under /
create template view
provide template with important links for each event
handle case of no events
create template tag to ensure installed apps
---
 .../locale/de_DE/LC_MESSAGES/django.po        | 42 ++++++++++++
 AKDashboard/static/AKDashboard/style.css      | 29 +++++++++
 .../templates/AKDashboard/dashboard.html      | 65 +++++++++++++++++++
 AKDashboard/urls.py                           |  2 +-
 AKDashboard/views.py                          | 20 ++++--
 AKModel/templatetags/tags_AKModel.py          |  7 ++
 AKPlanning/settings.py                        |  5 +-
 7 files changed, 159 insertions(+), 11 deletions(-)
 create mode 100644 AKDashboard/locale/de_DE/LC_MESSAGES/django.po
 create mode 100644 AKDashboard/static/AKDashboard/style.css
 create mode 100644 AKDashboard/templates/AKDashboard/dashboard.html

diff --git a/AKDashboard/locale/de_DE/LC_MESSAGES/django.po b/AKDashboard/locale/de_DE/LC_MESSAGES/django.po
new file mode 100644
index 00000000..e292f2be
--- /dev/null
+++ b/AKDashboard/locale/de_DE/LC_MESSAGES/django.po
@@ -0,0 +1,42 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2020-01-09 00:07+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: templates/AKDashboard/dashboard.html:31
+msgid "Current AKs"
+msgstr "Aktuelle AKs"
+
+#: templates/AKDashboard/dashboard.html:36
+msgid "AK Wall"
+msgstr "AK-Wall"
+
+#: templates/AKDashboard/dashboard.html:44
+msgid "AK Submission"
+msgstr "AK-Submission"
+
+#: templates/AKDashboard/dashboard.html:51
+msgid "Write to organizers of this event for questions and comments"
+msgstr "Kontaktiere die Organisator*innen des Events bei Fragen oder Kommentaren"
+
+#: templates/AKDashboard/dashboard.html:58
+msgid "Currently, there are no Events!"
+msgstr "Aktuell gibt es keine Events!"
+
+#: templates/AKDashboard/dashboard.html:61
+msgid "Please contact an administrator if you want to use AKPlanning."
+msgstr "Bitte kontaktiere eine*n Administrator*in, falls du AKPlanning verwenden möchtest."
diff --git a/AKDashboard/static/AKDashboard/style.css b/AKDashboard/static/AKDashboard/style.css
new file mode 100644
index 00000000..4cb50650
--- /dev/null
+++ b/AKDashboard/static/AKDashboard/style.css
@@ -0,0 +1,29 @@
+.dashboard-row {
+    margin-bottom: 5em;
+}
+
+.dashboard-row > .row {
+    margin-left: 0;
+    padding-bottom: 1em;
+}
+
+.dashboard-box .fa {
+    font-size: 26pt;
+}
+
+.dashboard-box span.text {
+    display: block;
+    padding-top: 10px;
+    font-size: 12pt;
+}
+
+.dashboard-box {
+    display: block;
+    padding: 2em;
+
+}
+
+.dashboard-button {
+    display: inline;
+    padding: 0;
+}
diff --git a/AKDashboard/templates/AKDashboard/dashboard.html b/AKDashboard/templates/AKDashboard/dashboard.html
new file mode 100644
index 00000000..0c4399ba
--- /dev/null
+++ b/AKDashboard/templates/AKDashboard/dashboard.html
@@ -0,0 +1,65 @@
+{% extends 'base.html' %}
+
+{% load fontawesome %}
+{% load i18n %}
+{% load static %}
+{% load tags_AKModel %}
+
+{% block imports %}
+
+    {{ block.super }}
+
+    <link rel="stylesheet" href="{% static 'AKDashboard/style.css' %}">
+
+{% endblock %}
+
+{% block breadcrumbs %}
+    <li class="breadcrumb-item">AKPlanning</li>
+{% endblock %}
+
+{% block content %}
+    {% for event in events %}
+        <div class="dashboard-row">
+            <h2> {{ event.name }} </h2>
+            <div class="row">
+                {% if 'AKPlan'|check_app_installed %}
+
+                    <a class="Color-Default"
+                       href="{% url 'plan:ak_plan_current_next' event_slug=event.slug %}">
+                        <div class="col-sm-12 col-md-3 col-lg-2 dashboard-button"><span
+                                class="fa fa-list-ul"></span> <span
+                                class='text'>{% trans 'Current AKs' %}</span></div>
+                    </a>
+                    <a class="Color-Default"
+                       href="{% url 'plan:ak_plan_timeline' event_slug=event.slug %}">
+                        <div class="col-sm-12 col-md-3 col-lg-2 dashboard-button"><span
+                                class="fa fa-calendar"></span> <span class='text'>{% trans "AK Wall" %}</span></div>
+                    </a>
+                {% endif %}
+                {% if 'AKSubmission'|check_app_installed %}
+                    <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"><span
+                                class="fa fa-pencil-alt"></span> <span
+                                class='text'>{% trans 'AK Submission' %}</span></div>
+                    </a>
+
+                {% endif %}
+            </div>
+            {% if event.contact_email %}
+                <p>
+                    <a href="mailto:{{ event.contact_email }}">{% fontawesome_icon "envelope" %} {% trans "Write to organizers of this event for questions and comments" %}</a>
+                </p>
+            {% endif %}
+        </div>
+    {% empty %}
+        <div class="jumbotron">
+            <h2 class="display-4">
+                {% trans 'Currently, there are no Events!' %}
+            </h2>
+            <p class="lead">
+                {% trans 'Please contact an administrator if you want to use AKPlanning.' %}
+            </p>
+        </div>
+    {% endfor %}
+{% endblock %}
\ No newline at end of file
diff --git a/AKDashboard/urls.py b/AKDashboard/urls.py
index b920578c..24497d30 100644
--- a/AKDashboard/urls.py
+++ b/AKDashboard/urls.py
@@ -5,5 +5,5 @@ from AKDashboard import views
 app_name = "dashboard"
 
 urlpatterns = [
-    path('', views.TopLevelRedirectView.as_view(), name='top_level_redirect'),
+    path('', views.DashboardView.as_view(), name="dashboard"),
 ]
diff --git a/AKDashboard/views.py b/AKDashboard/views.py
index 14660a24..6d870680 100644
--- a/AKDashboard/views.py
+++ b/AKDashboard/views.py
@@ -1,12 +1,18 @@
-from django.urls import reverse_lazy
-from django.views.generic import RedirectView
+from django.utils.decorators import method_decorator
+from django.views.decorators.csrf import ensure_csrf_cookie
+from django.views.generic import TemplateView
 
 from AKModel.models import Event
 
 
-class TopLevelRedirectView(RedirectView):
-    is_permanent = False
+class DashboardView(TemplateView):
+    template_name = 'AKDashboard/dashboard.html'
 
-    def get_redirect_url(self, *args, **kwargs):
-        return reverse_lazy('submit:submission_overview',
-                       kwargs={'event_slug': Event.objects.filter(active=True).last().slug})
+    @method_decorator(ensure_csrf_cookie)
+    def dispatch(self, *args, **kwargs):
+        return super().dispatch(*args, **kwargs)
+
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context['events'] = Event.objects.all()
+        return context
diff --git a/AKModel/templatetags/tags_AKModel.py b/AKModel/templatetags/tags_AKModel.py
index 4c154816..4540e859 100644
--- a/AKModel/templatetags/tags_AKModel.py
+++ b/AKModel/templatetags/tags_AKModel.py
@@ -1,9 +1,16 @@
 from django import template
+from django.apps import apps
 from django.conf import settings
 
 register = template.Library()
 
+
 # Get Footer Info from settings
 @register.simple_tag
 def footer_info():
     return settings.FOOTER_INFO
+
+
+@register.filter
+def check_app_installed(name):
+    return apps.is_installed(name)
diff --git a/AKPlanning/settings.py b/AKPlanning/settings.py
index ae81292a..4d10d860 100644
--- a/AKPlanning/settings.py
+++ b/AKPlanning/settings.py
@@ -11,9 +11,8 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
 """
 
 import os
-from django.utils.translation import gettext_lazy as _
-
 
+from django.utils.translation import gettext_lazy as _
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 from split_settings.tools import optional, include
 
@@ -37,7 +36,7 @@ INSTALLED_APPS = [
     'AKDashboard.apps.AkdashboardConfig',
     'AKSubmission.apps.AksubmissionConfig',
     'AKScheduling.apps.AkschedulingConfig',
-    'AKPlan.apps.AkplanConfig',
+    # 'AKPlan.apps.AkplanConfig',
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
-- 
GitLab