8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-09 03:16:25 +00:00

History générique sur topologie.

This commit is contained in:
LEVY-FALK Hugo 2017-12-28 12:39:25 +01:00 committed by root
parent 784ef5d598
commit 3cff068365
3 changed files with 20 additions and 88 deletions

View file

@ -35,7 +35,7 @@ from reversion.models import Version
from django.contrib import messages from django.contrib import messages
from preferences.models import Service from preferences.models import Service
from preferences.models import OptionalUser, GeneralOption from preferences.models import OptionalUser, GeneralOption
import users, preferences, cotisations import users, preferences, cotisations, topologie
def form(ctx, template, request): def form(ctx, template, request):
"""Form générique, raccourci importé par les fonctions views du site""" """Form générique, raccourci importé par les fonctions views du site"""
@ -64,6 +64,12 @@ HISTORY_BIND = {
'article' : cotisations.models.Article, 'article' : cotisations.models.Article,
'paiement' : cotisations.models.Paiement, 'paiement' : cotisations.models.Paiement,
'banque' : cotisations.models.Banque, '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 @login_required

View file

@ -30,6 +30,7 @@ from __future__ import unicode_literals
from django.conf.urls import url from django.conf.urls import url
import re2o
from . import views from . import views
urlpatterns = [ urlpatterns = [
@ -45,24 +46,11 @@ urlpatterns = [
url(r'^switch/(?P<switch_id>[0-9]+)$', url(r'^switch/(?P<switch_id>[0-9]+)$',
views.index_port, views.index_port,
name='index-port'), name='index-port'),
url(r'^history/(?P<object_name>switch)/(?P<object_id>[0-9]+)$', url(
views.history, r'^history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
name='history'), re2o.views.history,
url(r'^history/(?P<object_name>port)/(?P<object_id>[0-9]+)$', name='history'
views.history, ),
name='history'),
url(r'^history/(?P<object_name>room)/(?P<object_id>[0-9]+)$',
views.history,
name='history'),
url(r'^history/(?P<object_name>stack)/(?P<object_id>[0-9]+)$',
views.history,
name='history'),
url(r'^history/(?P<object_name>model_switch)/(?P<object_id>[0-9]+)$',
views.history,
name='history'),
url(r'^history/(?P<object_name>constructor_switch)/(?P<object_id>[0-9]+)$',
views.history,
name='history'),
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'), url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),
url(r'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'), url(r'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'),
url(r'^del_port/(?P<port_id>[0-9]+)$', views.del_port, name='del-port'), url(r'^del_port/(?P<port_id>[0-9]+)$', views.del_port, name='del-port'),

View file

@ -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 @login_required
@can_view_all(Port) @can_view_all(Port)
@can_view(Switch) @can_view(Switch)