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>
@ -27,7 +27,7 @@
{% for device in devices %}
<tr>
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">&#11044;</div>&nbsp;<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">&#11044;</div>&nbsp;<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 }}-network">{{ device.network }}</td>
<td><div style="display:inline;" id="{{ device.id }}-ip">{% if device.curip %}{{ device.curip }} (at {{ device.lasttime }}){% endif %}</div></td>