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

Pep8 compliance on topologie

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