context_processors.py 786 Bytes
Newer Older
chirac's avatar
chirac committed
1
from machines.models import Interface, Machine
chirac's avatar
chirac committed
2
from .settings import SITE_NAME
chirac's avatar
chirac committed
3 4 5

def context_user(request):
    user = request.user
chirac's avatar
chirac committed
6 7 8 9
    if user.is_authenticated():
        interfaces = Interface.objects.filter(machine=Machine.objects.filter(user=user, active=True))
    else:
        interfaces = None
chirac's avatar
chirac committed
10 11 12 13 14 15 16 17 18 19 20 21
    is_cableur = user.has_perms(('cableur',))
    is_bureau = user.has_perms(('bureau',))
    is_bofh = user.has_perms(('bofh',))
    is_trez = user.has_perms(('trésorier',))
    is_infra = user.has_perms(('infra',))
    return {
        'request_user': user,
        'is_cableur': is_cableur,
        'is_bureau': is_bureau,
        'is_bofh': is_bofh,
        'is_trez': is_trez,
        'is_infra': is_infra,
chirac's avatar
chirac committed
22
        'interfaces': interfaces,
chirac's avatar
chirac committed
23
        'site_name': SITE_NAME,
chirac's avatar
chirac committed
24
    }