Move orga string generation for management panel to template tag

This commit is contained in:
Kumi 2019-02-01 08:56:02 +00:00
parent 1fbd067afe
commit e4e7ce3a52
3 changed files with 11 additions and 5 deletions

View file

@ -0,0 +1,8 @@
from django import template
from manager.models import Organization
register = template.Library()
@register.simple_tag
def orgaString(user):
return ", ".join(str(orga) for orga in Organization.objects.filter(users=user))

View file

@ -259,7 +259,6 @@ def devices(request):
devices = set()
wifis = set()
users = set()
orga = ", ".join([x.__str__() for x in Organization.objects.filter(users=user)])
for organization in Organization.objects.filter(users=user):
for device in Device.objects.filter(organization=organization):
@ -277,7 +276,6 @@ def devices(request):
{
"title": "Device Administration",
"user": user,
"organization": orga,
"devices": sorted(devices, key=lambda x: x.serial),
"wifis": sorted(wifis, key=lambda x: x.serial),
"users": sorted(users, key=lambda x: x.username)

View file

@ -1,9 +1,9 @@
{% extends "base.html" %}
{% load notifications %}
{% load manager %}
{% block content %}
<p><b>Organization:</b> {{ organization }}</p>
<p><b>Organization:</b> {% orgaString user %}</p>
<p><b>User:</b> {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) <a href="/user/{{ user.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a></p>
<div align="center"><b>Manage:</b> <a id="linkdevices" href="#" onclick="showdevices();">Devices</a> &dash; <a id="linkwifi" href="#" onclick="showwifi();">WiFi</a>{% if user.is_staff %} &dash; <a id="linkusers" href="#" onclick="showusers();">Users</a>{% endif %}</div>