diff --git a/topologie/admin.py b/topologie/admin.py
index f388c688..68598ac1 100644
--- a/topologie/admin.py
+++ b/topologie/admin.py
@@ -10,7 +10,7 @@ class PortAdmin(admin.ModelAdmin):
list_display = ('switch', 'port','room','machine_interface','details')
class RoomAdmin(admin.ModelAdmin):
- list_display = ('name',)
+ list_display = ('name','details')
admin.site.register(Port, PortAdmin)
admin.site.register(Room, RoomAdmin)
diff --git a/topologie/forms.py b/topologie/forms.py
index 1f7ed7c9..eb95ef72 100644
--- a/topologie/forms.py
+++ b/topologie/forms.py
@@ -1,4 +1,4 @@
-from .models import Port, Switch
+from .models import Port, Switch, Room
from django.forms import ModelForm, Form
class PortForm(ModelForm):
@@ -23,3 +23,7 @@ class EditSwitchForm(ModelForm):
class Meta(SwitchForm.Meta):
fields = ['building', 'number', 'details']
+class EditRoomForm(ModelForm):
+ class Meta:
+ model = Room
+ fields = '__all__'
diff --git a/topologie/migrations/0018_room_details.py b/topologie/migrations/0018_room_details.py
new file mode 100644
index 00000000..c2ac5252
--- /dev/null
+++ b/topologie/migrations/0018_room_details.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('topologie', '0017_auto_20160718_1141'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='room',
+ name='details',
+ field=models.CharField(blank=True, max_length=255),
+ ),
+ ]
diff --git a/topologie/models.py b/topologie/models.py
index 8eba55a3..47350f76 100644
--- a/topologie/models.py
+++ b/topologie/models.py
@@ -54,6 +54,7 @@ class Port(models.Model):
class Room(models.Model):
name = models.CharField(max_length=255, unique=True)
+ details = models.CharField(max_length=255, blank=True)
def __str__(self):
return str(self.name)
diff --git a/topologie/templates/topologie/aff_chambres.html b/topologie/templates/topologie/aff_chambres.html
new file mode 100644
index 00000000..2937a051
--- /dev/null
+++ b/topologie/templates/topologie/aff_chambres.html
@@ -0,0 +1,17 @@
+
+
+
+ Chambre |
+ Commentaire |
+ |
+
+
+ {% for room in room_list %}
+
+ {{room.name}} |
+ {{room.details}} |
+ {% if is_infra %} Editer
+ Supprimer{% endif %} |
+
+ {% endfor %}
+
diff --git a/topologie/templates/topologie/delete.html b/topologie/templates/topologie/delete.html
new file mode 100644
index 00000000..7873bd29
--- /dev/null
+++ b/topologie/templates/topologie/delete.html
@@ -0,0 +1,16 @@
+{% extends "machines/sidebar.html" %}
+{% load bootstrap3 %}
+
+{% block title %}Création et modification de machines{% endblock %}
+
+{% block content %}
+
+
+
+
+
+{% endblock %}
diff --git a/topologie/templates/topologie/index_room.html b/topologie/templates/topologie/index_room.html
new file mode 100644
index 00000000..3ae9a671
--- /dev/null
+++ b/topologie/templates/topologie/index_room.html
@@ -0,0 +1,15 @@
+{% extends "topologie/sidebar.html" %}
+{% load bootstrap3 %}
+
+{% block title %}Chambres{% endblock %}
+
+{% block content %}
+ Chambres
+{% if is_infra %}
+ Ajouter une chambre
+{% endif %}
+ {% include "topologie/aff_chambres.html" with room_list=room_list %}
+
+
+
+{% endblock %}
diff --git a/topologie/templates/topologie/sidebar.html b/topologie/templates/topologie/sidebar.html
index b74e53d3..bb8f906a 100644
--- a/topologie/templates/topologie/sidebar.html
+++ b/topologie/templates/topologie/sidebar.html
@@ -2,4 +2,5 @@
{% block sidebar %}
Liste des switchs
+ Liste des chambres
{% endblock %}
diff --git a/topologie/templates/topologie/port.html b/topologie/templates/topologie/topo.html
similarity index 100%
rename from topologie/templates/topologie/port.html
rename to topologie/templates/topologie/topo.html
diff --git a/topologie/urls.py b/topologie/urls.py
index 67f4c241..7f75a096 100644
--- a/topologie/urls.py
+++ b/topologie/urls.py
@@ -5,6 +5,10 @@ from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^new_switch/$', views.new_switch, name='new-switch'),
+ url(r'^index_room/$', views.index_room, name='index-room'),
+ url(r'^new_room/$', views.new_room, name='new-room'),
+ url(r'^edit_room/(?P[0-9]+)$', views.edit_room, name='edit-room'),
+ url(r'^del_room/(?P[0-9]+)$', views.del_room, name='del-room'),
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'),
url(r'^new_port/(?P[0-9]+)$', views.new_port, name='new-port'),
diff --git a/topologie/views.py b/topologie/views.py
index 0166cfe7..1b93840d 100644
--- a/topologie/views.py
+++ b/topologie/views.py
@@ -3,8 +3,8 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.db import IntegrityError
-from topologie.models import Switch, Port
-from topologie.forms import EditPortForm, EditSwitchForm, AddPortForm
+from topologie.models import Switch, Port, Room
+from topologie.forms import EditPortForm, EditSwitchForm, AddPortForm, EditRoomForm
from users.views import form
@login_required
@@ -24,6 +24,12 @@ def index_port(request, switch_id):
port_list = Port.objects.filter(switch = switch).order_by('port')
return render(request, 'topologie/index_p.html', {'port_list':port_list, 'id_switch':switch_id, 'nom_switch':switch})
+@login_required
+@permission_required('cableur')
+def index_room(request):
+ room_list = Room.objects.order_by('name')
+ return render(request, 'topologie/index_room.html', {'room_list': room_list})
+
@login_required
@permission_required('infra')
def new_port(request, switch_id):
@@ -42,7 +48,7 @@ def new_port(request, switch_id):
except IntegrityError:
messages.error(request,"Ce port existe déjà" )
return redirect("/topologie/switch/" + switch_id)
- return form({'topoform':port}, 'topologie/port.html', request)
+ return form({'topoform':port}, 'topologie/topo.html', request)
@login_required
@permission_required('infra')
@@ -57,7 +63,7 @@ def edit_port(request, port_id):
port.save()
messages.success(request, "Le port a bien été modifié")
return redirect("/topologie/")
- return form({'topoform':port}, 'topologie/port.html', request)
+ return form({'topoform':port}, 'topologie/topo.html', request)
@login_required
@permission_required('infra')
@@ -67,7 +73,7 @@ def new_switch(request):
switch.save()
messages.success(request, "Le switch a été créé")
return redirect("/topologie/")
- return form({'topoform':switch}, 'topologie/port.html', request)
+ return form({'topoform':switch}, 'topologie/topo.html', request)
@login_required
@permission_required('infra')
@@ -82,4 +88,43 @@ def edit_switch(request, switch_id):
switch.save()
messages.success(request, "Le switch a bien été modifié")
return redirect("/topologie/")
- return form({'topoform':switch}, 'topologie/port.html', request)
+ return form({'topoform':switch}, 'topologie/topo.html', request)
+
+@login_required
+@permission_required('infra')
+def new_room(request):
+ room = EditRoomForm(request.POST or None)
+ if room.is_valid():
+ room.save()
+ messages.success(request, "La chambre a été créé")
+ return redirect("/topologie/index_room/")
+ return form({'topoform':room}, 'topologie/topo.html', request)
+
+@login_required
+@permission_required('infra')
+def edit_room(request, room_id):
+ try:
+ room = Room.objects.get(pk=room_id)
+ except Room.DoesNotExist:
+ messages.error(request, u"Chambre inexistante")
+ return redirect("/topologie/index_room/")
+ room = EditRoomForm(request.POST or None, instance=room)
+ if room.is_valid():
+ room.save()
+ messages.success(request, "La chambre a bien été modifiée")
+ return redirect("/topologie/index_room/")
+ return form({'topoform':room}, 'topologie/topo.html', request)
+
+@login_required
+@permission_required('infra')
+def del_room(request, room_id):
+ try:
+ room = Room.objects.get(pk=room_id)
+ except Room.DoesNotExist:
+ messages.error(request, u"Chambre inexistante" )
+ return redirect("/topologie/index_room/")
+ if request.method == "POST":
+ room.delete()
+ messages.success(request, "La chambre/prise a été détruite")
+ return redirect("/topologie/index_room/")
+ return form({'objet': room, 'objet_name': 'Chambre'}, 'topologie/delete.html', request)