Add network adding form
This commit is contained in:
parent
3f734fed15
commit
c85549c124
7 changed files with 38 additions and 2 deletions
9
manager/forms.py
Normal file
9
manager/forms.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from django import forms
|
||||
|
||||
from .models import Organization
|
||||
|
||||
class NetworkForm(forms.Form):
|
||||
name = forms.CharField(label="Common Name", max_length=64)
|
||||
intip = forms.GenericIPAddressField(label="Internal IP Address", protocol="ipv4")
|
||||
extip = forms.GenericIPAddressField(label="External IP Address", protocol="ipv4")
|
||||
orgas = forms.MultipleChoiceField(label="Assigned Organizations", choices=[(orga.id, str(orga)) for orga in Organization.objects.all()])
|
|
@ -48,3 +48,7 @@ def userUsers(context):
|
|||
@register.simple_tag(takes_context=True)
|
||||
def userNets(context):
|
||||
return orgaObjects(Network, userOrgas(context))
|
||||
|
||||
@register.simple_tag
|
||||
def netOrgaString(network):
|
||||
return ", ".join(str(orga) for orga in network.organization.all())
|
||||
|
|
|
@ -20,6 +20,7 @@ urlpatterns = [
|
|||
path('makewifi/', views.makewifi, name='makewifi'),
|
||||
path('makeuser/', views.makeuser, name='makeuser'),
|
||||
path('makenet/', views.makenetwork, name='makenet'),
|
||||
path('networks/<int:network_id>/delete', views.deletenetwork, name='deletenetwork'),
|
||||
path('wifi/<int:wifi_id>/edit/', views.editwifi, name='editwifi'),
|
||||
path('wifi/<int:wifi_id>/delete/', views.deletewifi, name='deletewifi'),
|
||||
path('users/<int:user_id>/edit/', views.edituser, name='edituser'),
|
||||
|
|
|
@ -464,6 +464,12 @@ def deleteuser(request, user_id):
|
|||
user.delete()
|
||||
return redirect("/users/")
|
||||
|
||||
@user_passes_test(is_superuser)
|
||||
def deletenetwork(request, network_id):
|
||||
network = get_object_or_404(Network, id=network_id)
|
||||
network.delete()
|
||||
return redirect("/networks/")
|
||||
|
||||
@user_passes_test(is_staff)
|
||||
def makewifi(request):
|
||||
wifi_serial = request.POST.get("serial", "")
|
||||
|
|
|
@ -62,6 +62,10 @@ function askdeleteuser(user_id) {
|
|||
if (confirm("Are you sure you want to delete this User?")) window.location.href = "/users/" + user_id + "/delete";
|
||||
};
|
||||
|
||||
function askdeletenet(network_id) {
|
||||
if (confirm("Are you sure you want to delete this Network?")) window.location.href = "/networks/" + network_id + "/delete";
|
||||
};
|
||||
|
||||
function askreboot(device_id) {
|
||||
if (confirm("Are you sure you want to reboot this Device?")) window.location.href = "/devices/" + device_id + "/reboot";
|
||||
};
|
||||
|
|
12
templates/manager/form.html
Normal file
12
templates/manager/form.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
{% extends "base.html" %}
|
||||
{% load bootstrap %}
|
||||
{% block content %}
|
||||
|
||||
<form action="#" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|bootstrap }}
|
||||
<button type="submit" class="btn btn-success">Apply Changes</button>
|
||||
<a class="btn btn-danger" href="/devices/" role="button">Cancel</a>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
|
@ -112,10 +112,10 @@
|
|||
{% userNets as networks %}
|
||||
{% for network in networks %}
|
||||
<tr>
|
||||
<td><div style="display:inline;">{{ network.name }}</div></td>
|
||||
<td><div style="display:inline;" title="{% netOrgaString network %}">{{ network.name }}</div></td>
|
||||
<td>{{ network.intip }}</td>
|
||||
<td>{{ network.extip }}</td>
|
||||
<td></td>
|
||||
<td><a href="#"><i style="color: darkred;" onclick="askdeletenet({{ network.id }});" class="fas fa-trash-alt" title="Delete Network"></i></a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue