Commit 0e282037 authored by Yoann Pietri's avatar Yoann Pietri Committed by root

Modification de la navbar

parent 6b8b5764
......@@ -33,7 +33,13 @@ from django.contrib import messages
from django.shortcuts import redirect
from django.urls import reverse
import cotisations, logs, machines, preferences, search, topologie, users
import cotisations
import logs
import machines
import preferences
import search
import topologie
import users
def can_create(model):
......@@ -46,7 +52,8 @@ def can_create(model):
def wrapper(request, *args, **kwargs):
can, msg = model.can_create(request.user, *args, **kwargs)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('index'))
return view(request, *args, **kwargs)
return wrapper
......@@ -67,22 +74,25 @@ def can_edit(model, *field_list):
except model.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
can, msg = instance.can_edit(request.user)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
for field in field_list:
can_change = getattr(instance, 'can_change_' + field)
can, msg = can_change(request.user, *args, **kwargs)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(
request.user.id)}
))
return view(request, instance, *args, **kwargs)
return wrapper
return decorator
......@@ -98,10 +108,12 @@ def can_change(model, *field_list):
can_change = getattr(model, 'can_change_' + field)
can, msg = can_change(request.user, *args, **kwargs)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(
request.user.id)}
))
return view(request, *args, **kwargs)
return wrapper
return decorator
......@@ -121,14 +133,15 @@ def can_delete(model):
except model.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
can, msg = instance.can_delete(request.user)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
return view(request, instance, *args, **kwargs)
return wrapper
return decorator
......@@ -149,8 +162,8 @@ def can_delete_set(model):
if not instances:
messages.error(request, "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
return view(request, instances, *args, **kwargs)
return wrapper
return decorator
......@@ -170,14 +183,15 @@ def can_view(model):
except model.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
can, msg = instance.can_view(request.user)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
return view(request, instance, *args, **kwargs)
return wrapper
return decorator
......@@ -190,10 +204,11 @@ def can_view_all(model):
def wrapper(request, *args, **kwargs):
can, msg = model.can_view_all(request.user)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
messages.error(
request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
return view(request, *args, **kwargs)
return wrapper
return decorator
......@@ -203,16 +218,17 @@ def can_view_app(app_name):
"""Decorator to check if an user can view an application.
"""
assert app_name in sys.modules.keys()
def decorator(view):
def wrapper(request, *args, **kwargs):
app = sys.modules[app_name]
can,msg = app.can_view(request.user)
can, msg = app.can_view(request.user)
if can:
return view(request, *args, **kwargs)
messages.error(request, msg)
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
return wrapper
return decorator
......@@ -223,11 +239,10 @@ def can_edit_history(view):
if request.user.has_perm('admin.change_logentry'):
return view(request, *args, **kwargs)
messages.error(
request,
"Vous ne pouvez pas éditer l'historique."
request,
"Vous ne pouvez pas éditer l'historique."
)
return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)}
))
kwargs={'userid': str(request.user.id)}
))
return wrapper
......@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<meta property="og:url" content="\\{{request.get_host}}" />
<meta property="og:image" content="\\{{request.get_host}}/static/logo/re2o.png"/>
<meta property="og:description" content="Site de gestion de réseau supporté par FedeRez." />
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
{# Load CSS and JavaScript #}
{% bootstrap_css %}
<link href="/static/css/typeaheadjs.css" rel="stylesheet">
......@@ -69,22 +70,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="{% url "users:mon-profil" %}">Mon profil</a></li>
{% can_view_app users %}
<li><a href="{% url "users:index" %}">Adhérents</a></li>
{% acl_end %}
{% can_view_app machines %}
<li><a href="{% url "machines:index" %}">Machines</a></li>
{% acl_end %}
{% can_view_app cotisations %}
<li><a href="{% url "cotisations:index" %}">Cotisations</a></li>
<li><a href="{% url "users:mon-profil" %}"><i class="fa fa-user"></i> Mon profil</a></li>
{% can_view_any_app users machines cotisations %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-users"></i> Adhérents<span class="caret"></span></a>
<ul class="dropdown-menu">
{% can_view_app users %}
<li><a href="{% url 'users:index' %}"><i class="fa fa-users"></i> Voir les adhérents</a></li>
{% acl_end %}
{% can_view_app machines %}
<li><a href="{% url 'machines:index' %}"><i class="fa fa-desktop"></i> Voir les machines</a></li>
{% acl_end %}
{% can_view_app cotisations %}
<li><a href="{% url 'cotisations:index' %}"><i class="fa fa-dollar-sign"></i> Voir les cotisations</a></li>
{% acl_end %}
</ul>
</li>
{% acl_end %}
{% can_view_app topologie %}
<li><a href="{% url "topologie:index" %}">Topologie</a></li>
<li><a href="{% url "topologie:index" %}"><i class="fa fa-sitemap"></i> Topologie</a></li>
{% acl_end %}
{% can_view_app logs %}
<li><a href="{% url "logs:index" %}">Statistiques</a></li>
<li><a href="{% url "logs:index" %}"><i class="fa fa-chart-area"></i> Statistiques</a></li>
{% acl_end %}
</ul>
<div class="col-sm-3 col-md-3 navbar-right">
......@@ -92,8 +99,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-term" {% if search_term %}value="{{ search_term }}"{% endif %}>
<div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
<a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="glyphicon glyphicon-plus"></i></a>
<button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
<a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="fa fa-plus"></i></a>
</div>
</div>
</form>
......@@ -102,20 +109,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if request.user.is_authenticated %}
<li>
<a href="{% url 'logout' %}">
<span class="glyphicon glyphicon-log-out"></span> Logout
<i class="fa fa-sign-out-alt"></i> Logout
</a>
</li>
{% else %}
{% if var_sa %}
<li>
<a href="{% url 'users:new-user' %}">
<span class="glyphicon glyphicon-user"></span> Créer un compte
<i class="fa fa-user-plus"></i> Créer un compte
</a>
</li>
{% endif %}
<li>
<a href="{% url 'login' %}">
<span class="glyphicon glyphicon-log-in"></span> Login
<i class="fa fa-sign-in-alt"></i> Login
</a>
</li>
{% endif %}
......@@ -124,7 +131,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<ul class="nav navbar-nav navbar-right">
<li>
<a href="{% url 'preferences:display-options' %}">
<span class="glyphicon glyphicon-cog"></span> Preferences
<i class="fa fa-cogs"></i> Preferences
</a>
</li>
</ul>
......@@ -187,7 +194,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</table>
<div class="list-group">
<a class="list-group-item list-group-item-info" role="button"href="{% url "users:mon-profil" %}">
<i class="glyphicon glyphicon-user"></i>
<i class="fa fa-user-circle"></i>
Voir mon profil
</a>
</div>
......
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