Move orga string generation for management panel to template tag
This commit is contained in:
parent
1fbd067afe
commit
e4e7ce3a52
3 changed files with 11 additions and 5 deletions
8
manager/templatetags/manager.py
Normal file
8
manager/templatetags/manager.py
Normal 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))
|
|
@ -259,7 +259,6 @@ def devices(request):
|
||||||
devices = set()
|
devices = set()
|
||||||
wifis = set()
|
wifis = set()
|
||||||
users = set()
|
users = set()
|
||||||
orga = ", ".join([x.__str__() for x in Organization.objects.filter(users=user)])
|
|
||||||
|
|
||||||
for organization in Organization.objects.filter(users=user):
|
for organization in Organization.objects.filter(users=user):
|
||||||
for device in Device.objects.filter(organization=organization):
|
for device in Device.objects.filter(organization=organization):
|
||||||
|
@ -277,7 +276,6 @@ def devices(request):
|
||||||
{
|
{
|
||||||
"title": "Device Administration",
|
"title": "Device Administration",
|
||||||
"user": user,
|
"user": user,
|
||||||
"organization": orga,
|
|
||||||
"devices": sorted(devices, key=lambda x: x.serial),
|
"devices": sorted(devices, key=lambda x: x.serial),
|
||||||
"wifis": sorted(wifis, key=lambda x: x.serial),
|
"wifis": sorted(wifis, key=lambda x: x.serial),
|
||||||
"users": sorted(users, key=lambda x: x.username)
|
"users": sorted(users, key=lambda x: x.username)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load notifications %}
|
{% load notifications %}
|
||||||
|
{% load manager %}
|
||||||
{% block content %}
|
{% 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>
|
<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> ‐ <a id="linkwifi" href="#" onclick="showwifi();">WiFi</a>{% if user.is_staff %} ‐ <a id="linkusers" href="#" onclick="showusers();">Users</a>{% endif %}</div>
|
<div align="center"><b>Manage:</b> <a id="linkdevices" href="#" onclick="showdevices();">Devices</a> ‐ <a id="linkwifi" href="#" onclick="showwifi();">WiFi</a>{% if user.is_staff %} ‐ <a id="linkusers" href="#" onclick="showusers();">Users</a>{% endif %}</div>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
{% for device in devices %}
|
{% for device in devices %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">⬤</div> <div style="display: inline;" {% if user.is_superuser %}title="{{device.organization.name}}"{% endif %} id="{{ device.id }}-id">{{ device.serial }}</div></td>
|
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">⬤</div> <div style="display: inline;" {% if user.is_superuser %}title="{{ device.organization.name }}"{% endif %} id="{{ device.id }}-id">{{ device.serial }}</div></td>
|
||||||
<td id="{{ device.id }}-name">{% if device.name %}{{ device.name }}{% endif %}</td>
|
<td id="{{ device.id }}-name">{% if device.name %}{{ device.name }}{% endif %}</td>
|
||||||
<td id="{{ device.id }}-network">{{ device.network }}</td>
|
<td id="{{ device.id }}-network">{{ device.network }}</td>
|
||||||
<td><div style="display:inline;" id="{{ device.id }}-ip">{% if device.curip %}{{ device.curip }} (at {{ device.lasttime }}){% endif %}</div></td>
|
<td><div style="display:inline;" id="{{ device.id }}-ip">{% if device.curip %}{{ device.curip }} (at {{ device.lasttime }}){% endif %}</div></td>
|
||||||
|
|
Loading…
Reference in a new issue