|
|
|
@ -3,9 +3,15 @@ import os |
|
|
|
from django.shortcuts import redirect, render |
|
|
|
from django.urls import reverse |
|
|
|
from django.conf import settings |
|
|
|
from django.contrib.auth.decorators import login_required |
|
|
|
from django.contrib.auth.models import User, Group |
|
|
|
|
|
|
|
from preferences.models import GeneralPreferences |
|
|
|
from gestion.models import Keg |
|
|
|
from preferences.models import GeneralPreferences, PaymentMethod, Cotisation |
|
|
|
from gestion.models import Keg, ConsumptionHistory, Category, Product, Menu |
|
|
|
from users.models import School |
|
|
|
|
|
|
|
|
|
|
|
from .acl import active_required, admin_required |
|
|
|
|
|
|
|
def home(request): |
|
|
|
""" |
|
|
|
@ -50,4 +56,48 @@ def about(request): |
|
|
|
with open(settings.BASE_DIR + "/LICENSE", "r") as f: |
|
|
|
for line in f: |
|
|
|
license.append(line) |
|
|
|
return render(request, "about.html", {"contributors": contributors, "license": license}) |
|
|
|
return render(request, "about.html", {"contributors": contributors, "license": license}) |
|
|
|
|
|
|
|
@active_required |
|
|
|
@login_required |
|
|
|
@admin_required |
|
|
|
def stats(request): |
|
|
|
users = User.objects.all() |
|
|
|
adherents = [x for x in users if x.profile.is_adherent] |
|
|
|
transactions = ConsumptionHistory.objects.all() |
|
|
|
categories = Category.objects.all() |
|
|
|
categories_shown = Category.objects.exclude(order=0) |
|
|
|
products = Product.objects.all() |
|
|
|
active_products = Product.objects.filter(is_active=True) |
|
|
|
active_kegs = Keg.objects.filter(is_active=True) |
|
|
|
sum_positive_balance = sum([x.profile.balance for x in users if x.profile.balance > 0]) |
|
|
|
sum_balance = sum([x.profile.balance for x in users]) |
|
|
|
schools = School.objects.all() |
|
|
|
groups = Group.objects.all() |
|
|
|
admins = User.objects.filter(is_staff=True) |
|
|
|
superusers = User.objects.filter(is_superuser=True) |
|
|
|
menus = Menu.objects.all() |
|
|
|
payment_methods = PaymentMethod.objects.all() |
|
|
|
cotisations = Cotisation.objects.all() |
|
|
|
gp,_ = GeneralPreferences.objects.get_or_create(pk=1) |
|
|
|
nb_quotes = len(gp.global_message.split("\n")) |
|
|
|
return render(request, "stats.html", { |
|
|
|
"users": users, |
|
|
|
"adherents": adherents, |
|
|
|
"transactions": transactions, |
|
|
|
"categories": categories, |
|
|
|
"categories_shown": categories_shown, |
|
|
|
"products": products, |
|
|
|
"active_products": active_products, |
|
|
|
"active_kegs": active_kegs, |
|
|
|
"sum_positive_balance": sum_positive_balance, |
|
|
|
"sum_balance": sum_balance, |
|
|
|
"schools": schools, |
|
|
|
"groups": groups, |
|
|
|
"admins": admins, |
|
|
|
"superusers": superusers, |
|
|
|
"menus": menus, |
|
|
|
"payment_methods": payment_methods, |
|
|
|
"cotisations": cotisations, |
|
|
|
"nb_quotes": nb_quotes, |
|
|
|
}) |