Make device view more simple
This commit is contained in:
parent
a251f07ed4
commit
4e2f33c5f9
3 changed files with 26 additions and 21 deletions
|
@ -1,8 +1,22 @@
|
||||||
from django import template
|
from django import template
|
||||||
from manager.models import Organization
|
from manager.models import Organization, Device, Wifi
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag(takes_context=True)
|
||||||
def orgaString(user):
|
def orgaString(context):
|
||||||
return ", ".join(str(orga) for orga in user.organization_set.all())
|
return ", ".join(str(orga) for orga in context.request.user.organization_set.all())
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def userDevices(context):
|
||||||
|
return set(Device.objects.filter(organization__in=context.request.user.organization_set.all()))
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def userWifis(context):
|
||||||
|
return set(Wifi.objects.filter(organization__in=context.request.user.organization_set.all()))
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def userUsers(context):
|
||||||
|
return set(User.objects.filter(organization__in=context.request.user.organization_set.all()) if context.request.user.is_superuser else [])
|
||||||
|
|
||||||
|
|
|
@ -255,22 +255,10 @@ def ping(request, device_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def devices(request):
|
def devices(request):
|
||||||
devices = set()
|
|
||||||
wifis = set()
|
|
||||||
users = set()
|
|
||||||
|
|
||||||
for organization in request.user.organization_set.all():
|
|
||||||
devices = devices.union(organization.device_set.all())
|
|
||||||
wifis = wifis.union(organization.wifi_set.all())
|
|
||||||
users = users.union(organization.users.all()) if request.user.is_superuser else users
|
|
||||||
|
|
||||||
return render(request, "manager/index.html",
|
return render(request, "manager/index.html",
|
||||||
{
|
{
|
||||||
"title": "Device Administration",
|
"title": "Device Administration",
|
||||||
"user": request.user,
|
"user": request.user
|
||||||
"devices": sorted(devices, key=lambda x: x.serial),
|
|
||||||
"wifis": sorted(wifis, key=lambda x: x.serial),
|
|
||||||
"users": sorted(users, key=lambda x: x.username)
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -514,14 +502,14 @@ def makewifi(request):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
wifi = Wifi.objects.create(
|
wifi = Wifi.objects.create(
|
||||||
serial = wifi_serial,
|
serial = wifi_serial,
|
||||||
ssid = wifi_ssid,
|
ssid = wifi_ssid,
|
||||||
key = wifi_key,
|
key = wifi_key,
|
||||||
organization = Organization.objects.filter(id=wifi_organization)[0]
|
organization = Organization.objects.filter(id=wifi_organization)[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
@user_passes_test(is_superuser)
|
@user_passes_test(is_superuser)
|
||||||
def makedevice(request):
|
def makedevice(request):
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% load manager %}
|
{% load manager %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<p><b>Organization:</b> {% orgaString user %}</p>
|
<p><b>Organization:</b> {% orgaString %}</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>
|
||||||
|
@ -25,6 +25,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
{% userDevices as devices %}
|
||||||
{% 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>
|
||||||
|
@ -52,6 +53,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
{% userWifis as wifis %}
|
||||||
{% for wifi in wifis %}
|
{% for wifi in wifis %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div style="display:inline;" {% if user.is_superuser %}title="{{ wifi.organization.name }}"{% endif %}>{{ wifi.serial }}</div></td>
|
<td><div style="display:inline;" {% if user.is_superuser %}title="{{ wifi.organization.name }}"{% endif %}>{{ wifi.serial }}</div></td>
|
||||||
|
@ -64,7 +66,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if users %}
|
{% if request.user.is_staff %}
|
||||||
<div name="userpart" id="userpart">
|
<div name="userpart" id="userpart">
|
||||||
<h2>Users</h2>
|
<h2>Users</h2>
|
||||||
|
|
||||||
|
@ -79,6 +81,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
|
{% userUsers as users %}
|
||||||
{% for auser in users %}
|
{% for auser in users %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><div style="display:inline;" {% if user.is_superuser %}title="{% for orga in auser.organizations %}{{ orga }} {% endfor %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
|
<td><div style="display:inline;" {% if user.is_superuser %}title="{% for orga in auser.organizations %}{{ orga }} {% endfor %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
|
||||||
|
|
Loading…
Reference in a new issue