diff --git a/coopeV3/urls.py b/coopeV3/urls.py index 4b764f4..8247789 100644 --- a/coopeV3/urls.py +++ b/coopeV3/urls.py @@ -25,11 +25,13 @@ urlpatterns = [ path('home', views.homepage, name="homepage"), path('about', views.about, name="about"), path('coope-runner', views.coope_runner, name="coope-runner"), + path('stats', views.stats, name="stats"), path('admin/doc/', include('django.contrib.admindocs.urls')), path('admin/', admin.site.urls), path('users/', include('users.urls')), path('gestion/', include('gestion.urls')), - path('preferences/', include('preferences.urls')), + path('preferences/', include('preferences.urls')), + ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/coopeV3/views.py b/coopeV3/views.py index 430d66b..e9108b8 100644 --- a/coopeV3/views.py +++ b/coopeV3/views.py @@ -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}) \ No newline at end of file + 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, + }) \ No newline at end of file diff --git a/gestion/urls.py b/gestion/urls.py index 01e846a..c5c777f 100644 --- a/gestion/urls.py +++ b/gestion/urls.py @@ -52,7 +52,6 @@ urlpatterns = [ path('categoryProfile/', views.categoryProfile, name="categoryProfile"), path('categoriesList', views.categoriesList, name="categoriesList"), path('categories-autocomplete', views.CategoriesAutocomplete.as_view(), name="categories-autocomplete"), - path('stats', views.stats, name="stats"), path('divide', views.divide, name="divide"), path('gen_invoice', views.gen_invoice, name="gen_invoice"), path('compute-price', views.compute_price_view, name="compute-price"), diff --git a/gestion/views.py b/gestion/views.py index 8077f31..fbadea9 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -1013,7 +1013,9 @@ def divide(request): "divide_histories": divide_histories, } ) + ########## categories ########## + @active_required @login_required @permission_required('gestion.add_category') @@ -1091,47 +1093,6 @@ class CategoriesAutocomplete(autocomplete.Select2QuerySetView): qs = qs.filter(name__icontains=self.q) return qs -@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() - return render(request, "gestion/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, - }) - ########## Compute price ########## def compute_price_view(request): diff --git a/templates/nav.html b/templates/nav.html index e31ee29..876d1bd 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -31,7 +31,7 @@ {% endif %} {% if request.user.is_staff %} - Stats + Stats Relevé diff --git a/gestion/templates/gestion/stats.html b/templates/stats.html similarity index 97% rename from gestion/templates/gestion/stats.html rename to templates/stats.html index d40f393..771e863 100644 --- a/gestion/templates/gestion/stats.html +++ b/templates/stats.html @@ -63,6 +63,10 @@ Nombre de superusers {{superusers.count}} + + Nombre de citations + {{nb_quotes}} + Nombre 8 8