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

Pep8 compliance on topologie

This commit is contained in:
Maël Kervella 2018-04-14 00:20:44 +00:00
parent 48d904b6de
commit 8afc8e4304
7 changed files with 357 additions and 183 deletions

View file

@ -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.

View file

@ -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

View file

@ -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.

View file

@ -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 (
) )
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):
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):
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):
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__'

View file

@ -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):
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):
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):
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()

View file

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

View file

@ -93,12 +93,14 @@ from preferences.models import AssoOption, GeneralOption
@can_view_all(Switch) @can_view_all(Switch)
def index(request): def index(request):
""" Vue d'affichage de tous les swicthes""" """ Vue d'affichage de tous les swicthes"""
switch_list = Switch.objects\ switch_list = (Switch.objects
.prefetch_related(Prefetch( .prefetch_related(Prefetch(
'interface_set', '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('stack') .select_related('domain__extension'))
))
.select_related('stack'))
switch_list = SortTable.sort( switch_list = SortTable.sort(
switch_list, switch_list,
request.GET.get('col'), request.GET.get('col'),
@ -107,9 +109,11 @@ def index(request):
) )
pagination_number = GeneralOption.get_cached_value('pagination_number') pagination_number = GeneralOption.get_cached_value('pagination_number')
switch_list = re2o_paginator(request, switch_list, pagination_number) switch_list = re2o_paginator(request, switch_list, pagination_number)
return render(request, 'topologie/index.html', { return render(
'switch_list': switch_list request,
}) 'topologie/index.html',
{'switch_list': switch_list}
)
@login_required @login_required
@ -117,27 +121,33 @@ def index(request):
@can_view(Switch) @can_view(Switch)
def index_port(request, switch, switchid): def index_port(request, switch, switchid):
""" Affichage de l'ensemble des ports reliés à un switch particulier""" """ Affichage de l'ensemble des ports reliés à un switch particulier"""
port_list = Port.objects.filter(switch=switch)\ port_list = (Port.objects
.select_related('room')\ .filter(switch=switch)
.select_related('machine_interface__domain__extension')\ .select_related('room')
.select_related('machine_interface__machine__user')\ .select_related('machine_interface__domain__extension')
.select_related('related__switch')\ .select_related('machine_interface__machine__user')
.prefetch_related(Prefetch( .select_related('related__switch')
'related__switch__interface_set', .prefetch_related(Prefetch(
queryset=Interface.objects.select_related('domain__extension') 'related__switch__interface_set',
))\ queryset=(Interface.objects
.select_related('switch') .select_related('domain__extension'))
))
.select_related('switch'))
port_list = SortTable.sort( port_list = SortTable.sort(
port_list, port_list,
request.GET.get('col'), request.GET.get('col'),
request.GET.get('order'), request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX_PORT SortTable.TOPOLOGIE_INDEX_PORT
) )
return render(request, 'topologie/index_p.html', { return render(
'port_list': port_list, request,
'id_switch': switchid, 'topologie/index_p.html',
'nom_switch': switch {
}) 'port_list': port_list,
'id_switch': switchid,
'nom_switch': switch
}
)
@login_required @login_required
@ -153,20 +163,24 @@ def index_room(request):
) )
pagination_number = GeneralOption.get_cached_value('pagination_number') pagination_number = GeneralOption.get_cached_value('pagination_number')
room_list = re2o_paginator(request, room_list, pagination_number) room_list = re2o_paginator(request, room_list, pagination_number)
return render(request, 'topologie/index_room.html', { return render(
'room_list': room_list request,
}) 'topologie/index_room.html',
{'room_list': room_list}
)
@login_required @login_required
@can_view_all(AccessPoint) @can_view_all(AccessPoint)
def index_ap(request): def index_ap(request):
""" Affichage de l'ensemble des bornes""" """ Affichage de l'ensemble des bornes"""
ap_list = AccessPoint.objects\ ap_list = (AccessPoint.objects
.prefetch_related(Prefetch( .prefetch_related(Prefetch(
'interface_set', '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'))
)))
ap_list = SortTable.sort( ap_list = SortTable.sort(
ap_list, ap_list,
request.GET.get('col'), request.GET.get('col'),
@ -175,9 +189,11 @@ def index_ap(request):
) )
pagination_number = GeneralOption.get_cached_value('pagination_number') pagination_number = GeneralOption.get_cached_value('pagination_number')
ap_list = re2o_paginator(request, ap_list, pagination_number) ap_list = re2o_paginator(request, ap_list, pagination_number)
return render(request, 'topologie/index_ap.html', { return render(
'ap_list': ap_list request,
}) 'topologie/index_ap.html',
{'ap_list': ap_list}
)
@login_required @login_required
@ -186,8 +202,10 @@ def index_ap(request):
@can_view_all(SwitchBay) @can_view_all(SwitchBay)
def index_physical_grouping(request): def index_physical_grouping(request):
"""Affichage de la liste des stacks (affiche l'ensemble des switches)""" """Affichage de la liste des stacks (affiche l'ensemble des switches)"""
stack_list = Stack.objects\ stack_list = (Stack.objects
.prefetch_related('switch_set__interface_set__domain__extension') .prefetch_related(
'switch_set__interface_set__domain__extension'
))
building_list = Building.objects.all() building_list = Building.objects.all()
switch_bay_list = SwitchBay.objects.select_related('building') switch_bay_list = SwitchBay.objects.select_related('building')
stack_list = SortTable.sort( stack_list = SortTable.sort(
@ -208,11 +226,15 @@ def index_physical_grouping(request):
request.GET.get('order'), request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX_SWITCH_BAY SortTable.TOPOLOGIE_INDEX_SWITCH_BAY
) )
return render(request, 'topologie/index_physical_grouping.html', { return render(
'stack_list': stack_list, request,
'switch_bay_list': switch_bay_list, 'topologie/index_physical_grouping.html',
'building_list' : building_list, {
}) 'stack_list': stack_list,
'switch_bay_list': switch_bay_list,
'building_list': building_list,
}
)
@login_required @login_required
@ -234,10 +256,14 @@ def index_model_switch(request):
request.GET.get('order'), request.GET.get('order'),
SortTable.TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH SortTable.TOPOLOGIE_INDEX_CONSTRUCTOR_SWITCH
) )
return render(request, 'topologie/index_model_switch.html', { return render(
'model_switch_list': model_switch_list, request,
'constructor_switch_list': constructor_switch_list, 'topologie/index_model_switch.html',
}) {
'model_switch_list': model_switch_list,
'constructor_switch_list': constructor_switch_list,
}
)
@login_required @login_required
@ -260,9 +286,12 @@ def new_port(request, switchid):
messages.error(request, "Ce port existe déjà") messages.error(request, "Ce port existe déjà")
return redirect(reverse( return redirect(reverse(
'topologie:index-port', 'topologie:index-port',
kwargs={'switchid':switchid} kwargs={'switchid': switchid}
)) ))
return form({'id_switch': switchid,'topoform': port, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request) return form(
{'id_switch': switchid, 'topoform': port, 'action_name': 'Ajouter'},
'topologie/topo.html',
request)
@login_required @login_required
@ -279,8 +308,16 @@ def edit_port(request, port_object, portid):
return redirect(reverse( return redirect(reverse(
'topologie:index-port', 'topologie:index-port',
kwargs={'switchid': str(port_object.switch.id)} kwargs={'switchid': str(port_object.switch.id)}
)) ))
return form({'id_switch': str(port_object.switch.id), 'topoform': port, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{
'id_switch': str(port_object.switch.id),
'topoform': port,
'action_name': 'Editer'
},
'topologie/topo.html',
request
)
@login_required @login_required
@ -292,12 +329,15 @@ def del_port(request, port, portid):
port.delete() port.delete()
messages.success(request, "Le port a été détruit") messages.success(request, "Le port a été détruit")
except ProtectedError: except ProtectedError:
messages.error(request, "Le port %s est affecté à un autre objet,\ messages.error(
impossible de le supprimer" % port) request,
("Le port %s est affecté à un autre objet, impossible "
"de le supprimer" % port)
)
return redirect(reverse( return redirect(reverse(
'topologie:index-port', 'topologie:index-port',
kwargs={'switchid':str(port.switch.id)} kwargs={'switchid': str(port.switch.id)}
)) ))
return form({'objet': port}, 'topologie/delete.html', request) return form({'objet': port}, 'topologie/delete.html', request)
@ -309,7 +349,11 @@ def new_stack(request):
if stack.is_valid(): if stack.is_valid():
stack.save() stack.save()
messages.success(request, "Stack crée") messages.success(request, "Stack crée")
return form({'topoform': stack, 'action_name' : 'Créer'}, 'topologie/topo.html', request) return form(
{'topoform': stack, 'action_name': 'Créer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -321,7 +365,11 @@ def edit_stack(request, stack, stackid):
if stack.changed_data: if stack.changed_data:
stack.save() stack.save()
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({'topoform': stack, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{'topoform': stack, 'action_name': 'Editer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -333,8 +381,11 @@ def del_stack(request, stack, stackid):
stack.delete() stack.delete()
messages.success(request, "La stack a eté détruite") messages.success(request, "La stack a eté détruite")
except ProtectedError: except ProtectedError:
messages.error(request, "La stack %s est affectée à un autre\ messages.error(
objet, impossible de la supprimer" % stack) request,
("La stack %s est affectée à un autre objet, impossible "
"de la supprimer" % stack)
)
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({'objet': stack}, 'topologie/delete.html', request) return form({'objet': stack}, 'topologie/delete.html', request)
@ -372,8 +423,11 @@ def new_switch(request):
if switch.is_valid() and interface.is_valid(): if switch.is_valid() and interface.is_valid():
user = AssoOption.get_cached_value('utilisateur_asso') user = AssoOption.get_cached_value('utilisateur_asso')
if not user: if not user:
messages.error(request, "L'user association n'existe pas encore,\ messages.error(
veuillez le créer ou le linker dans preferences") request,
("L'user association n'existe pas encore, veuillez le "
"créer ou le linker dans preferences")
)
return redirect(reverse('topologie:index')) return redirect(reverse('topologie:index'))
new_switch = switch.save(commit=False) new_switch = switch.save(commit=False)
new_switch.user = user new_switch.user = user
@ -389,13 +443,17 @@ def new_switch(request):
messages.success(request, "Le switch a été créé") messages.success(request, "Le switch a été créé")
return redirect(reverse('topologie:index')) return redirect(reverse('topologie:index'))
i_mbf_param = generate_ipv4_mbf_param(interface, False) i_mbf_param = generate_ipv4_mbf_param(interface, False)
return form({ return form(
'topoform': interface, {
'machineform': switch, 'topoform': interface,
'domainform': domain, 'machineform': switch,
'i_mbf_param': i_mbf_param, 'domainform': domain,
'device' : 'switch', 'i_mbf_param': i_mbf_param,
}, 'topologie/topo_more.html', request) 'device': 'switch',
},
'topologie/topo_more.html',
request
)
@login_required @login_required
@ -430,9 +488,13 @@ def create_ports(request, switchid):
messages.error(request, ''.join(e)) messages.error(request, ''.join(e))
return redirect(reverse( return redirect(reverse(
'topologie:index-port', 'topologie:index-port',
kwargs={'switchid':switchid} kwargs={'switchid': switchid}
)) ))
return form({'id_switch': switchid, 'topoform': port_form}, 'topologie/switch.html', request) return form(
{'id_switch': switchid, 'topoform': port_form},
'topologie/switch.html',
request
)
@login_required @login_required
@ -467,15 +529,19 @@ def edit_switch(request, switch, switchid):
new_domain.save() new_domain.save()
messages.success(request, "Le switch a bien été modifié") messages.success(request, "Le switch a bien été modifié")
return redirect(reverse('topologie:index')) return redirect(reverse('topologie:index'))
i_mbf_param = generate_ipv4_mbf_param(interface_form, False ) i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
return form({ return form(
'id_switch': switchid, {
'topoform': interface_form, 'id_switch': switchid,
'machineform': switch_form, 'topoform': interface_form,
'domainform': domain_form, 'machineform': switch_form,
'i_mbf_param': i_mbf_param, 'domainform': domain_form,
'device' : 'switch', 'i_mbf_param': i_mbf_param,
}, 'topologie/topo_more.html', request) 'device': 'switch',
},
'topologie/topo_more.html',
request
)
@login_required @login_required
@ -498,8 +564,11 @@ def new_ap(request):
if ap.is_valid() and interface.is_valid(): if ap.is_valid() and interface.is_valid():
user = AssoOption.get_cached_value('utilisateur_asso') user = AssoOption.get_cached_value('utilisateur_asso')
if not user: if not user:
messages.error(request, "L'user association n'existe pas encore,\ messages.error(
veuillez le créer ou le linker dans preferences") request,
("L'user association n'existe pas encore, veuillez le "
"créer ou le linker dans preferences")
)
return redirect(reverse('topologie:index')) return redirect(reverse('topologie:index'))
new_ap = ap.save(commit=False) new_ap = ap.save(commit=False)
new_ap.user = user new_ap.user = user
@ -515,13 +584,17 @@ def new_ap(request):
messages.success(request, "La borne a été créé") messages.success(request, "La borne a été créé")
return redirect(reverse('topologie:index-ap')) return redirect(reverse('topologie:index-ap'))
i_mbf_param = generate_ipv4_mbf_param(interface, False) i_mbf_param = generate_ipv4_mbf_param(interface, False)
return form({ return form(
'topoform': interface, {
'machineform': ap, 'topoform': interface,
'domainform': domain, 'machineform': ap,
'i_mbf_param': i_mbf_param, 'domainform': domain,
'device' : 'wifi ap', 'i_mbf_param': i_mbf_param,
}, 'topologie/topo_more.html', request) 'device': 'wifi ap',
},
'topologie/topo_more.html',
request
)
@login_required @login_required
@ -546,8 +619,11 @@ def edit_ap(request, ap, accesspointid):
if ap_form.is_valid() and interface_form.is_valid(): if ap_form.is_valid() and interface_form.is_valid():
user = AssoOption.get_cached_value('utilisateur_asso') user = AssoOption.get_cached_value('utilisateur_asso')
if not user: if not user:
messages.error(request, "L'user association n'existe pas encore,\ messages.error(
veuillez le créer ou le linker dans preferences") request,
("L'user association n'existe pas encore, veuillez le "
"créer ou le linker dans preferences")
)
return redirect(reverse('topologie:index-ap')) return redirect(reverse('topologie:index-ap'))
new_ap = ap_form.save(commit=False) new_ap = ap_form.save(commit=False)
new_interface = interface_form.save(commit=False) new_interface = interface_form.save(commit=False)
@ -560,15 +636,19 @@ def edit_ap(request, ap, accesspointid):
new_domain.save() new_domain.save()
messages.success(request, "La borne a été modifiée") messages.success(request, "La borne a été modifiée")
return redirect(reverse('topologie:index-ap')) return redirect(reverse('topologie:index-ap'))
i_mbf_param = generate_ipv4_mbf_param(interface_form, False ) i_mbf_param = generate_ipv4_mbf_param(interface_form, False)
return form({ return form(
'topoform': interface_form, {
'machineform': ap_form, 'topoform': interface_form,
'domainform': domain_form, 'machineform': ap_form,
'i_mbf_param': i_mbf_param, 'domainform': domain_form,
'device' : 'wifi ap', 'i_mbf_param': i_mbf_param,
}, 'topologie/topo_more.html', request) 'device': 'wifi ap',
},
'topologie/topo_more.html',
request
)
@login_required @login_required
@can_create(Room) @can_create(Room)
@ -579,7 +659,11 @@ def new_room(request):
room.save() room.save()
messages.success(request, "La chambre a été créé") messages.success(request, "La chambre a été créé")
return redirect(reverse('topologie:index-room')) return redirect(reverse('topologie:index-room'))
return form({'topoform': room, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request) return form(
{'topoform': room, 'action_name': 'Ajouter'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -592,7 +676,11 @@ def edit_room(request, room, roomid):
room.save() room.save()
messages.success(request, "La chambre a bien été modifiée") messages.success(request, "La chambre a bien été modifiée")
return redirect(reverse('topologie:index-room')) return redirect(reverse('topologie:index-room'))
return form({'topoform': room, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{'topoform': room, 'action_name': 'Editer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -604,13 +692,17 @@ def del_room(request, room, roomid):
room.delete() room.delete()
messages.success(request, "La chambre/prise a été détruite") messages.success(request, "La chambre/prise a été détruite")
except ProtectedError: except ProtectedError:
messages.error(request, "La chambre %s est affectée à un autre objet,\ messages.error(
impossible de la supprimer (switch ou user)" % room) request,
("La chambre %s est affectée à un autre objet, impossible "
"de la supprimer (switch ou user)" % room)
)
return redirect(reverse('topologie:index-room')) return redirect(reverse('topologie:index-room'))
return form({ return form(
'objet': room, {'objet': room, 'objet_name': 'Chambre'},
'objet_name': 'Chambre' 'topologie/delete.html',
}, 'topologie/delete.html', request) request
)
@login_required @login_required
@ -622,7 +714,11 @@ def new_model_switch(request):
model_switch.save() model_switch.save()
messages.success(request, "Le modèle a été créé") messages.success(request, "Le modèle a été créé")
return redirect(reverse('topologie:index-model-switch')) return redirect(reverse('topologie:index-model-switch'))
return form({'topoform': model_switch, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request) return form(
{'topoform': model_switch, 'action_name': 'Ajouter'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -630,13 +726,20 @@ def new_model_switch(request):
def edit_model_switch(request, model_switch, modelswitchid): def edit_model_switch(request, model_switch, modelswitchid):
""" Edition d'un modèle de switch""" """ Edition d'un modèle de switch"""
model_switch = EditModelSwitchForm(request.POST or None, instance=model_switch) model_switch = EditModelSwitchForm(
request.POST or None,
instance=model_switch
)
if model_switch.is_valid(): if model_switch.is_valid():
if model_switch.changed_data: if model_switch.changed_data:
model_switch.save() model_switch.save()
messages.success(request, "Le modèle a bien été modifié") messages.success(request, "Le modèle a bien été modifié")
return redirect(reverse('topologie:index-model-switch')) return redirect(reverse('topologie:index-model-switch'))
return form({'topoform': model_switch, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{'topoform': model_switch, 'action_name': 'Editer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -648,13 +751,17 @@ def del_model_switch(request, model_switch, modelswitchid):
model_switch.delete() model_switch.delete()
messages.success(request, "Le modèle a été détruit") messages.success(request, "Le modèle a été détruit")
except ProtectedError: except ProtectedError:
messages.error(request, "Le modèle %s est affectée à un autre objet,\ messages.error(
impossible de la supprimer (switch ou user)" % model_switch) request,
("Le modèle %s est affectée à un autre objet, impossible "
"de la supprimer (switch ou user)" % model_switch)
)
return redirect(reverse('topologie:index-model-switch')) return redirect(reverse('topologie:index-model-switch'))
return form({ return form(
'objet': model_switch, {'objet': model_switch, 'objet_name': 'Modèle de switch'},
'objet_name': 'Modèle de switch' 'topologie/delete.html',
}, 'topologie/delete.html', request) request
)
@login_required @login_required
@ -666,7 +773,11 @@ def new_switch_bay(request):
switch_bay.save() switch_bay.save()
messages.success(request, "La baie a été créé") messages.success(request, "La baie a été créé")
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({'topoform': switch_bay, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request) return form(
{'topoform': switch_bay, 'action_name': 'Ajouter'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -679,7 +790,11 @@ def edit_switch_bay(request, switch_bay, switchbayid):
switch_bay.save() switch_bay.save()
messages.success(request, "Le switch a bien été modifié") messages.success(request, "Le switch a bien été modifié")
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({'topoform': switch_bay, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{'topoform': switch_bay, 'action_name': 'Editer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -691,13 +806,17 @@ def del_switch_bay(request, switch_bay, switchbayid):
switch_bay.delete() switch_bay.delete()
messages.success(request, "La baie a été détruite") messages.success(request, "La baie a été détruite")
except ProtectedError: except ProtectedError:
messages.error(request, "La baie %s est affecté à un autre objet,\ messages.error(
impossible de la supprimer (switch ou user)" % switch_bay) request,
("La baie %s est affecté à un autre objet, impossible "
"de la supprimer (switch ou user)" % switch_bay)
)
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({ return form(
'objet': switch_bay, {'objet': switch_bay, 'objet_name': 'Baie de switch'},
'objet_name': 'Baie de switch' 'topologie/delete.html',
}, 'topologie/delete.html', request) request
)
@login_required @login_required
@ -709,7 +828,11 @@ def new_building(request):
building.save() building.save()
messages.success(request, "Le batiment a été créé") messages.success(request, "Le batiment a été créé")
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({'topoform': building, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request) return form(
{'topoform': building, 'action_name': 'Ajouter'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -722,7 +845,11 @@ def edit_building(request, building, buildingid):
building.save() building.save()
messages.success(request, "Le batiment a bien été modifié") messages.success(request, "Le batiment a bien été modifié")
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({'topoform': building, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{'topoform': building, 'action_name': 'Editer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -734,13 +861,17 @@ def del_building(request, building, buildingid):
building.delete() building.delete()
messages.success(request, "La batiment a été détruit") messages.success(request, "La batiment a été détruit")
except ProtectedError: except ProtectedError:
messages.error(request, "Le batiment %s est affecté à un autre objet,\ messages.error(
impossible de la supprimer (switch ou user)" % building) request,
("Le batiment %s est affecté à un autre objet, impossible "
"de la supprimer (switch ou user)" % building)
)
return redirect(reverse('topologie:index-physical-grouping')) return redirect(reverse('topologie:index-physical-grouping'))
return form({ return form(
'objet': building, {'objet': building, 'objet_name': 'Bâtiment'},
'objet_name': 'Bâtiment' 'topologie/delete.html',
}, 'topologie/delete.html', request) request
)
@login_required @login_required
@ -752,7 +883,11 @@ def new_constructor_switch(request):
constructor_switch.save() constructor_switch.save()
messages.success(request, "Le constructeur a été créé") messages.success(request, "Le constructeur a été créé")
return redirect(reverse('topologie:index-model-switch')) return redirect(reverse('topologie:index-model-switch'))
return form({'topoform': constructor_switch, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request) return form(
{'topoform': constructor_switch, 'action_name': 'Ajouter'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -760,13 +895,20 @@ def new_constructor_switch(request):
def edit_constructor_switch(request, constructor_switch, constructorswitchid): def edit_constructor_switch(request, constructor_switch, constructorswitchid):
""" Edition d'un constructeur de switch""" """ Edition d'un constructeur de switch"""
constructor_switch = EditConstructorSwitchForm(request.POST or None, instance=constructor_switch) constructor_switch = EditConstructorSwitchForm(
request.POST or None,
instance=constructor_switch
)
if constructor_switch.is_valid(): if constructor_switch.is_valid():
if constructor_switch.changed_data: if constructor_switch.changed_data:
constructor_switch.save() constructor_switch.save()
messages.success(request, "Le modèle a bien été modifié") messages.success(request, "Le modèle a bien été modifié")
return redirect(reverse('topologie:index-model-switch')) return redirect(reverse('topologie:index-model-switch'))
return form({'topoform': constructor_switch, 'action_name' : 'Editer'}, 'topologie/topo.html', request) return form(
{'topoform': constructor_switch, 'action_name': 'Editer'},
'topologie/topo.html',
request
)
@login_required @login_required
@ -778,10 +920,14 @@ def del_constructor_switch(request, constructor_switch, constructorswitchid):
constructor_switch.delete() constructor_switch.delete()
messages.success(request, "Le constructeur a été détruit") messages.success(request, "Le constructeur a été détruit")
except ProtectedError: except ProtectedError:
messages.error(request, "Le constructeur %s est affecté à un autre objet,\ messages.error(
impossible de la supprimer (switch ou user)" % constructor_switch) request,
("Le constructeur %s est affecté à un autre objet, impossible "
"de la supprimer (switch ou user)" % constructor_switch)
)
return redirect(reverse('topologie:index-model-switch')) return redirect(reverse('topologie:index-model-switch'))
return form({ return form(
'objet': constructor_switch, {'objet': constructor_switch, 'objet_name': 'Constructeur de switch'},
'objet_name': 'Constructeur de switch' 'topologie/delete.html',
}, 'topologie/delete.html', request) request
)