mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
Topologie: ajout et modif
This commit is contained in:
parent
b23e1eeb65
commit
917e983f16
8 changed files with 67 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
||||||
from .models import Port
|
from .models import Port, Switch
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
|
|
||||||
class PortForm(ModelForm):
|
class PortForm(ModelForm):
|
||||||
|
@ -9,3 +9,17 @@ class PortForm(ModelForm):
|
||||||
class EditPortForm(ModelForm):
|
class EditPortForm(ModelForm):
|
||||||
class Meta(PortForm.Meta):
|
class Meta(PortForm.Meta):
|
||||||
fields = ['room', 'machine_interface', 'related', 'details']
|
fields = ['room', 'machine_interface', 'related', 'details']
|
||||||
|
|
||||||
|
class AddPortForm(ModelForm):
|
||||||
|
class Meta(PortForm.Meta):
|
||||||
|
fields = ['port', 'room', 'machine_interface', 'related', 'details']
|
||||||
|
|
||||||
|
class SwitchForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Switch
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
class EditSwitchForm(ModelForm):
|
||||||
|
class Meta(SwitchForm.Meta):
|
||||||
|
fields = ['building', 'number', 'details']
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class Switch(models.Model):
|
||||||
return str(self.building) + str(self.number)
|
return str(self.building) + str(self.number)
|
||||||
|
|
||||||
class Port(models.Model):
|
class Port(models.Model):
|
||||||
switch = models.ForeignKey(Switch, related_name="ports")
|
switch = models.ForeignKey('Switch', related_name="ports")
|
||||||
port = models.IntegerField()
|
port = models.IntegerField()
|
||||||
room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True, null=True)
|
room = models.ForeignKey('Room', on_delete=models.PROTECT, blank=True, null=True)
|
||||||
machine_interface = models.OneToOneField('machines.Interface', on_delete=models.PROTECT, blank=True, null=True)
|
machine_interface = models.OneToOneField('machines.Interface', on_delete=models.PROTECT, blank=True, null=True)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
<h2>Switch {% if port_list.0 %}{{ port_list.0.switch }}{% endif %}</h2>
|
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<td>{{switch.building}}</td>
|
<td>{{switch.building}}</td>
|
||||||
<td>{{switch.number}}</td>
|
<td>{{switch.number}}</td>
|
||||||
<td>{{switch.details}}</td>
|
<td>{{switch.details}}</td>
|
||||||
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:index-port' switch.pk %}"><i class="glyphicon glyphicon-list-alt"></i> Editer</a></td>
|
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:index-port' switch.pk %}"><i class="glyphicon glyphicon-cog"></i> Configurer</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
{% block title %}Ports du switch{% endblock %}
|
{% block title %}Ports du switch{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h2>Switch {{ nom_switch }}</h2>
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-switch' id_switch %}"><i class="glyphicon glyphicon-edit"></i> Editer</a>
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-port' id_switch %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un port</a>
|
||||||
{% include "topologie/aff_port.html" with port_list=port_list %}
|
{% include "topologie/aff_port.html" with port_list=port_list %}
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -2,4 +2,5 @@
|
||||||
|
|
||||||
{% block sidebar %}
|
{% block sidebar %}
|
||||||
<p><a href="{% url "topologie:index" %}">Liste des switchs</a></p>
|
<p><a href="{% url "topologie:index" %}">Liste des switchs</a></p>
|
||||||
|
<p><a href="{% url "topologie:new-switch" %}">Ajouter un switch</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,7 +4,10 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.index, name='index'),
|
url(r'^$', views.index, name='index'),
|
||||||
|
url(r'^new_switch/$', views.new_switch, name='new-switch'),
|
||||||
url(r'^switch/(?P<switch_id>[0-9]+)$', views.index_port, name='index-port'),
|
url(r'^switch/(?P<switch_id>[0-9]+)$', views.index_port, name='index-port'),
|
||||||
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),
|
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),
|
||||||
|
url(r'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'),
|
||||||
|
url(r'^edit_switch/(?P<switch_id>[0-9]+)$', views.edit_switch, name='edit-switch'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.db import IntegrityError
|
||||||
|
|
||||||
from topologie.models import Switch, Port
|
from topologie.models import Switch, Port
|
||||||
from topologie.forms import EditPortForm
|
from topologie.forms import EditPortForm, EditSwitchForm, AddPortForm
|
||||||
from users.views import form
|
from users.views import form
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,25 @@ def index_port(request, switch_id):
|
||||||
messages.error(request, u"Switch inexistant")
|
messages.error(request, u"Switch inexistant")
|
||||||
return redirect("/topologie/")
|
return redirect("/topologie/")
|
||||||
port_list = Port.objects.filter(switch = switch).order_by('port')
|
port_list = Port.objects.filter(switch = switch).order_by('port')
|
||||||
return render(request, 'topologie/index_p.html', {'port_list':port_list})
|
return render(request, 'topologie/index_p.html', {'port_list':port_list, 'id_switch':switch_id, 'nom_switch':switch})
|
||||||
|
|
||||||
|
def new_port(request, switch_id):
|
||||||
|
try:
|
||||||
|
switch = Switch.objects.get(pk=switch_id)
|
||||||
|
except Switch.DoesNotExist:
|
||||||
|
messages.error(request, u"Switch inexistant")
|
||||||
|
return redirect("/topologie/")
|
||||||
|
port = AddPortForm(request.POST or None)
|
||||||
|
if port.is_valid():
|
||||||
|
port = port.save(commit=False)
|
||||||
|
port.switch = switch
|
||||||
|
try:
|
||||||
|
port.save()
|
||||||
|
messages.success(request, "Port ajouté")
|
||||||
|
except IntegrityError:
|
||||||
|
pass
|
||||||
|
return redirect("/topologie/switch/" + switch_id)
|
||||||
|
return form({'topoform':port}, 'topologie/port.html', request)
|
||||||
|
|
||||||
def edit_port(request, port_id):
|
def edit_port(request, port_id):
|
||||||
try:
|
try:
|
||||||
|
@ -30,6 +48,26 @@ def edit_port(request, port_id):
|
||||||
if port.is_valid():
|
if port.is_valid():
|
||||||
port.save()
|
port.save()
|
||||||
messages.success(request, "Le port a bien été modifié")
|
messages.success(request, "Le port a bien été modifié")
|
||||||
return redirect("/topologie")
|
return redirect("/topologie/")
|
||||||
return form({'topoform':port}, 'topologie/port.html', request)
|
return form({'topoform':port}, 'topologie/port.html', request)
|
||||||
|
|
||||||
|
def new_switch(request):
|
||||||
|
switch = EditSwitchForm(request.POST or None)
|
||||||
|
if switch.is_valid():
|
||||||
|
switch.save()
|
||||||
|
messages.success(request, "Le switch a été créé")
|
||||||
|
return redirect("/topologie/")
|
||||||
|
return form({'topoform':switch}, 'topologie/port.html', request)
|
||||||
|
|
||||||
|
def edit_switch(request, switch_id):
|
||||||
|
try:
|
||||||
|
switch = Switch.objects.get(pk=switch_id)
|
||||||
|
except Switch.DoesNotExist:
|
||||||
|
messages.error(request, u"Switch inexistant")
|
||||||
|
return redirect("/topologie/")
|
||||||
|
switch = EditSwitchForm(request.POST or None, instance=switch)
|
||||||
|
if switch.is_valid():
|
||||||
|
switch.save()
|
||||||
|
messages.success(request, "Le switch a bien été modifié")
|
||||||
|
return redirect("/topologie/")
|
||||||
|
return form({'topoform':switch}, 'topologie/port.html', request)
|
||||||
|
|
Loading…
Reference in a new issue