mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Gestion complète de la baie de brassage, menu d'edition des switchs membres
This commit is contained in:
parent
3f05b27f3b
commit
bc1267e8f8
9 changed files with 140 additions and 12 deletions
|
@ -238,6 +238,10 @@ class SortTable:
|
||||||
'room_name': ['name'],
|
'room_name': ['name'],
|
||||||
'default': ['name']
|
'default': ['name']
|
||||||
}
|
}
|
||||||
|
TOPOLOGIE_INDEX_BUILDING = {
|
||||||
|
'building_name': ['name'],
|
||||||
|
'default': ['name']
|
||||||
|
}
|
||||||
TOPOLOGIE_INDEX_BORNE = {
|
TOPOLOGIE_INDEX_BORNE = {
|
||||||
'ap_name': ['interface__domain__name'],
|
'ap_name': ['interface__domain__name'],
|
||||||
'ap_ip': ['interface__ipv4__ipv4'],
|
'ap_ip': ['interface__ipv4__ipv4'],
|
||||||
|
@ -250,12 +254,17 @@ class SortTable:
|
||||||
'default': ['stack_id'],
|
'default': ['stack_id'],
|
||||||
}
|
}
|
||||||
TOPOLOGIE_INDEX_MODEL_SWITCH = {
|
TOPOLOGIE_INDEX_MODEL_SWITCH = {
|
||||||
'model_switch_name': ['reference'],
|
'model-switch_name': ['reference'],
|
||||||
'model_switch__contructor' : ['constructor__name'],
|
'model-switch_contructor' : ['constructor__name'],
|
||||||
'default': ['reference'],
|
'default': ['reference'],
|
||||||
}
|
}
|
||||||
|
TOPOLOGIE_INDEX_SWITCH_BAY = {
|
||||||
|
'switch-bay_name': ['name'],
|
||||||
|
'switch-bay_building': ['building__name'],
|
||||||
|
'default': ['name'],
|
||||||
|
}
|
||||||
TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH = {
|
TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH = {
|
||||||
'room_name': ['name'],
|
'constructor-switch_name': ['name'],
|
||||||
'default': ['name'],
|
'default': ['name'],
|
||||||
}
|
}
|
||||||
LOGS_INDEX = {
|
LOGS_INDEX = {
|
||||||
|
|
|
@ -170,6 +170,8 @@ class CreatePortsForm(forms.Form):
|
||||||
|
|
||||||
class EditModelSwitchForm(FormRevMixin, ModelForm):
|
class EditModelSwitchForm(FormRevMixin, ModelForm):
|
||||||
"""Permet d'éediter un modèle de switch : nom et constructeur"""
|
"""Permet d'éediter un modèle de switch : nom et constructeur"""
|
||||||
|
members = forms.ModelMultipleChoiceField(Switch.objects.all(), required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModelSwitch
|
model = ModelSwitch
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
@ -177,6 +179,14 @@ class EditModelSwitchForm(FormRevMixin, ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(EditModelSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(EditModelSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
instance = kwargs.get('instance', None)
|
||||||
|
if instance:
|
||||||
|
self.initial['members'] = Switch.objects.filter(model=instance)
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
instance = super().save(commit)
|
||||||
|
instance.switch_set = self.cleaned_data['members']
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
class EditConstructorSwitchForm(FormRevMixin, ModelForm):
|
class EditConstructorSwitchForm(FormRevMixin, ModelForm):
|
||||||
|
@ -192,6 +202,8 @@ class EditConstructorSwitchForm(FormRevMixin, ModelForm):
|
||||||
|
|
||||||
class EditSwitchBayForm(FormRevMixin, ModelForm):
|
class EditSwitchBayForm(FormRevMixin, ModelForm):
|
||||||
"""Permet d'éditer une baie de brassage"""
|
"""Permet d'éditer une baie de brassage"""
|
||||||
|
members = forms.ModelMultipleChoiceField(Switch.objects.all(), required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = SwitchBay
|
model = SwitchBay
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
@ -199,6 +211,14 @@ class EditSwitchBayForm(FormRevMixin, ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
super(EditSwitchBayForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(EditSwitchBayForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
instance = kwargs.get('instance', None)
|
||||||
|
if instance:
|
||||||
|
self.initial['members'] = Switch.objects.filter(switchbay=instance)
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
instance = super().save(commit)
|
||||||
|
instance.switch_set = self.cleaned_data['members']
|
||||||
|
return instance
|
||||||
|
|
||||||
|
|
||||||
class EditBuildingForm(FormRevMixin, ModelForm):
|
class EditBuildingForm(FormRevMixin, ModelForm):
|
||||||
|
|
25
topologie/migrations/0057_auto_20180408_0316.py
Normal file
25
topologie/migrations/0057_auto_20180408_0316.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.7 on 2018-04-08 01:16
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('topologie', '0056_building_switchbay'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='switchbay',
|
||||||
|
name='members',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='switch',
|
||||||
|
name='switchbay',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='topologie.SwitchBay'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -136,6 +136,12 @@ class Switch(AclMixin, Machine):
|
||||||
null=True,
|
null=True,
|
||||||
on_delete=models.SET_NULL
|
on_delete=models.SET_NULL
|
||||||
)
|
)
|
||||||
|
switchbay = models.ForeignKey(
|
||||||
|
'topologie.SwitchBay',
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
on_delete=models.SET_NULL
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('stack', 'stack_member_id')
|
unique_together = ('stack', 'stack_member_id')
|
||||||
|
@ -233,11 +239,6 @@ class SwitchBay(AclMixin, RevMixin, models.Model):
|
||||||
'Building',
|
'Building',
|
||||||
on_delete=models.PROTECT
|
on_delete=models.PROTECT
|
||||||
)
|
)
|
||||||
members = models.ManyToManyField(
|
|
||||||
blank=True,
|
|
||||||
to='Switch',
|
|
||||||
related_name='bay_switches'
|
|
||||||
)
|
|
||||||
info = models.CharField(
|
info = models.CharField(
|
||||||
max_length=255,
|
max_length=255,
|
||||||
blank=True,
|
blank=True,
|
||||||
|
|
|
@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{% include "buttons/sort.html" with prefix='switch-bay' col='name' text='Baie' %}</th>
|
<th>{% include "buttons/sort.html" with prefix='switch-bay' col='name' text='Baie' %}</th>
|
||||||
<th>Bâtiment</th>
|
<th>{% include "buttons/sort.html" with prefix='switch-bay' col='building' text='Bâtiment' %}</th>
|
||||||
<th>Info particulières</th>
|
<th>Info particulières</th>
|
||||||
<th>Switchs du batiment</th>
|
<th>Switchs du batiment</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
@ -43,9 +43,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<td>{{switch_bay.name}}</td>
|
<td>{{switch_bay.name}}</td>
|
||||||
<td>{{switch_bay.building}}</td>
|
<td>{{switch_bay.building}}</td>
|
||||||
<td>{{switch_bay.info}}</td>
|
<td>{{switch_bay.info}}</td>
|
||||||
<td>{{switch_bay.members}}</td>
|
<td>{{switch_bay.switch_set.all |join:", "}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'switch-bay' switch_bay.pk %}">
|
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'switchbay' switch_bay.pk %}">
|
||||||
<i class="fa fa-history"></i>
|
<i class="fa fa-history"></i>
|
||||||
</a>
|
</a>
|
||||||
{% can_edit switch_bay %}
|
{% can_edit switch_bay %}
|
||||||
|
|
|
@ -47,6 +47,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<hr>
|
<hr>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% include "topologie/aff_switch_bay.html" with switch_bay_list=switch_bay_list %}
|
{% include "topologie/aff_switch_bay.html" with switch_bay_list=switch_bay_list %}
|
||||||
|
<h2>Batiment</h2>
|
||||||
|
{% can_create Building %}
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-building' %}"><i class="fa fa-plus"></i> Ajouter un bâtiment</a>
|
||||||
|
<hr>
|
||||||
|
{% acl_end %}
|
||||||
|
{% include "topologie/aff_building.html" with building_list=building_list %}
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -36,7 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form class="form" method="post">
|
<form class="form" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% massive_bootstrap_form topoform 'room,related,machine_interface' %}
|
{% massive_bootstrap_form topoform 'room,related,machine_interface,members' %}
|
||||||
{% bootstrap_button action_name button_type="submit" icon="ok" %}
|
{% bootstrap_button action_name button_type="submit" icon="ok" %}
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -109,4 +109,14 @@ urlpatterns = [
|
||||||
url(r'^del_switch_bay/(?P<switchbayid>[0-9]+)$',
|
url(r'^del_switch_bay/(?P<switchbayid>[0-9]+)$',
|
||||||
views.del_switch_bay,
|
views.del_switch_bay,
|
||||||
name='del-switch-bay'),
|
name='del-switch-bay'),
|
||||||
|
url(r'^new_building/$',
|
||||||
|
views.new_building,
|
||||||
|
name='new-building'
|
||||||
|
),
|
||||||
|
url(r'^edit_building/(?P<buildingid>[0-9]+)$',
|
||||||
|
views.edit_building,
|
||||||
|
name='edit-building'),
|
||||||
|
url(r'^del_building/(?P<buildingid>[0-9]+)$',
|
||||||
|
views.del_building,
|
||||||
|
name='del-building'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -205,6 +205,7 @@ def index_model_switch(request):
|
||||||
model_switch_list = ModelSwitch.objects.select_related('constructor')
|
model_switch_list = ModelSwitch.objects.select_related('constructor')
|
||||||
constructor_switch_list = ConstructorSwitch.objects
|
constructor_switch_list = ConstructorSwitch.objects
|
||||||
switch_bay_list = SwitchBay.objects.select_related('building')
|
switch_bay_list = SwitchBay.objects.select_related('building')
|
||||||
|
building_list = Building.objects.all()
|
||||||
model_switch_list = SortTable.sort(
|
model_switch_list = SortTable.sort(
|
||||||
model_switch_list,
|
model_switch_list,
|
||||||
request.GET.get('col'),
|
request.GET.get('col'),
|
||||||
|
@ -217,10 +218,23 @@ def index_model_switch(request):
|
||||||
request.GET.get('order'),
|
request.GET.get('order'),
|
||||||
SortTable.TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH
|
SortTable.TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH
|
||||||
)
|
)
|
||||||
|
building_list = SortTable.sort(
|
||||||
|
building_list,
|
||||||
|
request.GET.get('col'),
|
||||||
|
request.GET.get('order'),
|
||||||
|
SortTable.TOPOLOGIE_INDEX_BUILDING
|
||||||
|
)
|
||||||
|
switch_bay_list = SortTable.sort(
|
||||||
|
switch_bay_list,
|
||||||
|
request.GET.get('col'),
|
||||||
|
request.GET.get('order'),
|
||||||
|
SortTable.TOPOLOGIE_INDEX_SWITCH_BAY
|
||||||
|
)
|
||||||
return render(request, 'topologie/index_model_switch.html', {
|
return render(request, 'topologie/index_model_switch.html', {
|
||||||
'model_switch_list': model_switch_list,
|
'model_switch_list': model_switch_list,
|
||||||
'constructor_switch_list': constructor_switch_list,
|
'constructor_switch_list': constructor_switch_list,
|
||||||
'switch_bay_list': switch_bay_list,
|
'switch_bay_list': switch_bay_list,
|
||||||
|
'building_list' : building_list,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -684,6 +698,49 @@ def del_switch_bay(request, switch_bay, switchbayid):
|
||||||
}, 'topologie/delete.html', request)
|
}, 'topologie/delete.html', request)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_create(Building)
|
||||||
|
def new_building(request):
|
||||||
|
"""Nouveau batiment"""
|
||||||
|
building = EditBuildingForm(request.POST or None)
|
||||||
|
if building.is_valid():
|
||||||
|
building.save()
|
||||||
|
messages.success(request, "Le batiment a été créé")
|
||||||
|
return redirect(reverse('topologie:index-model-switch'))
|
||||||
|
return form({'topoform': building, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_edit(Building)
|
||||||
|
def edit_building(request, building, buildingid):
|
||||||
|
""" Edition d'un batiment"""
|
||||||
|
building = EditBuildingForm(request.POST or None, instance=building)
|
||||||
|
if building.is_valid():
|
||||||
|
if building.changed_data:
|
||||||
|
building.save()
|
||||||
|
messages.success(request, "Le batiment a bien été modifié")
|
||||||
|
return redirect(reverse('topologie:index-model-switch'))
|
||||||
|
return form({'topoform': building, 'action_name' : 'Editer'}, 'topologie/topo.html', request)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_delete(Building)
|
||||||
|
def del_building(request, building, buildingid):
|
||||||
|
""" Suppression d'un batiment"""
|
||||||
|
if request.method == "POST":
|
||||||
|
try:
|
||||||
|
building.delete()
|
||||||
|
messages.success(request, "La batiment a été détruit")
|
||||||
|
except ProtectedError:
|
||||||
|
messages.error(request, "Le batiment %s est affecté à un autre objet,\
|
||||||
|
impossible de la supprimer (switch ou user)" % building)
|
||||||
|
return redirect(reverse('topologie:index-model-switch'))
|
||||||
|
return form({
|
||||||
|
'objet': building,
|
||||||
|
'objet_name': 'Bâtiment'
|
||||||
|
}, 'topologie/delete.html', request)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@can_create(ConstructorSwitch)
|
@can_create(ConstructorSwitch)
|
||||||
def new_constructor_switch(request):
|
def new_constructor_switch(request):
|
||||||
|
|
Loading…
Reference in a new issue