8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +00:00

Permet de gérer les chambres

This commit is contained in:
Gabriel Detraz 2016-07-19 02:30:52 +02:00
parent 32c882b23e
commit bdb8c2ee42
11 changed files with 130 additions and 8 deletions

View file

@ -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)

View file

@ -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__'

View file

@ -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),
),
]

View file

@ -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)

View file

@ -0,0 +1,17 @@
<table class="table table-striped">
<thead>
<tr>
<th>Chambre</th>
<th>Commentaire</th>
<th></th>
</tr>
</thead>
{% for room in room_list %}
<tr>
<td>{{room.name}}</td>
<td>{{room.details}}</td>
<td>{% if is_infra %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-room' room.id %}"><i class="glyphicon glyphicon-random"></i> Editer</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'topologie:del-room' room.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a>{% endif %}</td>
</tr>
{% endfor %}
</table>

View file

@ -0,0 +1,16 @@
{% extends "machines/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Création et modification de machines{% endblock %}
{% block content %}
<form class="form" method="post">
{% csrf_token %}
<h4>Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?</h4>
{% bootstrap_button "Confirmer" button_type="submit" icon="trash" %}
</form>
<br />
<br />
<br />
{% endblock %}

View file

@ -0,0 +1,15 @@
{% extends "topologie/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Chambres{% endblock %}
{% block content %}
<h2>Chambres</h2>
{% if is_infra %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-room' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter une chambre</a>
{% endif %}
{% include "topologie/aff_chambres.html" with room_list=room_list %}
<br />
<br />
<br />
{% endblock %}

View file

@ -2,4 +2,5 @@
{% block sidebar %}
<p><a href="{% url "topologie:index" %}">Liste des switchs</a></p>
<p><a href="{% url "topologie:index-room" %}">Liste des chambres</a></p>
{% endblock %}

View file

@ -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<room_id>[0-9]+)$', views.edit_room, name='edit-room'),
url(r'^del_room/(?P<room_id>[0-9]+)$', views.del_room, name='del-room'),
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'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'),

View file

@ -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)