8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Fix divers sur la creation de port

This commit is contained in:
Gabriel Detraz 2018-03-26 22:11:03 +02:00 committed by root
parent 02240a8fce
commit 3ce73a7a46
3 changed files with 12 additions and 7 deletions

View file

@ -80,9 +80,10 @@ class EditPortForm(ModelForm):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditPortForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['machine_interface'].queryset = Interface.objects.all()\
.select_related('domain__extension')
.select_related('domain__extension')
self.fields['related'].queryset = Port.objects.all()\
.select_related('switch__domain__extension')\
.select_related('switch')\
.prefetch_related('switch__interface_set__domain__extension')\
.order_by('switch', 'port')
@ -97,9 +98,10 @@ class AddPortForm(ModelForm):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(AddPortForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['machine_interface'].queryset = Interface.objects.all()\
.select_related('domain__extension')
.select_related('domain__extension')
self.fields['related'].queryset = Port.objects.all()\
.select_related('switch__domain__extension')\
.select_related('switch')\
.prefetch_related('switch__interface_set__domain__extension')\
.order_by('switch', 'port')

View file

@ -263,6 +263,9 @@ class Switch(Machine):
except IntegrityError:
ValidationError("Création d'un port existant.")
def __str__(self):
return str(self.interface_set.first())
class ModelSwitch(models.Model):
"""Un modèle (au sens constructeur) de switch"""
@ -416,11 +419,11 @@ class Port(models.Model):
def get_instance(port_id, *args, **kwargs):
return Port.objects\
.select_related('switch__domain__extension')\
.select_related('machine_interface__domain__extension')\
.select_related('machine_interface__switch')\
.select_related('machine_interface__machine__switch')\
.select_related('room')\
.select_related('related')\
.prefetch_related('switch__interface_set__domain__extension')\
.get(pk=port_id)
def can_create(user_request, *args, **kwargs):

View file

@ -46,7 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<td>
<a title="Configuer" href="{% url 'topologie:index-port' switch.pk %}">
{{switch.interface_set.first}}
{{switch}}
</a>
</td>
<td>{{switch.interface_set.first.ipv4}}</td>