8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00

Modifie le model switch

This commit is contained in:
chirac 2016-10-26 14:05:40 +02:00
parent 62721032e8
commit 3442680933
8 changed files with 76 additions and 15 deletions

View file

@ -100,7 +100,7 @@ class ExtensionForm(ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(ExtensionForm, self).__init__(*args, **kwargs) super(ExtensionForm, self).__init__(*args, **kwargs)
self.fields['name'].label = 'Exstension à ajouter' self.fields['name'].label = 'Extension à ajouter'
class DelExtensionForm(ModelForm): class DelExtensionForm(ModelForm):
extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple) extensions = forms.ModelMultipleChoiceField(queryset=Extension.objects.all(), label="Extensions actuelles", widget=forms.CheckboxSelectMultiple)

View file

@ -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'),
),
]

View file

@ -5,7 +5,7 @@ from reversion.admin import VersionAdmin
from .models import Port, Room, Switch from .models import Port, Room, Switch
class SwitchAdmin(VersionAdmin): class SwitchAdmin(VersionAdmin):
list_display = ('building','number','details') list_display = ('switch_interface','location','number','details')
class PortAdmin(VersionAdmin): class PortAdmin(VersionAdmin):
list_display = ('switch', 'port','room','machine_interface','details') list_display = ('switch', 'port','room','machine_interface','details')

View file

@ -14,14 +14,19 @@ class AddPortForm(ModelForm):
class Meta(PortForm.Meta): class Meta(PortForm.Meta):
fields = ['port', 'room', 'machine_interface', 'related', 'details'] fields = ['port', 'room', 'machine_interface', 'related', 'details']
class SwitchForm(ModelForm): class EditSwitchForm(ModelForm):
class Meta: class Meta:
model = Switch model = Switch
fields = '__all__' fields = '__all__'
class EditSwitchForm(ModelForm): def __init__(self, *args, **kwargs):
class Meta(SwitchForm.Meta): super(EditSwitchForm, self).__init__(*args, **kwargs)
fields = ['building', 'number', 'details'] 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 EditRoomForm(ModelForm):
class Meta: class Meta:

View file

@ -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',
),
]

View file

@ -16,15 +16,13 @@ def clean_port_related(port):
related_port.save() related_port.save()
class Switch(models.Model): 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() number = models.IntegerField()
details = models.CharField(max_length=255, blank=True) details = models.CharField(max_length=255, blank=True)
class Meta:
unique_together = ('building', 'number')
def __str__(self): def __str__(self):
return str(self.building) + str(self.number) return str(self.location)
class Port(models.Model): class Port(models.Model):
switch = models.ForeignKey('Switch', related_name="ports") switch = models.ForeignKey('Switch', related_name="ports")

View file

@ -1,15 +1,19 @@
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Bâtiment</th> <th>Dns</th>
<th>Numero</th> <th>Ipv4</th>
<th>Localisation</th>
<th>Nombre de ports</th>
<th>Détails</th> <th>Détails</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for switch in switch_list %} {% for switch in switch_list %}
<tr> <tr>
<td>{{switch.building}}</td> <td>{{switch.switch_interface.dns}}</td>
<td>{{switch.switch_interface.ipv4}}</td>
<td>{{switch.location}}</td>
<td>{{switch.number}}</td> <td>{{switch.number}}</td>
<td>{{switch.details}}</td> <td>{{switch.details}}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:index-port' switch.pk %}"><i class="glyphicon glyphicon-cog"></i> Configurer</a> <td><a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:index-port' switch.pk %}"><i class="glyphicon glyphicon-cog"></i> Configurer</a>

View file

@ -15,7 +15,7 @@ from re2o.settings import PAGINATION_NUMBER
@login_required @login_required
@permission_required('cableur') @permission_required('cableur')
def index(request): 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}) return render(request, 'topologie/index.html', {'switch_list': switch_list})
@login_required @login_required