diff --git a/re2o/urls.py b/re2o/urls.py
index 96ae98be..fe6776d8 100644
--- a/re2o/urls.py
+++ b/re2o/urls.py
@@ -24,5 +24,6 @@ urlpatterns = [
url(r'^search/', include('search.urls', namespace='search')),
url(r'^cotisations/', include('cotisations.urls', namespace='cotisations')),
url(r'^machines/', include('machines.urls', namespace='machines')),
+ url(r'^topologie/', include('topologie.urls', namespace='topologie')),
#url(r'^logs/', include('logs.urls', namespace='logs')),
]
diff --git a/templates/base.html b/templates/base.html
index 34079495..544c0952 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -30,7 +30,7 @@
diff --git a/topologie/forms.py b/topologie/forms.py
new file mode 100644
index 00000000..8e7355ac
--- /dev/null
+++ b/topologie/forms.py
@@ -0,0 +1,11 @@
+from .models import Port
+from django.forms import ModelForm, Form
+
+class PortForm(ModelForm):
+ class Meta:
+ model = Port
+ fields = '__all__'
+
+class EditPortForm(ModelForm):
+ class Meta(PortForm.Meta):
+ fields = ['room', 'machine_interface', 'related', 'details']
diff --git a/topologie/models.py b/topologie/models.py
index 441a9f78..80af6534 100644
--- a/topologie/models.py
+++ b/topologie/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.forms import ModelForm, Form
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.core.exceptions import ValidationError
@@ -27,10 +28,10 @@ class Switch(models.Model):
class Port(models.Model):
switch = models.ForeignKey(Switch, related_name="ports")
port = models.IntegerField()
- details = models.CharField(max_length=255, blank=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)
related = models.OneToOneField('self', null=True, blank=True, related_name='related_port')
+ details = models.CharField(max_length=255, blank=True)
class Meta:
unique_together = ('switch', 'port')
diff --git a/topologie/templates/topologie/aff_port.html b/topologie/templates/topologie/aff_port.html
new file mode 100644
index 00000000..d94b341f
--- /dev/null
+++ b/topologie/templates/topologie/aff_port.html
@@ -0,0 +1,23 @@
+
Switch {% if port_list.0 %}{{ port_list.0.switch }}{% endif %}
+
+
+
+ Port |
+ Room |
+ Interface machine |
+ Related |
+ Détails |
+ |
+
+
+ {% for port in port_list %}
+
+ {{ port.port }} |
+ {{ port.room }} |
+ {{ port.machine_interface }} |
+ {{ port.related }} |
+ {{ port.details }} |
+ Editer |
+
+ {% endfor %}
+
diff --git a/topologie/templates/topologie/aff_switch.html b/topologie/templates/topologie/aff_switch.html
new file mode 100644
index 00000000..880c264a
--- /dev/null
+++ b/topologie/templates/topologie/aff_switch.html
@@ -0,0 +1,18 @@
+
+
+
+ Bâtiment |
+ Numero |
+ Détails |
+ |
+
+
+ {% for switch in switch_list %}
+
+ {{switch.building}} |
+ {{switch.number}} |
+ {{switch.details}} |
+ Editer |
+
+ {% endfor %}
+
diff --git a/topologie/templates/topologie/index.html b/topologie/templates/topologie/index.html
new file mode 100644
index 00000000..c95f1491
--- /dev/null
+++ b/topologie/templates/topologie/index.html
@@ -0,0 +1,11 @@
+{% extends "topologie/sidebar.html" %}
+{% load bootstrap3 %}
+
+{% block title %}Switchs{% endblock %}
+
+{% block content %}
+ {% include "topologie/aff_switch.html" with switch_list=switch_list %}
+
+
+
+{% endblock %}
diff --git a/topologie/templates/topologie/index_p.html b/topologie/templates/topologie/index_p.html
new file mode 100644
index 00000000..5309bc46
--- /dev/null
+++ b/topologie/templates/topologie/index_p.html
@@ -0,0 +1,11 @@
+{% extends "topologie/sidebar.html" %}
+{% load bootstrap3 %}
+
+{% block title %}Ports du switch{% endblock %}
+
+{% block content %}
+ {% include "topologie/aff_port.html" with port_list=port_list %}
+
+
+
+{% endblock %}
diff --git a/topologie/templates/topologie/port.html b/topologie/templates/topologie/port.html
new file mode 100644
index 00000000..bd6713b7
--- /dev/null
+++ b/topologie/templates/topologie/port.html
@@ -0,0 +1,17 @@
+{% extends "topologie/sidebar.html" %}
+{% load bootstrap3 %}
+
+{% block title %}Création et modificationd 'utilisateur{% endblock %}
+
+{% block content %}
+{% bootstrap_form_errors topoform %}
+
+
+
+
+
+{% endblock %}
diff --git a/topologie/templates/topologie/sidebar.html b/topologie/templates/topologie/sidebar.html
new file mode 100644
index 00000000..b74e53d3
--- /dev/null
+++ b/topologie/templates/topologie/sidebar.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block sidebar %}
+
Liste des switchs
+{% endblock %}
diff --git a/topologie/urls.py b/topologie/urls.py
new file mode 100644
index 00000000..bc960eb6
--- /dev/null
+++ b/topologie/urls.py
@@ -0,0 +1,10 @@
+from django.conf.urls import url
+
+from . import views
+
+urlpatterns = [
+ url(r'^$', views.index, name='index'),
+ url(r'^switch/(?P
[0-9]+)$', views.index_port, name='index-port'),
+ url(r'^edit_port/(?P[0-9]+)$', views.edit_port, name='edit-port'),
+]
+
diff --git a/topologie/views.py b/topologie/views.py
index 91ea44a2..af3befe2 100644
--- a/topologie/views.py
+++ b/topologie/views.py
@@ -1,3 +1,35 @@
-from django.shortcuts import render
+from django.shortcuts import render, redirect
+from django.contrib import messages
-# Create your views here.
+
+from topologie.models import Switch, Port
+from topologie.forms import EditPortForm
+from users.views import form
+
+
+def index(request):
+ switch_list = Switch.objects.order_by('building', 'number')
+ return render(request, 'topologie/index.html', {'switch_list': switch_list})
+
+def index_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_list = Port.objects.filter(switch = switch).order_by('port')
+ return render(request, 'topologie/index_p.html', {'port_list':port_list})
+
+def edit_port(request, port_id):
+ try:
+ port = Port.objects.get(pk=port_id)
+ except Port.DoesNotExist:
+ messages.error(request, u"Port inexistant")
+ return redirect("/topologie/")
+ port = EditPortForm(request.POST or None, instance=port)
+ if port.is_valid():
+ port.save()
+ messages.success(request, "Le port a bien été modifié")
+ return redirect("/topologie")
+ return form({'topoform':port}, 'topologie/port.html', request)
+