Implement network adding form

This commit is contained in:
Kumi 2019-02-02 14:31:25 +00:00
parent 41d915a90b
commit 3e744a4bc5
3 changed files with 18 additions and 1 deletions

View file

@ -19,6 +19,7 @@ urlpatterns = [
path('makedevice/', views.makedevice, name="makedevice"),
path('makewifi/', views.makewifi, name='makewifi'),
path('makeuser/', views.makeuser, name='makeuser'),
path('makenet/', views.makenetwork, name='makenet'),
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'),

View file

@ -15,6 +15,7 @@ from django.contrib.auth.forms import PasswordResetForm
from .models import Device, Organization, Network, Model, Wifi, UserStatus
from .signals import *
from .forms import *
from .device import makewificonfig, heartbeathandler
from distutils.dir_util import copy_tree
@ -486,6 +487,21 @@ def makewifi(request):
return redirect("/wifi/")
@user_passes_test(is_superuser)
def makenetwork(request):
if request.method == "POST":
form = NetworkForm(request.POST)
if form.is_valid():
data = form.cleaned_data
network = Network.objects.create(name=data["name"], intip=data["intip"], extip=data["extip"])
network.organization.set(data["orgas"])
return redirect("/networks/")
else:
form = NetworkForm()
return render(request, "manager/form.html", { "title": "Add Network", "form": form })
@user_passes_test(is_superuser)
def makedevice(request):
CADIR = "/etc/openvpn/ca/"

View file

@ -113,7 +113,7 @@
{% userNets as networks %}
{% for network in networks %}
<tr>
<td><div style="display:inline;" title="{% directOrgaString auser %}">{{ network.name }}</div></td>
<td><div style="display:inline;">{{ network.name }}</div></td>
<td>{{ network.intip }}</td>
<td>{{ network.extip }}</td>
<td></td>