add helper feedback
This commit is contained in:
parent
f16e6f15a5
commit
d91e1e607a
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class FeedbackConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "shiftregister.feedback"
|
|
@ -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,
|
||||||
|
}
|
|
@ -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="")),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -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="")
|
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
{% extends "helper_base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Danke :){% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<form action="" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
{% for field in form %}
|
||||||
|
<div class="field">
|
||||||
|
{% if field.widget_type == 'checkbox' %}
|
||||||
|
<div class="control">
|
||||||
|
<label class="checkbox" for="{{ field.id_for_label }}">{{ field }} {{ field.label }}</label>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<label class="label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
|
<div class="control">
|
||||||
|
{{ field }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% for error in field.errors %}
|
||||||
|
<p class="help is-danger">{{ error }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
{% if field.help_text %}
|
||||||
|
<p class="help">{{ field.help_text }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
<button class="button is-link" type="submit">Speichern</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
|
@ -0,0 +1,11 @@
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path(
|
||||||
|
"f/<slug:token>",
|
||||||
|
views.feedback,
|
||||||
|
name="feedback",
|
||||||
|
),
|
||||||
|
]
|
|
@ -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,
|
||||||
|
},
|
||||||
|
)
|
|
@ -47,6 +47,7 @@ INSTALLED_APPS = [
|
||||||
"shiftregister.pages.apps.PagesConfig",
|
"shiftregister.pages.apps.PagesConfig",
|
||||||
"shiftregister.signage.apps.SignageConfig",
|
"shiftregister.signage.apps.SignageConfig",
|
||||||
"shiftregister.team.apps.TeamConfig",
|
"shiftregister.team.apps.TeamConfig",
|
||||||
|
"shiftregister.feedback.apps.FeedbackConfig",
|
||||||
"django.contrib.admin",
|
"django.contrib.admin",
|
||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
"django.contrib.contenttypes",
|
"django.contrib.contenttypes",
|
||||||
|
|
|
@ -146,18 +146,19 @@ def bulk_message(request):
|
||||||
).filter(number_validated=True, shift_count__gte=1)
|
).filter(number_validated=True, shift_count__gte=1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
Message.objects.bulk_create(
|
outbox = []
|
||||||
(
|
for helper in helpers:
|
||||||
Message(
|
text = form.cleaned_data["message"].replace(
|
||||||
text=form.cleaned_data["message"].replace(
|
|
||||||
"$token",
|
"$token",
|
||||||
f"https://helfen.kntkt.de{helper.logintoken_set.first().get_absolute_url()}",
|
f"https://helfen.kntkt.de{helper.logintoken_set.first().get_absolute_url()}",
|
||||||
),
|
|
||||||
to=helper,
|
|
||||||
)
|
|
||||||
for helper in helpers
|
|
||||||
)
|
)
|
||||||
|
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(
|
messages.add_message(
|
||||||
request, messages.SUCCESS, "Massen-Nachricht erfolgreich versendet"
|
request, messages.SUCCESS, "Massen-Nachricht erfolgreich versendet"
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,6 +20,7 @@ urlpatterns = [
|
||||||
path("", include("shiftregister.metrics.urls")),
|
path("", include("shiftregister.metrics.urls")),
|
||||||
path("", include("shiftregister.app.urls")),
|
path("", include("shiftregister.app.urls")),
|
||||||
path("", include("shiftregister.pages.urls")),
|
path("", include("shiftregister.pages.urls")),
|
||||||
|
path("", include("shiftregister.feedback.urls")),
|
||||||
path("team/", include("shiftregister.team.urls")),
|
path("team/", include("shiftregister.team.urls")),
|
||||||
path("team/", include("shiftregister.fallback.urls")),
|
path("team/", include("shiftregister.fallback.urls")),
|
||||||
path("dashboard/", include("shiftregister.signage.urls")),
|
path("dashboard/", include("shiftregister.signage.urls")),
|
||||||
|
|
Loading…
Reference in New Issue