2
0
Fork 0

Add frontend helper feedback view

This commit is contained in:
Luca 2023-05-27 20:35:34 +02:00
parent 3d3686cec2
commit fc22cc4491
9 changed files with 131 additions and 8 deletions

View File

@ -1,6 +1,6 @@
from django.contrib import admin
from .models import Feedback
from .models import Feedback, ShareToken
@admin.register(Feedback)
@ -12,3 +12,13 @@ class FeedbackAdmin(admin.ModelAdmin):
def feedback_len(self, obj):
return len(obj.feedback_text)
@admin.register(ShareToken)
class ShareTokenAdmin(admin.ModelAdmin):
list_display = ("name", "url")
ordering = ("name",)
readonly_fields = ("token", "url")
def url(self, obj):
return f"https://helfen.kntkt.de/feedback/{obj.token}"

View File

@ -4,3 +4,6 @@ from django.apps import AppConfig
class FeedbackConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "shiftregister.feedback"
def ready(self):
from . import signals

View File

@ -0,0 +1,28 @@
# Generated by Django 4.0.4 on 2023-05-27 17:48
from django.db import migrations, models
import secrets
class Migration(migrations.Migration):
dependencies = [
("feedback", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="ShareToken",
fields=[
(
"token",
models.CharField(
default=secrets.token_urlsafe,
max_length=43,
primary_key=True,
serialize=False,
),
),
("name", models.CharField(max_length=200)),
],
),
]

View File

@ -1,4 +1,5 @@
from django.db import models
from secrets import token_urlsafe
from shiftregister.app.models import Helper
@ -19,3 +20,16 @@ class Feedback(models.Model):
def __str__(self):
return f"Feedback by {self.helper.name}"
def color(self):
return {"yes": "is-success", "no": "is-danger", "maybe": "is-warning"}[
self.party
]
class ShareToken(models.Model):
token = models.CharField(max_length=43, default=token_urlsafe, primary_key=True)
name = models.CharField(max_length=200)
def __str__(self):
return self.name

View File

@ -0,0 +1,20 @@
from django.dispatch import receiver
from django.shortcuts import reverse
from dynamic_preferences.registries import global_preferences_registry
from shiftregister.core.signals import populate_nav
global_preferences = global_preferences_registry.manager()
@receiver(populate_nav, dispatch_uid="populate_feedback_nav")
def populate_feedback_nav(sender, **kwargs):
request = sender
nav_items = []
if (
global_preferences["helper__event_state"] == "AFTER"
and request.user.is_authenticated
):
nav_items.append({"link": reverse("submissions"), "text": "Feedback"})
return nav_items

View File

@ -0,0 +1,22 @@
{% extends "base.html" %}
{% block title %}Feedback{% endblock %}
{% block content %}
<h3 class="title">Feedback von Helfer*innen</h3>
<div class="content is-flex">
Zum Helfer*innenfest angemeldet:&nbsp;
<div class="tags">
<span class="tag is-success">ja</span>
<span class="tag is-danger">nein</span>
<span class="tag is-warning">vielleicht</span>
</div>
</div>
{% for feedback in submissions %}
<div class="message message-{% cycle 'incoming' 'outgoing' %} {{ feedback.color }}">
<div class="message-body">
{{ feedback.feedback_text }}
</div>
</div>
{% endfor %}
{% endblock %}

View File

@ -8,4 +8,10 @@ urlpatterns = [
views.feedback,
name="feedback",
),
path("feedback/", views.feedback_submissions, name="submissions"),
path(
"feedback/<slug:token>",
views.feedback_submissions_shared,
name="submissions_shared",
),
]

View File

@ -1,8 +1,9 @@
from django.shortcuts import render, get_object_or_404
from .forms import FeedbackForm
from .models import Feedback
from .models import Feedback, ShareToken
from shiftregister.app.models import LoginToken
from django.contrib import messages
from django.contrib.auth.decorators import login_required
def feedback(request, token):
@ -29,3 +30,16 @@ def feedback(request, token):
)
return render(request, "feedback.html", {"form": form})
@login_required
def feedback_submissions(request):
submissions = Feedback.objects.exclude(feedback_text="")
return render(request, "submissions.html", {"submissions": submissions})
def feedback_submissions_shared(request, token):
token = get_object_or_404(ShareToken, pk=token)
submissions = Feedback.objects.exclude(feedback_text="")
return render(request, "submissions.html", {"submissions": submissions})

View File

@ -1,19 +1,25 @@
from django.dispatch import receiver
from django.shortcuts import reverse
from dynamic_preferences.registries import global_preferences_registry
from shiftregister.core.signals import populate_nav
from .models import IncomingMessage
global_preferences = global_preferences_registry.manager()
@receiver(populate_nav, dispatch_uid="populate_team_nav")
def populate_team_nav(sender, **kwargs):
request = sender
nav_items = []
is_not_over = global_preferences["helper__event_state"] != "AFTER"
if request.user.is_authenticated:
if is_not_over:
nav_items.append(
{"link": reverse("team:shift_overview"), "text": "Schichtübersicht"}
)
nav_items.append({"link": reverse("team:checkins"), "text": "Checkin"})
if is_not_over:
nav_items.append(
{"link": reverse("team:shift_free"), "text": "Freie Schichten"}
)