add messages and debug links
This commit is contained in:
parent
7d2426cc2c
commit
14e18e9f2e
|
@ -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
|
|
@ -3,7 +3,9 @@
|
||||||
{% block title %}Help!{% endblock %}
|
{% block title %}Help!{% endblock %}
|
||||||
|
|
||||||
{% block navbar %}
|
{% block navbar %}
|
||||||
|
{% if not helper%}
|
||||||
<a class="navbar-item" href="{% url 'register' %}">Anmelden</a>
|
<a class="navbar-item" href="{% url 'register' %}">Anmelden</a>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
|
@ -21,4 +23,15 @@
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
{% if DEBUG%}
|
||||||
|
<footer class="footer">
|
||||||
|
Debug Mode:
|
||||||
|
{% if helper %}
|
||||||
|
<a href="{% url 'token_logout' %}">logout</a>
|
||||||
|
<a href="{{ helper.logintoken_set.first.get_absolute_url }}">login url</a>
|
||||||
|
{% endif %}
|
||||||
|
</footer>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -4,6 +4,8 @@ from django.db.models import F, Count, Q, ExpressionWrapper
|
||||||
from .forms import RegisterForm, EmptyForm
|
from .forms import RegisterForm, EmptyForm
|
||||||
from django.db.models.fields import DateTimeField
|
from django.db.models.fields import DateTimeField
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
|
@ -15,7 +17,6 @@ def index(request):
|
||||||
helper = None
|
helper = None
|
||||||
if request.session.get("token"):
|
if request.session.get("token"):
|
||||||
helper = LoginToken.objects.get(pk=request.session["token"]).helper
|
helper = LoginToken.objects.get(pk=request.session["token"]).helper
|
||||||
context["helper"] = helper
|
|
||||||
context["my_shifts"] = helper.shiftregistration_set.filter(
|
context["my_shifts"] = helper.shiftregistration_set.filter(
|
||||||
shift__start_at__gt=timezone.now()
|
shift__start_at__gt=timezone.now()
|
||||||
).order_by("shift__start_at")
|
).order_by("shift__start_at")
|
||||||
|
@ -87,6 +88,12 @@ def register(request):
|
||||||
helper.save()
|
helper.save()
|
||||||
token = helper.send_confirmation()
|
token = helper.send_confirmation()
|
||||||
request.session["token"] = token.pk
|
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})
|
return render(request, "wait_confirmation.html", {"helper": helper})
|
||||||
context["form"] = RegisterForm()
|
context["form"] = RegisterForm()
|
||||||
return render(request, "register.html", context)
|
return render(request, "register.html", context)
|
||||||
|
|
|
@ -67,6 +67,7 @@ TEMPLATES = [
|
||||||
"django.template.context_processors.request",
|
"django.template.context_processors.request",
|
||||||
"django.contrib.auth.context_processors.auth",
|
"django.contrib.auth.context_processors.auth",
|
||||||
"django.contrib.messages.context_processors.messages",
|
"django.contrib.messages.context_processors.messages",
|
||||||
|
"shiftregister.app.context_processors.proc",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,6 +18,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
{% for message in messages %}
|
||||||
|
<div class="notification {% for tag in message.tags.split %} is-{{ tag }} {% endfor %}}">
|
||||||
|
<button class="delete"></button>
|
||||||
|
{{ message }}
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue