From 3cff0683654020e0f03d3b73cc3d04193290aa17 Mon Sep 17 00:00:00 2001 From: LEVY-FALK Hugo Date: Thu, 28 Dec 2017 12:39:25 +0100 Subject: [PATCH] =?UTF-8?q?History=20g=C3=A9n=C3=A9rique=20sur=20topologie?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- re2o/views.py | 8 ++++- topologie/urls.py | 24 ++++----------- topologie/views.py | 76 +++++----------------------------------------- 3 files changed, 20 insertions(+), 88 deletions(-) diff --git a/re2o/views.py b/re2o/views.py index 50502211..e55cf039 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -35,7 +35,7 @@ from reversion.models import Version from django.contrib import messages from preferences.models import Service from preferences.models import OptionalUser, GeneralOption -import users, preferences, cotisations +import users, preferences, cotisations, topologie def form(ctx, template, request): """Form générique, raccourci importé par les fonctions views du site""" @@ -64,6 +64,12 @@ HISTORY_BIND = { 'article' : cotisations.models.Article, 'paiement' : cotisations.models.Paiement, 'banque' : cotisations.models.Banque, + 'switch' : topologie.models.Switch, + 'port' : topologie.models.Port, + 'room' : topologie.models.Room, + 'stack' : topologie.models.Stack, + 'model_switch' : topologie.models.ModelSwitch, + 'constructor_switch' : topologie.models.ConstructorSwitch, } @login_required diff --git a/topologie/urls.py b/topologie/urls.py index 752ebcc5..7885cda5 100644 --- a/topologie/urls.py +++ b/topologie/urls.py @@ -30,6 +30,7 @@ from __future__ import unicode_literals from django.conf.urls import url +import re2o from . import views urlpatterns = [ @@ -45,24 +46,11 @@ urlpatterns = [ url(r'^switch/(?P[0-9]+)$', views.index_port, name='index-port'), - url(r'^history/(?Pswitch)/(?P[0-9]+)$', - views.history, - name='history'), - url(r'^history/(?Pport)/(?P[0-9]+)$', - views.history, - name='history'), - url(r'^history/(?Proom)/(?P[0-9]+)$', - views.history, - name='history'), - url(r'^history/(?Pstack)/(?P[0-9]+)$', - views.history, - name='history'), - url(r'^history/(?Pmodel_switch)/(?P[0-9]+)$', - views.history, - name='history'), - url(r'^history/(?Pconstructor_switch)/(?P[0-9]+)$', - views.history, - name='history'), + url( + r'^history/(?P\w+)/(?P[0-9]+)$', + re2o.views.history, + name='history' + ), url(r'^edit_port/(?P[0-9]+)$', views.edit_port, name='edit-port'), url(r'^new_port/(?P[0-9]+)$', views.new_port, name='new-port'), url(r'^del_port/(?P[0-9]+)$', views.del_port, name='del-port'), diff --git a/topologie/views.py b/topologie/views.py index fc4da4e4..0e24ebcd 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -60,7 +60,7 @@ from topologie.forms import ( AddPortForm, EditRoomForm, StackForm, - EditModelSwitchForm, + EditModelSwitchForm, EditConstructorSwitchForm, CreatePortsForm ) @@ -116,68 +116,6 @@ def index(request): }) -@login_required -@permission_required('cableur') -def history(request, object_name, object_id): - """ Vue générique pour afficher l'historique complet d'un objet""" - if object_name == 'switch': - try: - object_instance = Switch.objects.get(pk=object_id) - except Switch.DoesNotExist: - messages.error(request, "Switch inexistant") - return redirect(reverse('topologie:index')) - elif object_name == 'port': - try: - object_instance = Port.objects.get(pk=object_id) - except Port.DoesNotExist: - messages.error(request, "Port inexistant") - return redirect(reverse('topologie:index')) - elif object_name == 'room': - try: - object_instance = Room.objects.get(pk=object_id) - except Room.DoesNotExist: - messages.error(request, "Chambre inexistante") - return redirect(reverse('topologie:index')) - elif object_name == 'stack': - try: - object_instance = Stack.objects.get(pk=object_id) - except Room.DoesNotExist: - messages.error(request, "Stack inexistante") - return redirect(reverse('topologie:index')) - elif object_name == 'model_switch': - try: - object_instance = ModelSwitch.objects.get(pk=object_id) - except ModelSwitch.DoesNotExist: - messages.error(request, "SwitchModel inexistant") - return redirect(reverse('topologie:index')) - elif object_name == 'constructor_switch': - try: - object_instance = ConstructorSwitch.objects.get(pk=object_id) - except ConstructorSwitch.DoesNotExist: - messages.error(request, "SwitchConstructor inexistant") - return redirect(reverse('topologie:index')) - else: - messages.error(request, "Objet inconnu") - return redirect(reverse('topologie:index')) - options, _created = GeneralOption.objects.get_or_create() - pagination_number = options.pagination_number - reversions = Version.objects.get_for_object(object_instance) - paginator = Paginator(reversions, pagination_number) - page = request.GET.get('page') - try: - reversions = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - reversions = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - reversions = paginator.page(paginator.num_pages) - return render(request, 're2o/history.html', { - 'reversions': reversions, - 'object': object_instance - }) - - @login_required @can_view_all(Port) @can_view(Switch) @@ -296,7 +234,7 @@ def new_port(request, switch_id): except IntegrityError: messages.error(request, "Ce port existe déjà") return redirect(reverse( - 'topologie:index-port', + 'topologie:index-port', kwargs={'switch_id':switch_id} )) return form({'id_switch': switch_id,'topoform': port}, 'topologie/topo.html', request) @@ -307,7 +245,7 @@ def new_port(request, switch_id): def edit_port(request, port_object, port_id): """ Edition d'un port. Permet de changer le switch parent et l'affectation du port""" - + port = EditPortForm(request.POST or None, instance=port_object) if port.is_valid(): with transaction.atomic(), reversion.create_revision(): @@ -363,7 +301,7 @@ def new_stack(request): @can_edit(Stack) def edit_stack(request, stack, stack_id): """Edition d'un stack (nombre de switches, nom...)""" - + stack = StackForm(request.POST or None, instance=stack) if stack.is_valid(): with transaction.atomic(), reversion.create_revision(): @@ -400,7 +338,7 @@ def del_stack(request, stack, stack_id): @can_edit(Stack) def edit_switchs_stack(request, stack, stack_id): """Permet d'éditer la liste des switches dans une stack et l'ajouter""" - + if request.method == "POST": pass else: @@ -476,14 +414,14 @@ def create_ports(request, switch_id): except Switch.DoesNotExist: messages.error(request, u"Switch inexistant") return redirect("/topologie/") - + s_begin = s_end = 0 nb_ports = switch.ports.count() if nb_ports > 0: ports = switch.ports.order_by('port').values('port') s_begin = ports.first().get('port') s_end = ports.last().get('port') - + port_form = CreatePortsForm( request.POST or None, initial={'begin': s_begin, 'end': s_end}