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

Modification de la navbar

This commit is contained in:
Yoann Pétri 2018-03-06 16:38:47 +01:00 committed by root
parent 6b8b576452
commit 0e282037d5
2 changed files with 77 additions and 55 deletions

View file

@ -33,7 +33,13 @@ from django.contrib import messages
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse 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): def can_create(model):
@ -46,7 +52,8 @@ def can_create(model):
def wrapper(request, *args, **kwargs): def wrapper(request, *args, **kwargs):
can, msg = model.can_create(request.user, *args, **kwargs) can, msg = model.can_create(request.user, *args, **kwargs)
if not can: 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 redirect(reverse('index'))
return view(request, *args, **kwargs) return view(request, *args, **kwargs)
return wrapper return wrapper
@ -71,7 +78,8 @@ def can_edit(model, *field_list):
)) ))
can, msg = instance.can_edit(request.user) can, msg = instance.can_edit(request.user)
if not can: 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', return redirect(reverse('users:profil',
kwargs={'userid': str(request.user.id)} kwargs={'userid': str(request.user.id)}
)) ))
@ -79,9 +87,11 @@ def can_edit(model, *field_list):
can_change = getattr(instance, 'can_change_' + field) can_change = getattr(instance, 'can_change_' + field)
can, msg = can_change(request.user, *args, **kwargs) can, msg = can_change(request.user, *args, **kwargs)
if not can: 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', return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)} kwargs={'userid': str(
request.user.id)}
)) ))
return view(request, instance, *args, **kwargs) return view(request, instance, *args, **kwargs)
return wrapper return wrapper
@ -98,9 +108,11 @@ def can_change(model, *field_list):
can_change = getattr(model, 'can_change_' + field) can_change = getattr(model, 'can_change_' + field)
can, msg = can_change(request.user, *args, **kwargs) can, msg = can_change(request.user, *args, **kwargs)
if not can: 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', return redirect(reverse('users:profil',
kwargs={'userid':str(request.user.id)} kwargs={'userid': str(
request.user.id)}
)) ))
return view(request, *args, **kwargs) return view(request, *args, **kwargs)
return wrapper return wrapper
@ -125,7 +137,8 @@ def can_delete(model):
)) ))
can, msg = instance.can_delete(request.user) can, msg = instance.can_delete(request.user)
if not can: 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', return redirect(reverse('users:profil',
kwargs={'userid': str(request.user.id)} kwargs={'userid': str(request.user.id)}
)) ))
@ -174,7 +187,8 @@ def can_view(model):
)) ))
can, msg = instance.can_view(request.user) can, msg = instance.can_view(request.user)
if not can: 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', return redirect(reverse('users:profil',
kwargs={'userid': str(request.user.id)} kwargs={'userid': str(request.user.id)}
)) ))
@ -190,7 +204,8 @@ def can_view_all(model):
def wrapper(request, *args, **kwargs): def wrapper(request, *args, **kwargs):
can, msg = model.can_view_all(request.user) can, msg = model.can_view_all(request.user)
if not can: 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', return redirect(reverse('users:profil',
kwargs={'userid': str(request.user.id)} kwargs={'userid': str(request.user.id)}
)) ))
@ -203,6 +218,7 @@ def can_view_app(app_name):
"""Decorator to check if an user can view an application. """Decorator to check if an user can view an application.
""" """
assert app_name in sys.modules.keys() assert app_name in sys.modules.keys()
def decorator(view): def decorator(view):
def wrapper(request, *args, **kwargs): def wrapper(request, *args, **kwargs):
app = sys.modules[app_name] app = sys.modules[app_name]
@ -230,4 +246,3 @@ def can_edit_history(view):
kwargs={'userid': str(request.user.id)} kwargs={'userid': str(request.user.id)}
)) ))
return wrapper return wrapper

View file

@ -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:url" content="\\{{request.get_host}}" />
<meta property="og:image" content="\\{{request.get_host}}/static/logo/re2o.png"/> <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." /> <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 #} {# Load CSS and JavaScript #}
{% bootstrap_css %} {% bootstrap_css %}
<link href="/static/css/typeaheadjs.css" rel="stylesheet"> <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>
<div class="collapse navbar-collapse" id="myNavbar"> <div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li><a href="{% url "users:mon-profil" %}">Mon profil</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 %} {% can_view_app users %}
<li><a href="{% url 'users:index' %}"><i class="fa fa-users"></i> Voir les adhérents</a></li>
<li><a href="{% url "users:index" %}">Adhérents</a></li>
{% acl_end %} {% acl_end %}
{% can_view_app machines %} {% can_view_app machines %}
<li><a href="{% url "machines:index" %}">Machines</a></li> <li><a href="{% url 'machines:index' %}"><i class="fa fa-desktop"></i> Voir les machines</a></li>
{% acl_end %} {% acl_end %}
{% can_view_app cotisations %} {% can_view_app cotisations %}
<li><a href="{% url "cotisations:index" %}">Cotisations</a></li> <li><a href="{% url 'cotisations:index' %}"><i class="fa fa-dollar-sign"></i> Voir les cotisations</a></li>
{% acl_end %}
</ul>
</li>
{% acl_end %} {% acl_end %}
{% can_view_app topologie %} {% 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 %} {% acl_end %}
{% can_view_app logs %} {% 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 %} {% acl_end %}
</ul> </ul>
<div class="col-sm-3 col-md-3 navbar-right"> <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"> <div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-term" {% if search_term %}value="{{ search_term }}"{% endif %}> <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"> <div class="input-group-btn">
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button> <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="glyphicon glyphicon-plus"></i></a> <a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="fa fa-plus"></i></a>
</div> </div>
</div> </div>
</form> </form>
@ -102,20 +109,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if request.user.is_authenticated %} {% if request.user.is_authenticated %}
<li> <li>
<a href="{% url 'logout' %}"> <a href="{% url 'logout' %}">
<span class="glyphicon glyphicon-log-out"></span> Logout <i class="fa fa-sign-out-alt"></i> Logout
</a> </a>
</li> </li>
{% else %} {% else %}
{% if var_sa %} {% if var_sa %}
<li> <li>
<a href="{% url 'users:new-user' %}"> <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> </a>
</li> </li>
{% endif %} {% endif %}
<li> <li>
<a href="{% url 'login' %}"> <a href="{% url 'login' %}">
<span class="glyphicon glyphicon-log-in"></span> Login <i class="fa fa-sign-in-alt"></i> Login
</a> </a>
</li> </li>
{% endif %} {% endif %}
@ -124,7 +131,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li> <li>
<a href="{% url 'preferences:display-options' %}"> <a href="{% url 'preferences:display-options' %}">
<span class="glyphicon glyphicon-cog"></span> Preferences <i class="fa fa-cogs"></i> Preferences
</a> </a>
</li> </li>
</ul> </ul>
@ -187,7 +194,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</table> </table>
<div class="list-group"> <div class="list-group">
<a class="list-group-item list-group-item-info" role="button"href="{% url "users:mon-profil" %}"> <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 Voir mon profil
</a> </a>
</div> </div>