From e470d15b003767009ad015f8822197b45974ee37 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Sat, 6 Jan 2018 19:09:18 +0100 Subject: [PATCH] Discrimination de l'historique par application. --- cotisations/urls.py | 1 + machines/urls.py | 1 + preferences/urls.py | 3 +- re2o/views.py | 76 +++++++++++++++++++++++++-------------------- topologie/urls.py | 3 +- users/urls.py | 3 +- 6 files changed, 51 insertions(+), 36 deletions(-) diff --git a/cotisations/urls.py b/cotisations/urls.py index e16812b4..2a0c0163 100644 --- a/cotisations/urls.py +++ b/cotisations/urls.py @@ -104,6 +104,7 @@ urlpatterns = [ r'history/(?P\w+)/(?P[0-9]+)$', re2o.views.history, name='history', + kwargs={'application':'cotisations'}, ), url(r'^control/$', views.control, diff --git a/machines/urls.py b/machines/urls.py index 960afa8f..41f443e9 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -80,6 +80,7 @@ urlpatterns = [ r'history/(?P\w+)/(?P[0-9]+)$', re2o.views.history, name='history', + kwargs={'application':'machines'}, ), url(r'^$', views.index, name='index'), url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'), diff --git a/preferences/urls.py b/preferences/urls.py index e28cdb63..3bc15275 100644 --- a/preferences/urls.py +++ b/preferences/urls.py @@ -72,7 +72,8 @@ urlpatterns = [ url( r'^history/(?P\w+)/(?P[0-9]+)$', re2o.views.history, - name='history' + name='history', + kwargs={'application':'preferences'}, ), url(r'^$', views.display_options, name='display-options'), ] diff --git a/re2o/views.py b/re2o/views.py index a90841f2..dce28b5d 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -54,41 +54,51 @@ def index(request): #: Binding the corresponding char sequence of history url to re2o models. HISTORY_BIND = { - 'user' : users.models.User, - 'ban' : users.models.Ban, - 'whitelist' : users.models.Whitelist, - 'school' : users.models.School, - 'listright' : users.models.ListRight, - 'serviceuser' : users.models.ServiceUser, - 'service' : preferences.models.Service, - 'facture' : cotisations.models.Facture, - '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, - 'machine' : machines.models.Machine, - 'interface' : machines.models.Interface, - 'alias' : machines.models.Domain, - 'machinetype' : machines.models.MachineType, - 'iptype' : machines.models.IpType, - 'extension' : machines.models.Extension, - 'soa' : machines.models.SOA, - 'mx' : machines.models.Mx, - 'txt' : machines.models.Txt, - 'srv' : machines.models.Srv, - 'ns' : machines.models.Ns, - 'service' : machines.models.Service, - 'vlan' : machines.models.Vlan, - 'nas' : machines.models.Vlan, + 'users' : { + 'user' : users.models.User, + 'ban' : users.models.Ban, + 'whitelist' : users.models.Whitelist, + 'school' : users.models.School, + 'listright' : users.models.ListRight, + 'serviceuser' : users.models.ServiceUser, + }, + 'preferences' : { + 'service' : preferences.models.Service, + }, + 'cotisations' : { + 'facture' : cotisations.models.Facture, + 'article' : cotisations.models.Article, + 'paiement' : cotisations.models.Paiement, + 'banque' : cotisations.models.Banque, + }, + 'topologie' : { + '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, + }, + 'machines' : { + 'machine' : machines.models.Machine, + 'interface' : machines.models.Interface, + 'alias' : machines.models.Domain, + 'machinetype' : machines.models.MachineType, + 'iptype' : machines.models.IpType, + 'extension' : machines.models.Extension, + 'soa' : machines.models.SOA, + 'mx' : machines.models.Mx, + 'txt' : machines.models.Txt, + 'srv' : machines.models.Srv, + 'ns' : machines.models.Ns, + 'service' : machines.models.Service, + 'vlan' : machines.models.Vlan, + 'nas' : machines.models.Vlan, + }, } @login_required -def history(request, object_name, object_id): +def history(request, application, object_name, object_id): """Render history for a model. The model is determined using the `HISTORY_BIND` dictionnary if none is @@ -108,7 +118,7 @@ def history(request, object_name, object_id): Http404: This kind of models doesn't have history. """ try: - model = HISTORY_BIND[object_name] + model = HISTORY_BIND[application][object_name] except KeyError as e: raise Http404(u"Il n'existe pas d'historique pour ce modèle.") try: diff --git a/topologie/urls.py b/topologie/urls.py index 7885cda5..3caf22c5 100644 --- a/topologie/urls.py +++ b/topologie/urls.py @@ -49,7 +49,8 @@ urlpatterns = [ url( r'^history/(?P\w+)/(?P[0-9]+)$', re2o.views.history, - name='history' + name='history', + kwargs={'application':'topologie'}, ), 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'), diff --git a/users/urls.py b/users/urls.py index 051b0fb6..425f9618 100644 --- a/users/urls.py +++ b/users/urls.py @@ -97,7 +97,8 @@ urlpatterns = [ url( r'^history/(?P\w+)/(?P[0-9]+)$', re2o.views.history, - name='history' + name='history', + kwargs={'application':'users'}, ), url(r'^$', views.index, name='index'), url(r'^index_clubs/$', views.index_clubs, name='index-clubs'),