Commit 0b0a79b7 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST

[statistics][templatetags] Add user accurate computation method

This allows for correct numbers to be shown.
parent bceddcc4
......@@ -27,16 +27,55 @@
from django import template
from django.contrib.auth.models import User
from ..views import calculate_totals
from ...algorithms.models import Algorithm
from ...attestations.models import Attestation
from ...backend.models import Environment
from ...backend.models import Queue
from ...backend.models import Worker
from ...databases.models import Database
from ...dataformats.models import DataFormat
from ...experiments.models import Experiment
from ...libraries.models import Library
from ...plotters.models import Plotter
from ...plotters.models import PlotterParameter
from ...reports.models import Report
from ...search.models import Search
from ...team.models import Team
from ...toolchains.models import Toolchain
register = template.Library()
def calculate_totals(user):
"""Caculates all totals required by the statistics display"""
return dict(
users=User.objects.count(),
databases=Database.objects.for_user(user, True).count(),
environments=Environment.objects.for_user(user, True).count(),
queues=Queue.objects.count(),
workers=Worker.objects.count(),
experiments=Experiment.objects.for_user(user, True).count(),
toolchains=Toolchain.objects.for_user(user, True).count(),
algorithms=Algorithm.objects.for_user(user, True).count(),
libraries=Library.objects.for_user(user, True).count(),
dataformats=DataFormat.objects.for_user(user, True).count(),
teams=Team.objects.for_user(user, True).count(),
attestations=Attestation.objects.for_user(user, True).count(),
searches=Search.objects.for_user(user, True).count(),
reports=Report.objects.for_user(user, True).count(),
plotters=Plotter.objects.for_user(user, True).count(),
plotterparameters=PlotterParameter.objects.for_user(user, True).count(),
)
@register.inclusion_tag("statistics/panels/status.html", takes_context=True)
def status(context, id):
request = context["request"]
return {
"request": context["request"],
"user": request.user,
"panel_id": id,
"totals": calculate_totals(),
"totals": calculate_totals(request.user),
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment