feat: decorator group_required

This commit is contained in:
2025-01-13 22:18:28 -03:00
parent 9961d080b6
commit 5040744c8a
5 changed files with 21 additions and 14 deletions

View File

@@ -2,15 +2,17 @@ from django.shortcuts import render
from django.db.models import Sum
from django.db.models import Count, F
from django.http import JsonResponse, HttpResponse
from django.contrib.admin.views.decorators import staff_member_required
from comandas.models import ProductComanda
from orders.models import Order
from payments.models import Payments
from gestaoRaul.decorators import group_required
@group_required(groupName='Gerente')
def home(request):
if not request.user.is_authenticated or 'Admin' not in str(request.user.groups.all()):
return HttpResponse({'<h1>Você não esta logado ou não tem permissão!</h1>'})
total_pagamentos = Payments.objects.aggregate(total=Sum('value'))['total']
qdt_pagamentos = Payments.objects.aggregate(total=Count('value'))['total']
pagamentos = Payments.objects.all()
@@ -21,22 +23,13 @@ def home(request):
nome=F('product__name') ).order_by('-quantidade')[:5]
return render(request, 'home.html', {'total_pagamentos': total_pagamentos, 'pagamentos': pagamentos, 'qdt_pagamentos': qdt_pagamentos, 'produtos_mais_vendidos': produtos_mais_vendidos, 'ticekMedio': ticekMedio})
@group_required(groupName='Gerente')
def chartCuisine(request):
user = request.user.groups.all()
for u in user:
print(type(u))
# print(user.email)
print(request.user.first_name)
print(request.user.last_name)
if 'Admin' in str(user):
print('tem permisão admin')
tFila = []
tPreparando = []
tFinalizado = []
dataStart = request.GET.get("data-start")
dataEnd = request.GET.get("data-end")
orders = Order.objects.filter(delivered__isnull=False)