From 2c300ffc0126cc31dcd10077591d400b7d9f7634 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 1 Feb 2019 14:38:37 +0000 Subject: [PATCH] Set user variable in template tag --- manager/templatetags/userstatus.py | 4 ++++ manager/views.py | 8 +------- templates/base.html | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/manager/templatetags/userstatus.py b/manager/templatetags/userstatus.py index 1026e04..4da5387 100644 --- a/manager/templatetags/userstatus.py +++ b/manager/templatetags/userstatus.py @@ -21,3 +21,7 @@ def updateUserStatus(user, sec = False): except Exception as e: return "" % str(e) return "" + +@register.simple_tag(takes_context=True) +def setUser(context): + return context.request.user diff --git a/manager/views.py b/manager/views.py index 25a8e2b..5de5ffd 100644 --- a/manager/views.py +++ b/manager/views.py @@ -255,12 +255,7 @@ def ping(request, device_id): @login_required def devices(request): - return render(request, "manager/index.html", - { - "title": "Device Administration", - "user": request.user - } - ) + return render(request, "manager/index.html", {"title": "Device Administration"}) @login_required def editdevice(request, device_id): @@ -318,7 +313,6 @@ def editdevice(request, device_id): "title": "Edit Device", "device": device[0], "subnets": subnets, - "user": request.user, "wifis": wifis, "curfis": Wifi.objects.filter(device=device[0]) } diff --git a/templates/base.html b/templates/base.html index 6d7f962..157d72e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -13,6 +13,7 @@ {% load static %} {% load repo %} {% load userstatus %} + {% setUser as user %} {% updateUserStatus user %} {% block header %} {% endblock %}