group check template tag

This commit is contained in:
gw3000 2023-08-09 21:58:30 +02:00
parent 0fcec94275
commit cc02b4126b
3 changed files with 34 additions and 20 deletions

View file

View file

@ -0,0 +1,9 @@
from django import template
from django.contrib.auth.models import Group
register = template.Library()
@register.filter(name='group_check')
def has_group(user, group_name):
group = Group.objects.get(name=group_name)
return True if group in user.groups.all() else False

View file

@ -1,4 +1,6 @@
{% load static %} {% load static %}
{% load group_check %}
{% if user.is_authenticated %} {% if user.is_authenticated %}
<nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top"> <nav class="navbar navbar-expand-lg navbar-dark bg-primary sticky-top">
@ -30,11 +32,14 @@
<a class="nav-link {% if '/costs/all' in request.path %} active {% endif %}" <a class="nav-link {% if '/costs/all' in request.path %} active {% endif %}"
href="{% url 'costs_all' %}">alle Kosten</a> href="{% url 'costs_all' %}">alle Kosten</a>
</li> </li>
{% if request.user|group_check:"data-export" %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {% if '/export' in request.path %} active {% endif %}" <a class="nav-link {% if '/export' in request.path %} active {% endif %}"
href="{% url 'site_exports' %}">Daten-Export</a> href="{% url 'site_exports' %}">Daten-Export</a>
</li> </li>
{% endif %} {% endif %}
{% endif %}
</ul> </ul>
<ul class="navbar-nav pull-right"> <ul class="navbar-nav pull-right">