From d91e1e607ab8a3be167041ff4fa7b163cfde09a0 Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Thu, 25 May 2023 17:08:58 +0200 Subject: [PATCH] add helper feedback --- shiftregister/feedback/__init__.py | 0 shiftregister/feedback/admin.py | 3 ++ shiftregister/feedback/apps.py | 6 +++ shiftregister/feedback/forms.py | 20 +++++++++ .../feedback/migrations/0001_initial.py | 43 +++++++++++++++++++ shiftregister/feedback/migrations/__init__.py | 0 shiftregister/feedback/models.py | 19 ++++++++ .../feedback/templates/feedback.html | 31 +++++++++++++ shiftregister/feedback/tests.py | 3 ++ shiftregister/feedback/urls.py | 11 +++++ shiftregister/feedback/views.py | 34 +++++++++++++++ shiftregister/settings.py | 1 + shiftregister/team/views.py | 23 +++++----- shiftregister/urls.py | 1 + 14 files changed, 184 insertions(+), 11 deletions(-) create mode 100644 shiftregister/feedback/__init__.py create mode 100644 shiftregister/feedback/admin.py create mode 100644 shiftregister/feedback/apps.py create mode 100644 shiftregister/feedback/forms.py create mode 100644 shiftregister/feedback/migrations/0001_initial.py create mode 100644 shiftregister/feedback/migrations/__init__.py create mode 100644 shiftregister/feedback/models.py create mode 100644 shiftregister/feedback/templates/feedback.html create mode 100644 shiftregister/feedback/tests.py create mode 100644 shiftregister/feedback/urls.py create mode 100644 shiftregister/feedback/views.py diff --git a/shiftregister/feedback/__init__.py b/shiftregister/feedback/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shiftregister/feedback/admin.py b/shiftregister/feedback/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/shiftregister/feedback/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/shiftregister/feedback/apps.py b/shiftregister/feedback/apps.py new file mode 100644 index 0000000..ffdf1c3 --- /dev/null +++ b/shiftregister/feedback/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class FeedbackConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "shiftregister.feedback" diff --git a/shiftregister/feedback/forms.py b/shiftregister/feedback/forms.py new file mode 100644 index 0000000..aaa3757 --- /dev/null +++ b/shiftregister/feedback/forms.py @@ -0,0 +1,20 @@ +from .models import Feedback +from django.forms import ModelForm +from django import forms + + +class FeedbackForm(ModelForm): + class Meta: + model = Feedback + fields = ("party", "next_year", "feedback_text") + labels = { + "party": "Kommst du zum HelferInnen Fest?", + "feedback_text": "Wie wars?", + "next_year": "Dürfen wir dich nächstes Jahr wieder kontaktieren?", + } + help_texts = { + "feedback_text": "Was hat dir gefallen? Was hat geklappt? Was können wir naechstes Jahr besser machen?", + } + widgets = { + "party": forms.RadioSelect, + } diff --git a/shiftregister/feedback/migrations/0001_initial.py b/shiftregister/feedback/migrations/0001_initial.py new file mode 100644 index 0000000..052872a --- /dev/null +++ b/shiftregister/feedback/migrations/0001_initial.py @@ -0,0 +1,43 @@ +# Generated by Django 4.0.4 on 2023-05-25 14:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ("app", "0011_room_description"), + ] + + operations = [ + migrations.CreateModel( + name="Feedback", + fields=[ + ( + "helper", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + primary_key=True, + serialize=False, + to="app.helper", + ), + ), + ( + "party", + models.CharField( + choices=[ + ("yes", "ja"), + ("no", "nein"), + ("maybe", "vielleicht"), + ], + max_length=7, + ), + ), + ("next_year", models.BooleanField()), + ("feedback_text", models.TextField(blank=True, default="")), + ], + ), + ] diff --git a/shiftregister/feedback/migrations/__init__.py b/shiftregister/feedback/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/shiftregister/feedback/models.py b/shiftregister/feedback/models.py new file mode 100644 index 0000000..e575e1c --- /dev/null +++ b/shiftregister/feedback/models.py @@ -0,0 +1,19 @@ +from django.db import models +from shiftregister.app.models import Helper + + +class Feedback(models.Model): + helper = models.OneToOneField(Helper, primary_key=True, on_delete=models.CASCADE) + + class PartyState(models.TextChoices): + YES = "yes", "ja" + NO = "no", "nein" + MAYBE = "maybe", "vielleicht" + + party = models.CharField( + max_length=7, + choices=PartyState.choices, + blank=False, + ) + next_year = models.BooleanField() + feedback_text = models.TextField(blank=True, default="") diff --git a/shiftregister/feedback/templates/feedback.html b/shiftregister/feedback/templates/feedback.html new file mode 100644 index 0000000..67491b7 --- /dev/null +++ b/shiftregister/feedback/templates/feedback.html @@ -0,0 +1,31 @@ + +{% extends "helper_base.html" %} + +{% block title %}Danke :){% endblock %} + +{% block content %} +
+ {% csrf_token %} +{% for field in form %} +
+{% if field.widget_type == 'checkbox' %} +
+ +
+{% else %} + +
+ {{ field }} +
+{% endif %} +{% for error in field.errors %} +

{{ error }}

+{% endfor %} +{% if field.help_text %} +

{{ field.help_text }}

+{% endif %} +
+{% endfor %} + +
+{% endblock %} diff --git a/shiftregister/feedback/tests.py b/shiftregister/feedback/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/shiftregister/feedback/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/shiftregister/feedback/urls.py b/shiftregister/feedback/urls.py new file mode 100644 index 0000000..cf252c8 --- /dev/null +++ b/shiftregister/feedback/urls.py @@ -0,0 +1,11 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path( + "f/", + views.feedback, + name="feedback", + ), +] diff --git a/shiftregister/feedback/views.py b/shiftregister/feedback/views.py new file mode 100644 index 0000000..8058ddb --- /dev/null +++ b/shiftregister/feedback/views.py @@ -0,0 +1,34 @@ +from django.shortcuts import render, get_object_or_404 +from .forms import FeedbackForm +from .models import Feedback +from shiftregister.app.models import LoginToken +from django.contrib import messages + + +def feedback(request, token): + tk = get_object_or_404(LoginToken, pk=token) + helper = tk.helper + form = FeedbackForm() + prev_data = Feedback.objects.filter(helper=helper).first() + if prev_data: + form = FeedbackForm(instance=prev_data) + if request.method == "POST": + form = FeedbackForm(request.POST) + if form.is_valid(): + obj = form.save(commit=False) + obj.helper = helper + obj.save() + messages.add_message( + request, + messages.SUCCESS, + "Deine Angaben wurden gespeichert.", + ) + + return render( + request, + "feedback.html", + { + "form": form, + "helper": helper, + }, + ) diff --git a/shiftregister/settings.py b/shiftregister/settings.py index 73d177b..e20336c 100644 --- a/shiftregister/settings.py +++ b/shiftregister/settings.py @@ -47,6 +47,7 @@ INSTALLED_APPS = [ "shiftregister.pages.apps.PagesConfig", "shiftregister.signage.apps.SignageConfig", "shiftregister.team.apps.TeamConfig", + "shiftregister.feedback.apps.FeedbackConfig", "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index 810738c..ff2721d 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -146,18 +146,19 @@ def bulk_message(request): ).filter(number_validated=True, shift_count__gte=1) try: - Message.objects.bulk_create( - ( - Message( - text=form.cleaned_data["message"].replace( - "$token", - f"https://helfen.kntkt.de{helper.logintoken_set.first().get_absolute_url()}", - ), - to=helper, - ) - for helper in helpers + outbox = [] + for helper in helpers: + text = form.cleaned_data["message"].replace( + "$token", + f"https://helfen.kntkt.de{helper.logintoken_set.first().get_absolute_url()}", ) - ) + text = text.replace( + "$fb", + f"https://helfen.kntkt.de/f/{helper.logintoken_set.first().id}", + ) + outbox.append(Message(text=text, to=helper)) + + Message.objects.bulk_create(outbox) messages.add_message( request, messages.SUCCESS, "Massen-Nachricht erfolgreich versendet" ) diff --git a/shiftregister/urls.py b/shiftregister/urls.py index 8007fd4..ac76b85 100644 --- a/shiftregister/urls.py +++ b/shiftregister/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ path("", include("shiftregister.metrics.urls")), path("", include("shiftregister.app.urls")), path("", include("shiftregister.pages.urls")), + path("", include("shiftregister.feedback.urls")), path("team/", include("shiftregister.team.urls")), path("team/", include("shiftregister.fallback.urls")), path("dashboard/", include("shiftregister.signage.urls")),