diff --git a/re2o/utils.py b/re2o/utils.py index a3c1dcb8..fcb4f8a8 100644 --- a/re2o/utils.py +++ b/re2o/utils.py @@ -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'], diff --git a/topologie/forms.py b/topologie/forms.py index 568ddd74..5032d15e 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -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): diff --git a/topologie/migrations/0047_ap_machine.py b/topologie/migrations/0047_ap_machine.py new file mode 100644 index 00000000..f09ca318 --- /dev/null +++ b/topologie/migrations/0047_ap_machine.py @@ -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',), + ), + ] diff --git a/topologie/migrations/0048_ap_machine.py b/topologie/migrations/0048_ap_machine.py new file mode 100644 index 00000000..ed1aa2fd --- /dev/null +++ b/topologie/migrations/0048_ap_machine.py @@ -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', + ), + ] diff --git a/topologie/models.py b/topologie/models.py index d94c5704..76b24652 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -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 diff --git a/topologie/templates/topologie/aff_ap.html b/topologie/templates/topologie/aff_ap.html index b9130a0d..192e5026 100644 --- a/topologie/templates/topologie/aff_ap.html +++ b/topologie/templates/topologie/aff_ap.html @@ -43,10 +43,10 @@ with this program; if not, write to the Free Software Foundation, Inc., {% for ap in ap_list %} - {{ap}} - {{ap.mac_address}} - {{ap.ipv4}} - {{ap.details}} + {{ap.interface_set.first}} + {{ap.interface_set.first.mac_address}} + {{ap.interface_set.first.ipv4}} + {{ap.interface_set.first.details}} {{ap.location}} @@ -58,7 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% acl_end %} {% can_delete ap %} - + {% acl_end %} diff --git a/topologie/views.py b/topologie/views.py index 6102bb66..3fa846df 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -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,41 +585,41 @@ 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( + 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 ap_form.changed_data) + field for field in interface_form.changed_data) ) reversion.set_comment("Création") with transaction.atomic(), reversion.create_revision(): @@ -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',