Commit 8afc8e43 authored by Maël Kervella's avatar Maël Kervella

Pep8 compliance on topologie

parent 48d904b6
......@@ -26,6 +26,7 @@
Here are defined some functions to check acl on the application.
"""
def can_view(user):
"""Check if an user can view the application.
......
......@@ -144,7 +144,7 @@ def search_single_word(word, filters, user,
if not User.can_view_all(user)[0]:
filter_users &= Q(id=user.id)
filter_clubs = filter_users
filter_users |= Q(name__icontains=word)
filter_users |= Q(name__icontains=word)
filters['users'] |= filter_users
filters['clubs'] |= filter_clubs
......
......@@ -26,6 +26,7 @@
Here are defined some functions to check acl on the application.
"""
def can_view(user):
"""Check if an user can view the application.
......
......@@ -41,7 +41,7 @@ from machines.forms import (
from django import forms
from django.forms import ModelForm, Form
from django.db.models import Prefetch
from .models import (
from .models import (
Port,
Switch,
Room,
......@@ -54,6 +54,7 @@ from .models import (
)
from re2o.mixins import FormRevMixin
class PortForm(FormRevMixin, ModelForm):
"""Formulaire pour la création d'un port d'un switch
Relié directement au modèle port"""
......@@ -82,32 +83,48 @@ class EditPortForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs):
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')
self.fields['related'].queryset = Port.objects.all()\
self.fields['machine_interface'].queryset = (
Interface.objects.all().select_related('domain__extension')
)
self.fields['related'].queryset = (
Port.objects.all()
.prefetch_related(Prefetch(
'switch__interface_set',
queryset=Interface.objects.select_related('ipv4__ip_type__extension').select_related('domain__extension')
'switch__interface_set',
queryset=(Interface.objects
.select_related('ipv4__ip_type__extension')
.select_related('domain__extension'))
))
)
class AddPortForm(FormRevMixin, ModelForm):
"""Permet d'ajouter un port de switch. Voir EditPortForm pour plus
d'informations"""
class Meta(PortForm.Meta):
fields = ['port', 'room', 'machine_interface', 'related',
'radius', 'vlan_force', 'details']
fields = [
'port',
'room',
'machine_interface',
'related',
'radius',
'vlan_force',
'details'
]
def __init__(self, *args, **kwargs):
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')
self.fields['related'].queryset = Port.objects.all()\
.prefetch_related(Prefetch(
'switch__interface_set',
queryset=Interface.objects.select_related('ipv4__ip_type__extension').select_related('domain__extension')
self.fields['machine_interface'].queryset = (
Interface.objects.all().select_related('domain__extension')
)
self.fields['related'].queryset = (
Port.objects.all().prefetch_related(Prefetch(
'switch__interface_set',
queryset=(Interface.objects
.select_related('ipv4__ip_type__extension')
.select_related('domain__extension'))
))
)
class StackForm(FormRevMixin, ModelForm):
......@@ -170,15 +187,22 @@ class CreatePortsForm(forms.Form):
class EditModelSwitchForm(FormRevMixin, ModelForm):
"""Permet d'éediter un modèle de switch : nom et constructeur"""
members = forms.ModelMultipleChoiceField(Switch.objects.all(), required=False)
members = forms.ModelMultipleChoiceField(
Switch.objects.all(),
required=False
)
class Meta:
model = ModelSwitch
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditModelSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
super(EditModelSwitchForm, self).__init__(
*args,
prefix=prefix,
**kwargs
)
instance = kwargs.get('instance', None)
if instance:
self.initial['members'] = Switch.objects.filter(model=instance)
......@@ -197,13 +221,20 @@ class EditConstructorSwitchForm(FormRevMixin, ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(EditConstructorSwitchForm, self).__init__(*args, prefix=prefix, **kwargs)
super(EditConstructorSwitchForm, self).__init__(
*args,
prefix=prefix,
**kwargs
)
class EditSwitchBayForm(FormRevMixin, ModelForm):
"""Permet d'éditer une baie de brassage"""
members = forms.ModelMultipleChoiceField(Switch.objects.all(), required=False)
members = forms.ModelMultipleChoiceField(
Switch.objects.all(),
required=False
)
class Meta:
model = SwitchBay
fields = '__all__'
......
......@@ -50,6 +50,7 @@ from reversion import revisions as reversion
from machines.models import Machine, Interface, regen
from re2o.mixins import AclMixin, RevMixin
class Stack(AclMixin, RevMixin, models.Model):
"""Un objet stack. Regrouppe des switchs en foreign key
,contient une id de stack, un switch id min et max dans
......@@ -85,12 +86,12 @@ class Stack(AclMixin, RevMixin, models.Model):
class AccessPoint(AclMixin, Machine):
"""Define a wireless AP. Inherit from machines.interfaces
Definition pour une borne wifi , hérite de machines.interfaces
"""
PRETTY_NAME = "Borne WiFi"
location = models.CharField(
location = models.CharField(
max_length=255,
help_text="Détails sur la localisation de l'AP",
blank=True,
......@@ -120,7 +121,6 @@ class Switch(AclMixin, Machine):
id_max de la stack parente"""
PRETTY_NAME = "Switch / Commutateur"
number = models.PositiveIntegerField()
stack = models.ForeignKey(
'topologie.Stack',
......@@ -165,7 +165,8 @@ class Switch(AclMixin, Machine):
ne peut être nul"})
def create_ports(self, begin, end):
""" Crée les ports de begin à end si les valeurs données sont cohérentes. """
""" Crée les ports de begin à end si les valeurs données
sont cohérentes. """
s_begin = s_end = 0
nb_ports = self.ports.count()
......
......@@ -51,12 +51,10 @@ urlpatterns = [
url(r'^switch/(?P<switchid>[0-9]+)$',
views.index_port,
name='index-port'),
url(
r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
url(r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
re2o.views.history,
name='history',
kwargs={'application':'topologie'},
),
kwargs={'application': 'topologie'}),
url(r'^edit_port/(?P<portid>[0-9]+)$', views.edit_port, name='edit-port'),
url(r'^new_port/(?P<switchid>[0-9]+)$', views.new_port, name='new-port'),
url(r'^del_port/(?P<portid>[0-9]+)$', views.del_port, name='del-port'),
......@@ -64,7 +62,9 @@ urlpatterns = [
views.edit_switch,
name='edit-switch'),
url(r'^new_stack/$', views.new_stack, name='new-stack'),
url(r'^index_physical_grouping/$', views.index_physical_grouping, name='index-physical-grouping'),
url(r'^index_physical_grouping/$',
views.index_physical_grouping,
name='index-physical-grouping'),
url(r'^edit_stack/(?P<stackid>[0-9]+)$',
views.edit_stack,
name='edit-stack'),
......@@ -73,16 +73,13 @@ urlpatterns = [
name='del-stack'),
url(r'^index_model_switch/$',
views.index_model_switch,
name='index-model-switch'
),
name='index-model-switch'),
url(r'^index_model_switch/$',
views.index_model_switch,
name='index-model-switch'
),
name='index-model-switch'),
url(r'^new_model_switch/$',
views.new_model_switch,
name='new-model-switch'
),
name='new-model-switch'),
url(r'^edit_model_switch/(?P<modelswitchid>[0-9]+)$',
views.edit_model_switch,
name='edit-model-switch'),
......@@ -91,8 +88,7 @@ urlpatterns = [
name='del-model-switch'),
url(r'^new_constructor_switch/$',
views.new_constructor_switch,
name='new-constructor-switch'
),
name='new-constructor-switch'),
url(r'^edit_constructor_switch/(?P<constructorswitchid>[0-9]+)$',
views.edit_constructor_switch,
name='edit-constructor-switch'),
......@@ -101,8 +97,7 @@ urlpatterns = [
name='del-constructor-switch'),
url(r'^new_switch_bay/$',
views.new_switch_bay,
name='new-switch-bay'
),
name='new-switch-bay'),
url(r'^edit_switch_bay/(?P<switchbayid>[0-9]+)$',
views.edit_switch_bay,
name='edit-switch-bay'),
......@@ -111,8 +106,7 @@ urlpatterns = [
name='del-switch-bay'),
url(r'^new_building/$',
views.new_building,
name='new-building'
),
name='new-building'),
url(r'^edit_building/(?P<buildingid>[0-9]+)$',
views.edit_building,
name='edit-building'),
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment