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 %}