8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 03:16:25 +00:00

Bornes hérite de machine

This commit is contained in:
Gabriel Detraz 2018-03-26 03:09:42 +02:00 committed by chirac
parent 43ff16ccb9
commit 119416cc4f
7 changed files with 119 additions and 50 deletions

View file

@ -234,10 +234,10 @@ class SortTable:
'default': ['name']
}
TOPOLOGIE_INDEX_BORNE = {
'ap_name': ['domain__name'],
'ap_ip': ['ipv4__ipv4'],
'ap_mac': ['mac_address'],
'default': ['domain__name']
'ap_name': ['interface__domain__name'],
'ap_ip': ['interface__ipv4__ipv4'],
'ap_mac': ['interface__mac_address'],
'default': ['interface__domain__name']
}
TOPOLOGIE_INDEX_STACK = {
'stack_name': ['name'],

View file

@ -33,7 +33,11 @@ NewSwitchForm)
from __future__ import unicode_literals
from machines.models import Interface
from machines.forms import EditInterfaceForm
from machines.forms import (
EditInterfaceForm,
EditMachineForm,
NewMachineForm
)
from django import forms
from django.forms import ModelForm, Form
from .models import (
@ -111,19 +115,19 @@ class StackForm(ModelForm):
super(StackForm, self).__init__(*args, prefix=prefix, **kwargs)
class AddAccessPointForm(EditInterfaceForm):
class AddAccessPointForm(NewMachineForm):
"""Formulaire pour la création d'une borne
Relié directement au modèle borne"""
class Meta:
model = AccessPoint
fields = ['mac_address', 'type', 'ipv4', 'details', 'location']
fields = ['location', 'name']
class EditAccessPointForm(EditInterfaceForm):
"""Edition d'une interface. Edition complète"""
class EditAccessPointForm(EditMachineForm):
"""Edition d'une borne. Edition complète"""
class Meta:
model = AccessPoint
fields = ['machine', 'type', 'ipv4', 'mac_address', 'details', 'location']
fields = '__all__'
class EditSwitchForm(EditInterfaceForm):

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-03-23 01:18
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('topologie', '0046_auto_20180326_0129'),
]
operations = [
migrations.CreateModel(
name='NewAccessPoint',
fields=[
('machine_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='machines.Machine')),
('location', models.CharField(help_text="Détails sur la localisation de l'AP", max_length=255, null=True, blank=True)),
],
bases=('machines.machine',),
),
]

View file

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-03-23 01:18
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('topologie', '0047_ap_machine'),
]
def transfer_ap(apps, schema_editor):
db_alias = schema_editor.connection.alias
ap = apps.get_model("topologie", "AccessPoint")
new_ap = apps.get_model("topologie", "NewAccessPoint")
ap_list = ap.objects.using(db_alias).all()
for borne in ap_list:
new_borne = new_ap()
new_borne.machine_ptr_id = borne.machine.pk
new_borne.__dict__.update(borne.machine.__dict__)
new_borne.location = borne.location
new_borne.save()
def untransfer_ap(apps, schema_editor):
return
operations = [
migrations.RunPython(transfer_ap, untransfer_ap),
migrations.DeleteModel(
name='AccessPoint',
),
migrations.RenameModel(
old_name='NewAccessPoint',
new_name='AccessPoint',
),
]

View file

@ -47,7 +47,7 @@ from django.db import IntegrityError
from django.db import transaction
from reversion import revisions as reversion
from machines.models import Interface
from machines.models import Machine, Interface
class Stack(models.Model):
"""Un objet stack. Regrouppe des switchs en foreign key
@ -109,7 +109,7 @@ class Stack(models.Model):
inférieure à l'id minimale"})
class AccessPoint(Interface):
class AccessPoint(Machine):
"""Define a wireless AP. Inherit from machines.interfaces
Definition pour une borne wifi , hérite de machines.interfaces

View file

@ -43,10 +43,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</thead>
{% for ap in ap_list %}
<tr>
<td>{{ap}}</td>
<td>{{ap.mac_address}}</td>
<td>{{ap.ipv4}}</td>
<td>{{ap.details}}</td>
<td>{{ap.interface_set.first}}</td>
<td>{{ap.interface_set.first.mac_address}}</td>
<td>{{ap.interface_set.first.ipv4}}</td>
<td>{{ap.interface_set.first.details}}</td>
<td>{{ap.location}}</td>
<td class="text-right">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'ap' ap.pk %}">
@ -58,7 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</a>
{% acl_end %}
{% can_delete ap %}
<a class="btn btn-danger btn-sm" role="button" title="Supprimer" href="{% url 'machines:del-interface' ap.id %}">
<a class="btn btn-danger btn-sm" role="button" title="Supprimer" href="{% url 'machines:del-machine' ap.id %}">
<i class="fa fa-trash"></i>
</a>
{% acl_end %}

View file

@ -535,45 +535,45 @@ def new_ap(request):
request.POST or None,
user=request.user
)
machine = NewMachineForm(
interface = AddInterfaceForm(
request.POST or None,
user=request.user
)
domain = DomainForm(
request.POST or None,
)
if ap.is_valid() and machine.is_valid():
if ap.is_valid() and interface.is_valid():
user = AssoOption.get_cached_value('utilisateur_asso')
if not user:
messages.error(request, "L'user association n'existe pas encore,\
veuillez le créer ou le linker dans preferences")
return redirect(reverse('topologie:index'))
new_machine = machine.save(commit=False)
new_machine.user = user
new_ap = ap.save(commit=False)
domain.instance.interface_parent = new_ap
new_ap.user = user
new_interface = interface.save(commit=False)
domain.instance.interface_parent = new_interface
if domain.is_valid():
new_domain_instance = domain.save(commit=False)
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_ap.machine = new_machine
with transaction.atomic(), reversion.create_revision():
new_ap.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_domain_instance.interface_parent = new_ap
new_interface.machine = new_ap
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
new_domain_instance.interface_parent = new_interface
with transaction.atomic(), reversion.create_revision():
new_domain_instance.save()
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "La borne a été créé")
return redirect(reverse('topologie:index-ap'))
i_mbf_param = generate_ipv4_mbf_param(ap, False)
i_mbf_param = generate_ipv4_mbf_param(interface, False)
return form({
'topoform': ap,
'machineform': machine,
'topoform': interface,
'machineform': ap,
'domainform': domain,
'i_mbf_param': i_mbf_param,
'device' : 'wifi ap',
@ -585,42 +585,42 @@ def new_ap(request):
def edit_ap(request, ap, ap_id):
""" Edition d'un switch. Permet de chambre nombre de ports,
place dans le stack, interface et machine associée"""
interface_form = EditInterfaceForm(
request.POST or None,
user=request.user,
instance=ap.interface_set.first()
)
ap_form = EditAccessPointForm(
request.POST or None,
user=request.user,
instance=ap
)
machine_form = NewMachineForm(
request.POST or None,
user=request.user,
instance=ap.machine
)
domain_form = DomainForm(
request.POST or None,
instance=ap.domain
instance=ap.interface_set.first().domain
)
if ap_form.is_valid() and machine_form.is_valid():
if ap_form.is_valid() and interface_form.is_valid():
user = AssoOption.get_cached_value('utilisateur_asso')
if not user:
messages.error(request, "L'user association n'existe pas encore,\
veuillez le créer ou le linker dans preferences")
return redirect(reverse('topologie:index-ap'))
new_machine = machine_form.save(commit=False)
new_ap = ap_form.save(commit=False)
new_interface = interface_form.save(commit=False)
new_domain = domain_form.save(commit=False)
with transaction.atomic(), reversion.create_revision():
new_machine.save()
reversion.set_user(request.user)
reversion.set_comment(
"Champs modifié(s) : %s" % ', '.join(
field for field in machine_form.changed_data)
)
with transaction.atomic(), reversion.create_revision():
new_ap.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
reversion.set_comment(
"Champs modifié(s) : %s" % ', '.join(
field for field in ap_form.changed_data)
)
with transaction.atomic(), reversion.create_revision():
new_interface.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for field in interface_form.changed_data)
)
reversion.set_comment("Création")
with transaction.atomic(), reversion.create_revision():
new_domain.save()
@ -630,10 +630,10 @@ def edit_ap(request, ap, ap_id):
)
messages.success(request, "La borne a été modifiée")
return redirect(reverse('topologie:index-ap'))
i_mbf_param = generate_ipv4_mbf_param(ap_form, False )
i_mbf_param = generate_ipv4_mbf_param(interface_form, False )
return form({
'topoform': ap_form,
'machineform': machine_form,
'topoform': interface_form,
'machineform': ap_form,
'domainform': domain_form,
'i_mbf_param': i_mbf_param,
'device' : 'wifi ap',