From cad8945e2599e7daa47500058bb598f699d59208 Mon Sep 17 00:00:00 2001 From: "Andreas (@xAndy) Zimmermann" Date: Wed, 27 Apr 2022 23:11:45 +0200 Subject: [PATCH] add event state dependent messages and screens --- shiftregister/app/decorators.py | 16 ++++++++++++++++ .../app/dynamic_preferences_registry.py | 12 ++++++++++++ shiftregister/app/templates/event_after.html | 7 +++++++ shiftregister/app/templates/event_before.html | 7 +++++++ shiftregister/app/views.py | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 shiftregister/app/decorators.py create mode 100644 shiftregister/app/templates/event_after.html create mode 100644 shiftregister/app/templates/event_before.html diff --git a/shiftregister/app/decorators.py b/shiftregister/app/decorators.py new file mode 100644 index 0000000..71b34de --- /dev/null +++ b/shiftregister/app/decorators.py @@ -0,0 +1,16 @@ +from django.shortcuts import render +from dynamic_preferences.registries import global_preferences_registry + + +def event_state(view): + global_preferences = global_preferences_registry.manager() + + def wrapped(request, *args, **kwargs): + state = global_preferences["helper__event_state"] + if state == "RUNNING": + return view(request, *args, **kwargs) + if state == "BEFORE": + return render(request, "event_before.html", {}) + return render(request, "event_after.html", {}) + + return wrapped diff --git a/shiftregister/app/dynamic_preferences_registry.py b/shiftregister/app/dynamic_preferences_registry.py index 456a121..0f80a2d 100644 --- a/shiftregister/app/dynamic_preferences_registry.py +++ b/shiftregister/app/dynamic_preferences_registry.py @@ -24,6 +24,18 @@ class SendSMS(types.BooleanPreference): default = True +@global_preferences_registry.register +class EventState(types.ChoicePreference): + section = helper + name = "event_state" + choices = [ + ("BEFORE", "before event"), + ("RUNNING", "event is running"), + ("AFTER", "event is over"), + ] + default = "BEFORE" + + @global_preferences_registry.register class ShiftReminder(types.DurationPreference): section = helper diff --git a/shiftregister/app/templates/event_after.html b/shiftregister/app/templates/event_after.html new file mode 100644 index 0000000..a0df78f --- /dev/null +++ b/shiftregister/app/templates/event_after.html @@ -0,0 +1,7 @@ +{% extends "helper_base.html" %} + +{% block title %}Danke!{% endblock %} +{% block content %} +Das wars!
+Danke für Deine Hilfe, bis zum nächsten Event. +{% endblock %} diff --git a/shiftregister/app/templates/event_before.html b/shiftregister/app/templates/event_before.html new file mode 100644 index 0000000..1b72bfd --- /dev/null +++ b/shiftregister/app/templates/event_before.html @@ -0,0 +1,7 @@ +{% extends "helper_base.html" %} + +{% block title %}Stay Tuned!{% endblock %} +{% block content %} +Bald gehts los!
+Wir schicken Dir eine SMS wenn wir freie Schichten haben. +{% endblock %} diff --git a/shiftregister/app/views.py b/shiftregister/app/views.py index 0a97207..ec9415d 100644 --- a/shiftregister/app/views.py +++ b/shiftregister/app/views.py @@ -8,8 +8,10 @@ from django.utils import timezone from django.conf import settings from django.contrib import messages import datetime +from .decorators import event_state +@event_state def index(request): if request.session.get("last_seen_shift"): del request.session["last_seen_shift"] @@ -26,7 +28,6 @@ def index(request): ) imp_shift = request.helper.important_shift() - print(imp_shift) if imp_shift and imp_shift.is_running(): context["current_shift"] = imp_shift @@ -137,6 +138,7 @@ def register(request): return render(request, "register.html", context) +@event_state def shift(request, shiftid): shift = get_object_or_404(Shift, pk=shiftid) helper = request.helper