8
0
Fork 0
mirror of https://gitlab.federez.net/re2o/re2o synced 2024-05-20 17:42:26 +00:00

Modele pour les baies de switchs

This commit is contained in:
Gabriel Detraz 2018-04-07 20:45:29 +02:00 committed by chirac
parent 3affe08d29
commit 3f05b27f3b
11 changed files with 330 additions and 5 deletions

View file

@ -127,6 +127,8 @@ MODEL_NAME = {
'ConstructorSwitch' : topologie.models.ConstructorSwitch,
'Port' : topologie.models.Port,
'Room' : topologie.models.Room,
'Building' : topologie.models.Building,
'SwitchBay' : topologie.models.SwitchBay,
# users
'User' : users.models.User,
'Adherent' : users.models.Adherent,

View file

@ -85,6 +85,8 @@ HISTORY_BIND = {
'modelswitch' : topologie.models.ModelSwitch,
'constructorswitch' : topologie.models.ConstructorSwitch,
'accesspoint' : topologie.models.AccessPoint,
'switchbay' : topologie.models.SwitchBay,
'building' : topologie.models.Building,
},
'machines' : {
'machine' : machines.models.Machine,

View file

@ -36,7 +36,9 @@ from .models import (
Stack,
ModelSwitch,
ConstructorSwitch,
AccessPoint
AccessPoint,
SwitchBay,
Building
)
@ -75,6 +77,16 @@ class ConstructorSwitchAdmin(VersionAdmin):
pass
class SwitchBayAdmin(VersionAdmin):
"""Administration d'une baie de brassage"""
pass
class BuildingAdmin(VersionAdmin):
"""Administration d'un batiment"""
pass
admin.site.register(Port, PortAdmin)
admin.site.register(AccessPoint, AccessPointAdmin)
admin.site.register(Room, RoomAdmin)
@ -82,3 +94,5 @@ admin.site.register(Switch, SwitchAdmin)
admin.site.register(Stack, StackAdmin)
admin.site.register(ModelSwitch, ModelSwitchAdmin)
admin.site.register(ConstructorSwitch, ConstructorSwitchAdmin)
admin.site.register(Building, BuildingAdmin)
admin.site.register(SwitchBay, SwitchBayAdmin)

View file

@ -48,7 +48,9 @@ from .models import (
Stack,
ModelSwitch,
ConstructorSwitch,
AccessPoint
AccessPoint,
SwitchBay,
Building,
)
from re2o.mixins import FormRevMixin
@ -186,3 +188,25 @@ class EditConstructorSwitchForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditConstructorSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
class EditSwitchBayForm(FormRevMixin, ModelForm):
"""Permet d'éditer une baie de brassage"""
class Meta:
model = SwitchBay
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditSwitchBayForm, self).__init__(*args, prefix=prefix, **kwargs)
class EditBuildingForm(FormRevMixin, ModelForm):
"""Permet d'éditer le batiment"""
class Meta:
model = Building
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditBuildingForm, self).__init__(*args, prefix=prefix, **kwargs)

View file

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-04-07 17:41
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('topologie', '0055_auto_20180329_0431'),
]
operations = [
migrations.CreateModel(
name='Building',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
],
options={
'permissions': (('view_building', 'Peut voir un objet batiment'),),
},
bases=(re2o.mixins.AclMixin, re2o.mixins.RevMixin, models.Model),
),
migrations.CreateModel(
name='SwitchBay',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('info', models.CharField(blank=True, help_text='Informations particulières', max_length=255, null=True)),
('building', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='topologie.Building')),
('members', models.ManyToManyField(blank=True, related_name='bay_switches', to='topologie.Switch')),
],
options={
'permissions': (('view_switchbay', 'Peut voir un objet baie de brassage'),),
},
bases=(re2o.mixins.AclMixin, re2o.mixins.RevMixin, models.Model),
),
]

View file

@ -186,8 +186,11 @@ class Switch(AclMixin, Machine):
except IntegrityError:
ValidationError("Création d'un port existant.")
def main_interface(self):
return self.interface_set.first()
def __str__(self):
return str(self.interface_set.first())
return str(self.main_interface())
class ModelSwitch(AclMixin, RevMixin, models.Model):
@ -222,6 +225,49 @@ class ConstructorSwitch(AclMixin, RevMixin, models.Model):
return self.name
class SwitchBay(AclMixin, RevMixin, models.Model):
"""Une baie de brassage"""
PRETTY_NAME = "Baie de brassage"
name = models.CharField(max_length=255)
building = models.ForeignKey(
'Building',
on_delete=models.PROTECT
)
members = models.ManyToManyField(
blank=True,
to='Switch',
related_name='bay_switches'
)
info = models.CharField(
max_length=255,
blank=True,
null=True,
help_text="Informations particulières"
)
class Meta:
permissions = (
("view_switchbay", "Peut voir un objet baie de brassage"),
)
def __str__(self):
return self.name
class Building(AclMixin, RevMixin, models.Model):
"""Un batiment"""
PRETTY_NAME = "Batiment"
name = models.CharField(max_length=255)
class Meta:
permissions = (
("view_building", "Peut voir un objet batiment"),
)
def __str__(self):
return self.name
class Port(AclMixin, RevMixin, models.Model):
""" Definition d'un port. Relié à un switch(foreign_key),
un port peut etre relié de manière exclusive à :

View file

@ -0,0 +1,62 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% if building_list.paginator %}
{% include "pagination.html" with list=building_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>{% include "buttons/sort.html" with prefix='building' col='name' text='Bâtiment' %}</th>
<th></th>
</tr>
</thead>
{% for building in building_list %}
<tr>
<td>{{building.name}}</td>
<td class="text-right">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'building' building.pk %}">
<i class="fa fa-history"></i>
</a>
{% can_edit building %}
<a class="btn btn-primary btn-sm" role="button" title="Éditer" href="{% url 'topologie:edit-building' building.id %}">
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
{% can_delete building %}
<a class="btn btn-danger btn-sm" role="button" title="Supprimer" href="{% url 'topologie:del-building' building.id %}">
<i class="fa fa-trash"></i>
</a>
{% acl_end %}
</td>
</tr>
{% endfor %}
</table>
{% if building_list.paginator %}
{% include "pagination.html" with list=building_list %}
{% endif %}

View file

@ -0,0 +1,68 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% if switch_bay_list.paginator %}
{% include "pagination.html" with list=switch_bay_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>{% include "buttons/sort.html" with prefix='switch-bay' col='name' text='Baie' %}</th>
<th>Bâtiment</th>
<th>Info particulières</th>
<th>Switchs du batiment</th>
<th></th>
</tr>
</thead>
{% for switch_bay in switch_bay_list %}
<tr>
<td>{{switch_bay.name}}</td>
<td>{{switch_bay.building}}</td>
<td>{{switch_bay.info}}</td>
<td>{{switch_bay.members}}</td>
<td class="text-right">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'switch-bay' switch_bay.pk %}">
<i class="fa fa-history"></i>
</a>
{% can_edit switch_bay %}
<a class="btn btn-primary btn-sm" role="button" title="Éditer" href="{% url 'topologie:edit-switch-bay' switch_bay.id %}">
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
{% can_delete switch_bay %}
<a class="btn btn-danger btn-sm" role="button" title="Supprimer" href="{% url 'topologie:del-switch-bay' switch_bay.id %}">
<i class="fa fa-trash"></i>
</a>
{% acl_end %}
</td>
</tr>
{% endfor %}
</table>
{% if switch_bay_list.paginator %}
{% include "pagination.html" with list=switch_bay_list %}
{% endif %}

View file

@ -41,6 +41,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<hr>
{% acl_end %}
{% include "topologie/aff_constructor_switch.html" with constructor_switch_list=constructor_switch_list %}
<h2>Baie de brassage</h2>
{% can_create SwitchBay %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-switch-bay' %}"><i class="fa fa-plus"></i> Ajouter une baie de brassage</a>
<hr>
{% acl_end %}
{% include "topologie/aff_switch_bay.html" with switch_bay_list=switch_bay_list %}
<br />
<br />
<br />

View file

@ -99,4 +99,14 @@ urlpatterns = [
url(r'^del_constructor_switch/(?P<constructorswitchid>[0-9]+)$',
views.del_constructor_switch,
name='del-constructor-switch'),
url(r'^new_switch_bay/$',
views.new_switch_bay,
name='new-switch-bay'
),
url(r'^edit_switch_bay/(?P<switchbayid>[0-9]+)$',
views.edit_switch_bay,
name='edit-switch-bay'),
url(r'^del_switch_bay/(?P<switchbayid>[0-9]+)$',
views.del_switch_bay,
name='del-switch-bay'),
]

View file

@ -51,7 +51,9 @@ from topologie.models import (
Stack,
ModelSwitch,
ConstructorSwitch,
AccessPoint
AccessPoint,
SwitchBay,
Building
)
from topologie.forms import EditPortForm, NewSwitchForm, EditSwitchForm
from topologie.forms import (
@ -62,7 +64,9 @@ from topologie.forms import (
EditConstructorSwitchForm,
CreatePortsForm,
AddAccessPointForm,
EditAccessPointForm
EditAccessPointForm,
EditSwitchBayForm,
EditBuildingForm
)
from users.views import form
from re2o.utils import re2o_paginator, SortTable
@ -200,6 +204,7 @@ def index_model_switch(request):
""" Affichage de l'ensemble des modèles de switches"""
model_switch_list = ModelSwitch.objects.select_related('constructor')
constructor_switch_list = ConstructorSwitch.objects
switch_bay_list = SwitchBay.objects.select_related('building')
model_switch_list = SortTable.sort(
model_switch_list,
request.GET.get('col'),
@ -215,6 +220,7 @@ def index_model_switch(request):
return render(request, 'topologie/index_model_switch.html', {
'model_switch_list': model_switch_list,
'constructor_switch_list': constructor_switch_list,
'switch_bay_list': switch_bay_list,
})
@ -635,6 +641,49 @@ def del_model_switch(request, model_switch, modelswitchid):
}, 'topologie/delete.html', request)
@login_required
@can_create(SwitchBay)
def new_switch_bay(request):
"""Nouvelle baie de switch"""
switch_bay = EditSwitchBayForm(request.POST or None)
if switch_bay.is_valid():
switch_bay.save()
messages.success(request, "La baie a été créé")
return redirect(reverse('topologie:index-model-switch'))
return form({'topoform': switch_bay, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request)
@login_required
@can_edit(SwitchBay)
def edit_switch_bay(request, switch_bay, switchbayid):
""" Edition d'une baie de switch"""
switch_bay = EditSwitchBayForm(request.POST or None, instance=switch_bay)
if switch_bay.is_valid():
if switch_bay.changed_data:
switch_bay.save()
messages.success(request, "Le switch a bien été modifié")
return redirect(reverse('topologie:index-model-switch'))
return form({'topoform': switch_bay, 'action_name' : 'Editer'}, 'topologie/topo.html', request)
@login_required
@can_delete(SwitchBay)
def del_switch_bay(request, switch_bay, switchbayid):
""" Suppression d'une baie de switch"""
if request.method == "POST":
try:
switch_bay.delete()
messages.success(request, "La baie a été détruite")
except ProtectedError:
messages.error(request, "La baie %s est affecté à un autre objet,\
impossible de la supprimer (switch ou user)" % switch_bay)
return redirect(reverse('topologie:index-model-switch'))
return form({
'objet': switch_bay,
'objet_name': 'Baie de switch'
}, 'topologie/delete.html', request)
@login_required
@can_create(ConstructorSwitch)
def new_constructor_switch(request):