8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 03:43:12 +00:00

Affichage de la topologie

Modification d'un port
This commit is contained in:
Dalahro 2016-07-06 21:50:15 +02:00
parent 7be1e768d3
commit e8b55e5b55
12 changed files with 144 additions and 4 deletions

View file

@ -24,5 +24,6 @@ urlpatterns = [
url(r'^search/', include('search.urls', namespace='search')), url(r'^search/', include('search.urls', namespace='search')),
url(r'^cotisations/', include('cotisations.urls', namespace='cotisations')), url(r'^cotisations/', include('cotisations.urls', namespace='cotisations')),
url(r'^machines/', include('machines.urls', namespace='machines')), url(r'^machines/', include('machines.urls', namespace='machines')),
url(r'^topologie/', include('topologie.urls', namespace='topologie')),
#url(r'^logs/', include('logs.urls', namespace='logs')), #url(r'^logs/', include('logs.urls', namespace='logs')),
] ]

View file

@ -30,7 +30,7 @@
<li><a href="{% url "users:index" %}">Adhérents</a></li> <li><a href="{% url "users:index" %}">Adhérents</a></li>
<li><a href="{% url "machines:index" %}">Machines</a></li> <li><a href="{% url "machines:index" %}">Machines</a></li>
<li><a href="{% url "cotisations:index" %}">Cotisations</a></li> <li><a href="{% url "cotisations:index" %}">Cotisations</a></li>
<li><a href="#">Topologie</a></li> <li><a href="{% url "topologie:index" %}">Topologie</a></li>
<li><a href="#">Statistiques</a></li> <li><a href="#">Statistiques</a></li>
</ul> </ul>
<div class="col-sm-3 col-md-3 navbar-right"> <div class="col-sm-3 col-md-3 navbar-right">

11
topologie/forms.py Normal file
View file

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

View file

@ -1,4 +1,5 @@
from django.db import models from django.db import models
from django.forms import ModelForm, Form
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.fields import GenericForeignKey
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -27,10 +28,10 @@ class Switch(models.Model):
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()
details = models.CharField(max_length=255, blank=True)
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)
related = models.OneToOneField('self', null=True, blank=True, related_name='related_port') related = models.OneToOneField('self', null=True, blank=True, related_name='related_port')
details = models.CharField(max_length=255, blank=True)
class Meta: class Meta:
unique_together = ('switch', 'port') unique_together = ('switch', 'port')

View file

@ -0,0 +1,23 @@
<h2>Switch {% if port_list.0 %}{{ port_list.0.switch }}{% endif %}</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Port</th>
<th>Room</th>
<th>Interface machine</th>
<th>Related</th>
<th>Détails</th>
<th></th>
</tr>
</thead>
{% for port in port_list %}
<tr>
<td>{{ port.port }}</td>
<td>{{ port.room }}</td>
<td>{{ port.machine_interface }}</td>
<td>{{ port.related }}</td>
<td>{{ port.details }}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-port' port.id %}"><i class="glyphicon glyphicon-random"></i> Editer</a></td>
</tr>
{% endfor %}
</table>

View file

@ -0,0 +1,18 @@
<table class="table table-striped">
<thead>
<tr>
<th>Bâtiment</th>
<th>Numero</th>
<th>Détails</th>
<th></th>
</tr>
</thead>
{% for switch in switch_list %}
<tr>
<td>{{switch.building}}</td>
<td>{{switch.number}}</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>
</tr>
{% endfor %}
</table>

View file

@ -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 %}
<br />
<br />
<br />
{% endblock %}

View file

@ -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 %}
<br />
<br />
<br />
{% endblock %}

View file

@ -0,0 +1,17 @@
{% extends "topologie/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Création et modificationd 'utilisateur{% endblock %}
{% block content %}
{% bootstrap_form_errors topoform %}
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form topoform %}
{%bootstrap_button "Créer ou modifier" button_type="submit" icon="ok" %}
</form>
<br />
<br />
<br />
{% endblock %}

View file

@ -0,0 +1,5 @@
{% extends "base.html" %}
{% block sidebar %}
<p><a href="{% url "topologie:index" %}">Liste des switchs</a></p>
{% endblock %}

10
topologie/urls.py Normal file
View file

@ -0,0 +1,10 @@
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
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'),
]

View file

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