diff --git a/shiftregister/app/context_processors.py b/shiftregister/app/context_processors.py new file mode 100644 index 0000000..929a670 --- /dev/null +++ b/shiftregister/app/context_processors.py @@ -0,0 +1,12 @@ +from django.conf import settings +from .models import LoginToken + +# enhance template contexts with frequently used data so we have less code duplication +def proc(request): + context = { + "DEBUG": settings.DEBUG, + } + tk = LoginToken.objects.filter(pk=request.session.get("token")).first() + if tk: + context["helper"] = tk.helper + return context diff --git a/shiftregister/app/templates/helper_base.html b/shiftregister/app/templates/helper_base.html index 76a1e7b..101099f 100644 --- a/shiftregister/app/templates/helper_base.html +++ b/shiftregister/app/templates/helper_base.html @@ -3,7 +3,9 @@ {% block title %}Help!{% endblock %} {% block navbar %} +{% if not helper%} Anmelden +{% endif %} {% endblock %} {% block body %} @@ -21,4 +23,15 @@ {% block content %}{% endblock %} -{% endblock %} + +{% if DEBUG%} + +{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/shiftregister/app/views.py b/shiftregister/app/views.py index 4cd3453..c2510a9 100644 --- a/shiftregister/app/views.py +++ b/shiftregister/app/views.py @@ -4,6 +4,8 @@ from django.db.models import F, Count, Q, ExpressionWrapper from .forms import RegisterForm, EmptyForm from django.db.models.fields import DateTimeField from django.utils import timezone +from django.conf import settings +from django.contrib import messages def index(request): @@ -15,7 +17,6 @@ def index(request): helper = None if request.session.get("token"): helper = LoginToken.objects.get(pk=request.session["token"]).helper - context["helper"] = helper context["my_shifts"] = helper.shiftregistration_set.filter( shift__start_at__gt=timezone.now() ).order_by("shift__start_at") @@ -87,6 +88,12 @@ def register(request): helper.save() token = helper.send_confirmation() request.session["token"] = token.pk + if settings.DEBUG: + messages.add_message( + request, + messages.INFO, + f"DEBUG: login token: {token.get_absolute_url()}", + ) return render(request, "wait_confirmation.html", {"helper": helper}) context["form"] = RegisterForm() return render(request, "register.html", context) diff --git a/shiftregister/settings.py b/shiftregister/settings.py index bcc5aae..ed3bf5d 100644 --- a/shiftregister/settings.py +++ b/shiftregister/settings.py @@ -67,6 +67,7 @@ TEMPLATES = [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", + "shiftregister.app.context_processors.proc", ], }, }, diff --git a/templates/base.html b/templates/base.html index 5041a69..0a6fe2b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -18,6 +18,13 @@ + {% for message in messages %} +
+ + {{ message }} +
+ {% endfor %} + {% block body %} {% endblock %}