2
0
Fork 0

add event state dependent messages and screens

This commit is contained in:
Andreas (@xAndy) Zimmermann 2022-04-27 23:11:45 +02:00
parent 0863b8c45a
commit cad8945e25
5 changed files with 45 additions and 1 deletions

View File

@ -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

View File

@ -24,6 +24,18 @@ class SendSMS(types.BooleanPreference):
default = True 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 @global_preferences_registry.register
class ShiftReminder(types.DurationPreference): class ShiftReminder(types.DurationPreference):
section = helper section = helper

View File

@ -0,0 +1,7 @@
{% extends "helper_base.html" %}
{% block title %}Danke!{% endblock %}
{% block content %}
Das wars!<br/>
Danke für Deine Hilfe, bis zum nächsten Event.
{% endblock %}

View File

@ -0,0 +1,7 @@
{% extends "helper_base.html" %}
{% block title %}Stay Tuned!{% endblock %}
{% block content %}
Bald gehts los!<br/>
Wir schicken Dir eine SMS wenn wir freie Schichten haben.
{% endblock %}

View File

@ -8,8 +8,10 @@ from django.utils import timezone
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
import datetime import datetime
from .decorators import event_state
@event_state
def index(request): def index(request):
if request.session.get("last_seen_shift"): if request.session.get("last_seen_shift"):
del request.session["last_seen_shift"] del request.session["last_seen_shift"]
@ -26,7 +28,6 @@ def index(request):
) )
imp_shift = request.helper.important_shift() imp_shift = request.helper.important_shift()
print(imp_shift)
if imp_shift and imp_shift.is_running(): if imp_shift and imp_shift.is_running():
context["current_shift"] = imp_shift context["current_shift"] = imp_shift
@ -137,6 +138,7 @@ def register(request):
return render(request, "register.html", context) return render(request, "register.html", context)
@event_state
def shift(request, shiftid): def shift(request, shiftid):
shift = get_object_or_404(Shift, pk=shiftid) shift = get_object_or_404(Shift, pk=shiftid)
helper = request.helper helper = request.helper