Make things prettier

This commit is contained in:
Kumi 2019-01-05 16:08:19 +01:00
parent 66b1fb0fad
commit 78a34b80fa
7 changed files with 43 additions and 14 deletions

View file

@ -0,0 +1,23 @@
# Generated by Django 2.1.3 on 2019-01-03 18:23
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('manager', '0029_auto_20190103_1809'),
]
operations = [
migrations.RenameField(
model_name='network',
old_name='commonname',
new_name='name',
),
migrations.AlterField(
model_name='device',
name='wifi',
field=models.ManyToManyField(blank=True, to='manager.Wifi'),
),
]

View file

@ -13,13 +13,13 @@ class Organization(models.Model):
return self.name
class Network(models.Model):
commonname = models.CharField("Common Name", max_length=64, blank=True, null=True)
name = models.CharField("Common Name", max_length=64, blank=True, null=True)
extip = models.CharField("External/Public IP", max_length=15)
intip = models.CharField("Internal/Private IP", max_length=15)
organizations = models.ManyToManyField(Organization)
def __str__(self):
return ("%s" % self.intip + (" (%s)" % self.commonname if self.commonname else ""))
return ("%s" % self.intip + (" (%s)" % self.name if self.name else ""))
class Model(models.Model):
name = models.CharField("Model Name", max_length=100, unique=True)

View file

@ -18,9 +18,9 @@
<div class="form-group">
<label for="secret">Device Secret</label>
<input type="text" class="form-control" id="secret" disabled="disabled" value="{{ device.secret }}"></input>
</div>
{% endif %}
{% if user.is_staff %}
</div>
<div class="form-group">
<label for="password">Root Password</label>
<input type="text" class="form-control" id="password" disabled="disabled" value="{{ device.password }}"></input>
@ -34,7 +34,7 @@
<label for="subnet">Assigned Network</label>
<select class="custom-select mr-sm-2" id="subnet" name="subnet">
{% for choice in subnets %}
<option {% if choice.intip == device.network.intip %} selected {% endif %} value="{{ choice.intip }}">{{ choice.intip}} ({{ choice.extip }})</option>
<option {% if choice.intip == device.network.intip %} selected {% endif %} value="{{ choice.intip }}">{{ choice.intip}}{% if choice.name %} ({{ choice.name }}){% endif %}</option>
{% endfor %}
</select>
<small id="subnetHelp" class="form-text text-muted">A network change will require a reboot of the device to be applied.</small>

View file

@ -239,7 +239,7 @@ def ping(request, device_id):
ajax += ',\n "network": {'
ajax += '\n "intip": "%s"' % device[0].network.intip
ajax += ',\n "extip": "%s"' % device[0].network.extip
ajax += ',\n "commonname": "%s"' % device[0].network.commonname
ajax += ',\n "name": "%s"' % device[0].network.name
ajax += '\n }'
except:
@ -256,10 +256,9 @@ def devices(request):
user = request.user
devices = set()
wifis = set()
orga = None
orga = ", ".join([x.__str__() for x in Organization.objects.filter(users=user)])
for organization in Organization.objects.filter(users=user):
orga = orga or organization
for device in Device.objects.filter(organization=organization):
devices.add(device)
for wifi in Wifi.objects.filter(organization=organization):
@ -285,15 +284,16 @@ def editdevice(request, device_id):
for organization in Organization.objects.filter(users=request.user):
device = device or Device.objects.filter(id=device_id, organization=organization)
for subnet in Network.objects.filter(organizations=organization):
subnets.add(subnet)
for wifi in Wifi.objects.filter(organization=organization):
wifis.add(wifi)
if not device:
return redirect("/")
for subnet in Network.objects.filter(organizations=device[0].organization):
subnets.add(subnet)
for wifi in Wifi.objects.filter(organization=device[0].organization):
wifis.add(wifi)
if request.POST.get("subnet", ""):
subnet = Network.objects.filter(intip=request.POST.get("subnet", device[0].network.intip if device[0].network else "No VPN"))

View file

@ -29,7 +29,7 @@ function styleStatus(msg, device) {
};
if (msg.hasOwnProperty("network")) {
device_network.text(msg.network.intip + " (" + msg.network.commonname + ")");
device_network.text(msg.network.intip + " (" + msg.network.name + ")");
};
if (msg.hasOwnProperty("reboot")) {

View file

@ -0,0 +1,5 @@
from django.contrib import admin
def admin_header_processor(request):
site_header = getattr(admin.site, 'site_header')
return {"site_header": site_header}

View file

@ -49,6 +49,7 @@ TEMPLATES = [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'vpnmanager.context_processors.admin_header_processor',
],
},
},