mirror of https://gitlab.federez.net/re2o/re2o
12 changed files with 144 additions and 4 deletions
@ -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'] |
|||
@ -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> |
|||
@ -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> |
|||
@ -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 %} |
|||
@ -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 %} |
|||
@ -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 %} |
|||
@ -0,0 +1,5 @@ |
|||
{% extends "base.html" %} |
|||
|
|||
{% block sidebar %} |
|||
<p><a href="{% url "topologie:index" %}">Liste des switchs</a></p> |
|||
{% endblock %} |
|||
@ -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'), |
|||
] |
|||
|
|||
@ -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) |
|||
|
|||
|
|||
Loading…
Reference in new issue