mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 00:43:46 +00:00
Profile default different for dormitories (option)
This commit is contained in:
parent
a51c5f4b57
commit
3ec4fdd9d9
3 changed files with 54 additions and 4 deletions
34
topologie/migrations/0072_auto_20190720_2318.py
Normal file
34
topologie/migrations/0072_auto_20190720_2318.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.7 on 2019-07-20 21:18
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('topologie', '0071_auto_20190218_1936'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name='room',
|
||||
options={'ordering': ['building__name'], 'permissions': (('view_room', 'Can view a room object'),), 'verbose_name': 'room', 'verbose_name_plural': 'rooms'},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='portprofile',
|
||||
name='on_dormitory',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dormitory_ofprofil', to='topologie.Dormitory', verbose_name='Profil on dormitory'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='portprofile',
|
||||
name='profil_default',
|
||||
field=models.CharField(blank=True, choices=[('room', 'Room'), ('access_point', 'Access point'), ('uplink', 'Uplink'), ('asso_machine', 'Organisation machine'), ('nothing', 'Nothing')], max_length=32, null=True, verbose_name='Default profile'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='portprofile',
|
||||
unique_together=set([('on_dormitory', 'profil_default')]),
|
||||
),
|
||||
]
|
|
@ -650,7 +650,7 @@ class Port(AclMixin, RevMixin, models.Model):
|
|||
:returns: the profile of self (port)"""
|
||||
def profile_or_nothing(profile):
|
||||
port_profile = PortProfile.objects.filter(
|
||||
profil_default=profile).first()
|
||||
profil_default=profile).filter(switch__switchbay__building__dormitory).first()
|
||||
if port_profile:
|
||||
return port_profile
|
||||
else:
|
||||
|
@ -791,9 +791,16 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
|||
choices=PROFIL_DEFAULT,
|
||||
blank=True,
|
||||
null=True,
|
||||
unique=True,
|
||||
verbose_name=_("Default profile")
|
||||
)
|
||||
on_dormitory = models.ForeignKey(
|
||||
'topologie.Dormitory',
|
||||
related_name='dormitory_ofprofil',
|
||||
on_delete=models.SET_NULL,
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name=_("Profil on dormitory")
|
||||
)
|
||||
vlan_untagged = models.ForeignKey(
|
||||
'machines.Vlan',
|
||||
related_name='vlan_untagged',
|
||||
|
@ -871,6 +878,7 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
|||
)
|
||||
verbose_name = _("port profile")
|
||||
verbose_name_plural = _("port profiles")
|
||||
unique_together = ['on_dormitory', 'profil_default']
|
||||
|
||||
security_parameters_fields = [
|
||||
'loop_protect',
|
||||
|
@ -893,6 +901,14 @@ class PortProfile(AclMixin, RevMixin, models.Model):
|
|||
def security_parameters_as_str(self):
|
||||
return ','.join(self.security_parameters_enabled)
|
||||
|
||||
def clean(self):
|
||||
""" Check that there is only one generic profil default"""
|
||||
super(PortProfile, self).clean()
|
||||
if self.profil_default and not self.on_dormitory and PortProfile.objects.exclude(id=self.id).filter(profil_default=self.profil_default).exclude(on_dormitory__isnull=False).exists():
|
||||
raise ValidationError(
|
||||
{'profil_default': _("A default profile for all dormitory of that type already exists.")}
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Name" %}</th>
|
||||
<th>{% trans "Default for" %}</th>
|
||||
<th>{% trans "Default for and place" %}</th>
|
||||
<th>{% trans "VLANs" %}</th>
|
||||
<th>{% trans "RADIUS settings" %}</th>
|
||||
<th>{% trans "Speed limit" %}</th>
|
||||
|
@ -47,7 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% for port_profile in port_profile_list %}
|
||||
<tr>
|
||||
<td>{{ port_profile.name }}</td>
|
||||
<td>{{ port_profile.profil_default }}</td>
|
||||
<td>{{ port_profile.profil_default }} {% if port_profile.profil_default%}<b> - {% if port_profile.on_dormitory %} on {{ port_profile.on_dormitory }} {% else %} Everywhere {% endif %}</b>{% endif %}</td>
|
||||
<td>
|
||||
{% if port_profile.vlan_untagged %}
|
||||
<b>{% trans "Untagged: " %}</b>{{ port_profile.vlan_untagged }}
|
||||
|
|
Loading…
Reference in a new issue