diff --git a/haugebot/urls.py b/haugebot/urls.py index e291df7d2f96ead486c3ff170a3a5318a7d59c99..3859164f76c55daee20e71d67a035569b1d1b874 100644 --- a/haugebot/urls.py +++ b/haugebot/urls.py @@ -31,6 +31,7 @@ urlpatterns = [ path('wusstest_du_schon/edit/<int:text_id>', views.wusstest_du_schon_edit, name="wusstest_du_schon_edit"), path('wusstest_du_schon/active', views.wusstest_du_schon_active, name="wusstest_du_schon_active"), path('wusstest_du_schon/remove', views.wusstest_du_schon_remove, name="wusstest_du_schon_remove"), + path('whispers', views.whispers, name="whispers"), path('wordcloud/', views.wordcloud, name="wordcloud"), path('wordcloud/live/<str:id>', views.wordcloud_live, name="wordcloud_live") ] diff --git a/haugebot_web/migrations/0007_whisper.py b/haugebot_web/migrations/0007_whisper.py index b88acf1593527fbd5de47fb1e1d9c4284f6efe5f..1b0da07f2ff4bb3e2c415007c2a721ccb15c17ac 100644 --- a/haugebot_web/migrations/0007_whisper.py +++ b/haugebot_web/migrations/0007_whisper.py @@ -1,6 +1,5 @@ # Generated by Django 3.2.10 on 2021-12-22 09:49 -import datetime from django.db import migrations, models import django diff --git a/haugebot_web/templates/layout.html b/haugebot_web/templates/layout.html index 34fcd7d85874404a800b8e91e185dc8d54d2b50e..8b61690ff1c70ddc3eea5456e389ceab8d255c82 100644 --- a/haugebot_web/templates/layout.html +++ b/haugebot_web/templates/layout.html @@ -21,6 +21,8 @@ Schon?</a> <a href="{% url 'wordcloud' %}" class="w3-bar-item w3-button {% if title == "Wordcloud" %}w3-light-gray{% endif %}">Wordcloud</a> + <a href="{% url 'whispers' %}" + class="w3-bar-item w3-button {% if title == "Geflüster" %}w3-light-gray{% endif %}">Geflüster</a> <a href="{% url 'logout' %}" class="w3-bar-item w3-button">Logout</a> {% else %} <a href="{% url 'login' %}" class="w3-bar-item w3-button">Login</a> diff --git a/haugebot_web/templates/list_whispers.html b/haugebot_web/templates/list_whispers.html new file mode 100644 index 0000000000000000000000000000000000000000..3af46fdc503ba0fa76020968f18df94f58963d80 --- /dev/null +++ b/haugebot_web/templates/list_whispers.html @@ -0,0 +1,25 @@ +{% extends 'layout.html' %} + +{% block content %} +{% csrf_token %} +<div class="w3-card w3-white"> + <div class="w3-padding"> + <table class="w3-table w3-striped"> + <tbody> + <tr> + <th>Autor</th> + <th>Nachricht</th> + <th>Gesendet um</th> + </tr> + {% for whisper in whispers %} + <tr> + <td>{{ whisper.author }}</td> + <td>{{ whisper.content }}</td> + <td>{{ whisper.received_at | date:"d.m.Y G:i:s"}}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> +</div> +{% endblock %} \ No newline at end of file diff --git a/haugebot_web/views.py b/haugebot_web/views.py index 2031a8ef4ee13b991c9ad076f1970426d93de0ee..6befda5588da42ca52e24097badbdec9fd1f224f 100644 --- a/haugebot_web/views.py +++ b/haugebot_web/views.py @@ -4,13 +4,13 @@ import json import requests from django.contrib.auth import authenticate, login as django_login, logout as django_logout from django.contrib.auth.decorators import login_required -from django.forms import modelformset_factory, modelform_factory +from django.forms import modelform_factory from django.shortcuts import render, redirect, get_object_or_404 from django.urls import reverse from django.http import Http404, JsonResponse, HttpResponse, HttpRequest from .forms import BaseForm -from .models import WusstestDuSchon, Setting +from .models import WusstestDuSchon, Setting, Whisper # Create your views here. @@ -171,3 +171,9 @@ def wusstest_du_schon_remove(request): raise Http404 # </editor-fold> + +@login_required(login_url="/login") +def whispers(request): + whisper_messages = Whisper.objects.all().order_by("-received_at") + + return render(request, "list_whispers.html", {'title': 'Geflüster', "whispers": whisper_messages})