mirror of
https://github.com/nanoy42/coope
synced 2024-12-23 07:23:47 +00:00
Add number of quotes on stats page. Close #10
This commit is contained in:
parent
7110503edf
commit
c875881c63
6 changed files with 63 additions and 47 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
})
|
|
@ -52,7 +52,6 @@ urlpatterns = [
|
|||
path('categoryProfile/<int:pk>', 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"),
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
{% endif %}
|
||||
{% if request.user.is_staff %}
|
||||
<span class="tabulation2">
|
||||
<i class="fa fa-chart-bar"></i> <a href="{% url 'gestion:stats' %}">Stats</a>
|
||||
<i class="fa fa-chart-bar"></i> <a href="{% url 'stats' %}">Stats</a>
|
||||
</span>
|
||||
<span class="tabulation2">
|
||||
<i class="fa fa-business-time"></i> <a href="{% url 'gestion:gen_releve' %}">Relevé</a>
|
||||
|
|
|
@ -63,6 +63,10 @@
|
|||
<td>Nombre de superusers</td>
|
||||
<td>{{superusers.count}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nombre de citations</td>
|
||||
<td>{{nb_quotes}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Nombre 8</td>
|
||||
<td>8</td>
|
Loading…
Reference in a new issue