diff --git a/machines/forms.py b/machines/forms.py index 468b6140..d2818b0d 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -100,7 +100,7 @@ class ExtensionForm(ModelForm): def __init__(self, *args, **kwargs): super(ExtensionForm, self).__init__(*args, **kwargs) - self.fields['name'].label = 'Exstension à ajouter' + self.fields['name'].label = 'Extension à ajouter' class DelExtensionForm(ModelForm): extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple) diff --git a/machines/migrations/0026_auto_20161026_1348.py b/machines/migrations/0026_auto_20161026_1348.py new file mode 100644 index 00000000..bac001ec --- /dev/null +++ b/machines/migrations/0026_auto_20161026_1348.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0025_auto_20161023_0038'), + ] + + operations = [ + migrations.AlterField( + model_name='interface', + name='dns', + field=models.CharField(unique=True, max_length=255, help_text='Obligatoire et unique, ne doit pas comporter de points'), + ), + ] diff --git a/topologie/admin.py b/topologie/admin.py index 6d651876..a3ffa335 100644 --- a/topologie/admin.py +++ b/topologie/admin.py @@ -5,7 +5,7 @@ from reversion.admin import VersionAdmin from .models import Port, Room, Switch class SwitchAdmin(VersionAdmin): - list_display = ('building','number','details') + list_display = ('switch_interface','location','number','details') class PortAdmin(VersionAdmin): list_display = ('switch', 'port','room','machine_interface','details') diff --git a/topologie/forms.py b/topologie/forms.py index eb95ef72..f93d80b4 100644 --- a/topologie/forms.py +++ b/topologie/forms.py @@ -14,14 +14,19 @@ class AddPortForm(ModelForm): class Meta(PortForm.Meta): fields = ['port', 'room', 'machine_interface', 'related', 'details'] -class SwitchForm(ModelForm): +class EditSwitchForm(ModelForm): class Meta: model = Switch fields = '__all__' -class EditSwitchForm(ModelForm): - class Meta(SwitchForm.Meta): - fields = ['building', 'number', 'details'] + def __init__(self, *args, **kwargs): + super(EditSwitchForm, self).__init__(*args, **kwargs) + self.fields['location'].label = 'Localisation' + self.fields['number'].label = 'Nombre de ports' + +class NewSwitchForm(ModelForm): + class Meta(EditSwitchForm.Meta): + fields = ['location', 'number', 'details'] class EditRoomForm(ModelForm): class Meta: diff --git a/topologie/migrations/0019_auto_20161026_1348.py b/topologie/migrations/0019_auto_20161026_1348.py new file mode 100644 index 00000000..f14d5a47 --- /dev/null +++ b/topologie/migrations/0019_auto_20161026_1348.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0026_auto_20161026_1348'), + ('topologie', '0018_room_details'), + ] + + operations = [ + migrations.AddField( + model_name='switch', + name='location', + field=models.CharField(default='test', max_length=255), + preserve_default=False, + ), + migrations.AddField( + model_name='switch', + name='switch_interface', + field=models.OneToOneField(default=1, to='machines.Interface'), + preserve_default=False, + ), + migrations.AlterUniqueTogether( + name='switch', + unique_together=set([]), + ), + migrations.RemoveField( + model_name='switch', + name='building', + ), + ] diff --git a/topologie/models.py b/topologie/models.py index f85f7fa7..ceb06345 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -16,15 +16,13 @@ def clean_port_related(port): related_port.save() class Switch(models.Model): - building = models.CharField(max_length=10) + switch_interface = models.OneToOneField('machines.Interface', on_delete=models.CASCADE) + location = models.CharField(max_length=255) number = models.IntegerField() details = models.CharField(max_length=255, blank=True) - class Meta: - unique_together = ('building', 'number') - def __str__(self): - return str(self.building) + str(self.number) + return str(self.location) class Port(models.Model): switch = models.ForeignKey('Switch', related_name="ports") diff --git a/topologie/templates/topologie/aff_switch.html b/topologie/templates/topologie/aff_switch.html index cc80b12e..1b962bed 100644 --- a/topologie/templates/topologie/aff_switch.html +++ b/topologie/templates/topologie/aff_switch.html @@ -1,15 +1,19 @@ - - + + + + {% for switch in switch_list %} - + + +
BâtimentNumeroDnsIpv4LocalisationNombre de ports Détails
{{switch.building}}{{switch.switch_interface.dns}}{{switch.switch_interface.ipv4}}{{switch.location}} {{switch.number}} {{switch.details}} Configurer diff --git a/topologie/views.py b/topologie/views.py index cd1eca54..297c3eaa 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -15,7 +15,7 @@ from re2o.settings import PAGINATION_NUMBER @login_required @permission_required('cableur') def index(request): - switch_list = Switch.objects.order_by('building', 'number') + switch_list = Switch.objects.order_by('location') return render(request, 'topologie/index.html', {'switch_list': switch_list}) @login_required