mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Edition fine des modules pour chaque switchs avec le slot
This commit is contained in:
parent
4dbbb00cf7
commit
683cf229e9
7 changed files with 105 additions and 29 deletions
|
@ -55,7 +55,8 @@ from .models import (
|
||||||
SwitchBay,
|
SwitchBay,
|
||||||
Building,
|
Building,
|
||||||
PortProfile,
|
PortProfile,
|
||||||
ModuleSwitch
|
ModuleSwitch,
|
||||||
|
ModuleOnSwitch,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -279,14 +280,14 @@ class EditModuleForm(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(EditModuleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
super(EditModuleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
self.fields['switchs'].queryset = (Switch.objects.filter(model__is_modular=True))
|
|
||||||
|
|
||||||
def save(self, commit=True):
|
|
||||||
# TODO : None of the parents of ServiceForm use the commit
|
|
||||||
# parameter in .save()
|
|
||||||
instance = super(EditModuleForm, self).save(commit=False)
|
|
||||||
if commit:
|
|
||||||
instance.save()
|
|
||||||
instance.process_link(self.cleaned_data.get('switchs'))
|
|
||||||
return instance
|
|
||||||
|
|
||||||
|
class EditSwitchModuleForm(FormRevMixin, ModelForm):
|
||||||
|
"""Add/edit a switch to a module"""
|
||||||
|
class Meta:
|
||||||
|
model = ModuleOnSwitch
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
|
||||||
|
super(EditSwitchModuleForm, self).__init__(*args, prefix=prefix, **kwargs)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.10.7 on 2018-12-30 14:56
|
# Generated by Django 1.10.7 on 2018-12-30 17:19
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
@ -32,7 +32,6 @@ class Migration(migrations.Migration):
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('reference', models.CharField(help_text='Reference of a module', max_length=255, verbose_name='Module reference')),
|
('reference', models.CharField(help_text='Reference of a module', max_length=255, verbose_name='Module reference')),
|
||||||
('comment', models.CharField(blank=True, help_text='Comment', max_length=255, null=True, verbose_name='Comment')),
|
('comment', models.CharField(blank=True, help_text='Comment', max_length=255, null=True, verbose_name='Comment')),
|
||||||
('switchs', models.ManyToManyField(through='topologie.ModuleOnSwitch', to='topologie.Switch')),
|
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
'verbose_name': 'Module of a switch',
|
'verbose_name': 'Module of a switch',
|
||||||
|
@ -60,4 +59,8 @@ class Migration(migrations.Migration):
|
||||||
name='switch',
|
name='switch',
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='topologie.Switch'),
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='topologie.Switch'),
|
||||||
),
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='moduleonswitch',
|
||||||
|
unique_together=set([('slot', 'switch')]),
|
||||||
|
),
|
||||||
]
|
]
|
|
@ -438,7 +438,6 @@ class ModuleSwitch(AclMixin, RevMixin, models.Model):
|
||||||
help_text=_("Comment"),
|
help_text=_("Comment"),
|
||||||
verbose_name=_("Comment")
|
verbose_name=_("Comment")
|
||||||
)
|
)
|
||||||
switchs = models.ManyToManyField('Switch', through='ModuleOnSwitch')
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = (
|
||||||
|
@ -446,17 +445,6 @@ class ModuleSwitch(AclMixin, RevMixin, models.Model):
|
||||||
)
|
)
|
||||||
verbose_name = _("Module of a switch")
|
verbose_name = _("Module of a switch")
|
||||||
|
|
||||||
def process_link(self, switchs):
|
|
||||||
"""Django can't create itself foreignkey with explicit through"""
|
|
||||||
ModuleOnSwitch.objects.bulk_create(
|
|
||||||
[ModuleOnSwitch(
|
|
||||||
module=self, switch=sw
|
|
||||||
) for sw in switchs.exclude(
|
|
||||||
pk__in=Switch.objects.filter(moduleswitch=self)
|
|
||||||
)]
|
|
||||||
)
|
|
||||||
ModuleOnSwitch.objects.filter(module=self).exclude(switch__in=switchs).delete()
|
|
||||||
return
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.reference)
|
return str(self.reference)
|
||||||
|
@ -477,6 +465,10 @@ class ModuleOnSwitch(AclMixin, RevMixin, models.Model):
|
||||||
("view_moduleonswitch", _("Can view a moduleonswitch object")),
|
("view_moduleonswitch", _("Can view a moduleonswitch object")),
|
||||||
)
|
)
|
||||||
verbose_name = _("link between switchs and modules")
|
verbose_name = _("link between switchs and modules")
|
||||||
|
unique_together = ['slot', 'switch']
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'On slot ' + str(self.slot) + ' of ' + str(self.switch)
|
||||||
|
|
||||||
|
|
||||||
class ConstructorSwitch(AclMixin, RevMixin, models.Model):
|
class ConstructorSwitch(AclMixin, RevMixin, models.Model):
|
||||||
|
|
|
@ -43,9 +43,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ module.reference }}</td>
|
<td>{{ module.reference }}</td>
|
||||||
<td>{{ module.comment }}</td>
|
<td>{{ module.comment }}</td>
|
||||||
<td>{{ module.switchs.all }}</td>
|
<td>
|
||||||
|
{% for module_switch in module.moduleonswitch_set.all %}
|
||||||
|
<b>Slot</b> {{ module_switch.slot }} <b>of</b> {{ module_switch.switch }}
|
||||||
|
{% can_edit module_switch %}
|
||||||
|
<a class="btn btn-primary btn-xs" role="button" title={% trans "Edit" %} href="{% url 'topologie:edit-module-on' module_switch.id %}">
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
</a>
|
||||||
|
{% acl_end %}
|
||||||
|
{% can_delete module_switch %}
|
||||||
|
<a class="btn btn-danger btn-xs" role="button" title={% trans "Delete" %} href="{% url 'topologie:del-module-on' module_switch.id %}">
|
||||||
|
<i class="fa fa-trash"></i>
|
||||||
|
</a>
|
||||||
|
{% acl_end %}
|
||||||
|
<br>
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
{% can_edit module %}
|
{% can_edit module %}
|
||||||
|
<a class="btn btn-primary btn-sm" role="button" title={% trans "Add" %} href="{% url 'topologie:add-module-on' %}">
|
||||||
|
<i class="fa fa-plus"></i>
|
||||||
|
</a>
|
||||||
<a class="btn btn-primary btn-sm" role="button" title={% trans "Edit" %} href="{% url 'topologie:edit-module' module.id %}">
|
<a class="btn btn-primary btn-sm" role="button" title={% trans "Edit" %} href="{% url 'topologie:edit-module' module.id %}">
|
||||||
<i class="fa fa-edit"></i>
|
<i class="fa fa-edit"></i>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -37,7 +37,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,members,vlan_tagged,switchs' %}
|
{% massive_bootstrap_form topoform 'room,related,machine_interface,members,vlan_tagged,switch' %}
|
||||||
{% bootstrap_button action_name icon='ok' button_class='btn-success' %}
|
{% bootstrap_button action_name icon='ok' button_class='btn-success' %}
|
||||||
</form>
|
</form>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -124,9 +124,14 @@ urlpatterns = [
|
||||||
views.edit_vlanoptions,
|
views.edit_vlanoptions,
|
||||||
name='edit-vlanoptions'),
|
name='edit-vlanoptions'),
|
||||||
url(r'^add_module/$', views.add_module, name='add-module'),
|
url(r'^add_module/$', views.add_module, name='add-module'),
|
||||||
url(r'^edit_module/(?P<moduleid>[0-9]+)$',
|
url(r'^edit_module/(?P<moduleswitchid>[0-9]+)$',
|
||||||
views.edit_module,
|
views.edit_module,
|
||||||
name='edit-module'),
|
name='edit-module'),
|
||||||
url(r'^del_module/(?P<moduleid>[0-9]+)$', views.del_module, name='del-module'),
|
url(r'^del_module/(?P<moduleswitchid>[0-9]+)$', views.del_module, name='del-module'),
|
||||||
url(r'^index_module/$', views.index_module, name='index-module'),
|
url(r'^index_module/$', views.index_module, name='index-module'),
|
||||||
|
url(r'^add_module_on/$', views.add_module_on, name='add-module-on'),
|
||||||
|
url(r'^edit_module_on/(?P<moduleonswitchid>[0-9]+)$',
|
||||||
|
views.edit_module_on,
|
||||||
|
name='edit-module-on'),
|
||||||
|
url(r'^del_module_on/(?P<moduleonswitchid>[0-9]+)$', views.del_module_on, name='del-module-on'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -87,6 +87,7 @@ from .models import (
|
||||||
Server,
|
Server,
|
||||||
PortProfile,
|
PortProfile,
|
||||||
ModuleSwitch,
|
ModuleSwitch,
|
||||||
|
ModuleOnSwitch,
|
||||||
)
|
)
|
||||||
from .forms import (
|
from .forms import (
|
||||||
EditPortForm,
|
EditPortForm,
|
||||||
|
@ -103,7 +104,8 @@ from .forms import (
|
||||||
EditSwitchBayForm,
|
EditSwitchBayForm,
|
||||||
EditBuildingForm,
|
EditBuildingForm,
|
||||||
EditPortProfileForm,
|
EditPortProfileForm,
|
||||||
EditModuleForm
|
EditModuleForm,
|
||||||
|
EditSwitchModuleForm,
|
||||||
)
|
)
|
||||||
|
|
||||||
from subprocess import (
|
from subprocess import (
|
||||||
|
@ -1064,6 +1066,7 @@ def del_port_profile(request, port_profile, **_kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
@can_create(ModuleSwitch)
|
@can_create(ModuleSwitch)
|
||||||
def add_module(request):
|
def add_module(request):
|
||||||
""" View used to add a Module object """
|
""" View used to add a Module object """
|
||||||
|
@ -1117,6 +1120,60 @@ def del_module(request, module, **_kwargs):
|
||||||
request
|
request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_create(ModuleOnSwitch)
|
||||||
|
def add_module_on(request):
|
||||||
|
"""Add a module to a switch"""
|
||||||
|
module_switch = EditSwitchModuleForm(request.POST or None)
|
||||||
|
if module_switch.is_valid():
|
||||||
|
module_switch.save()
|
||||||
|
messages.success(request, _("The module added to that switch"))
|
||||||
|
return redirect(reverse('topologie:index-module'))
|
||||||
|
return form(
|
||||||
|
{'topoform': module_switch, 'action_name': _("Create")},
|
||||||
|
'topologie/topo.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_edit(ModuleOnSwitch)
|
||||||
|
def edit_module_on(request, module_instance, **_kwargs):
|
||||||
|
""" View used to edit a Module object """
|
||||||
|
module = EditSwitchModuleForm(request.POST or None, instance=module_instance)
|
||||||
|
if module.is_valid():
|
||||||
|
if module.changed_data:
|
||||||
|
module.save()
|
||||||
|
messages.success(request, _("The module was edited."))
|
||||||
|
return redirect(reverse('topologie:index-module'))
|
||||||
|
return form(
|
||||||
|
{'topoform': module, 'action_name': _("Edit")},
|
||||||
|
'topologie/topo.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
@can_delete(ModuleOnSwitch)
|
||||||
|
def del_module_on(request, module, **_kwargs):
|
||||||
|
"""Compleete delete a module"""
|
||||||
|
if request.method == "POST":
|
||||||
|
try:
|
||||||
|
module.delete()
|
||||||
|
messages.success(request, _("The module was deleted."))
|
||||||
|
except ProtectedError:
|
||||||
|
messages.error(
|
||||||
|
request,
|
||||||
|
(_("The module %s is used by another object, impossible to"
|
||||||
|
" deleted it.") % module)
|
||||||
|
)
|
||||||
|
return redirect(reverse('topologie:index-module'))
|
||||||
|
return form(
|
||||||
|
{'objet': module, 'objet_name': _("Module")},
|
||||||
|
'topologie/delete.html',
|
||||||
|
request
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def make_machine_graph():
|
def make_machine_graph():
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue