Commit 88050397 authored by Dalahro's avatar Dalahro

Affichage de la topologie

Modification d'un port
parent db638966
......@@ -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')),
]
......@@ -30,7 +30,7 @@
<li><a href="{% url "users:index" %}">Adhérents</a></li>
<li><a href="{% url "machines:index" %}">Machines</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>
</ul>
<div class="col-sm-3 col-md-3 navbar-right">
......
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']
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')
......
<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>
<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>
{% 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 %}
{% 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 %}
{% 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 %}
{% extends "base.html" %}
{% block sidebar %}
<p><a href="{% url "topologie:index" %}">Liste des switchs</a></p>
{% endblock %}
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'),
]
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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment