Commit 9fd1fd56 authored by Flavio TARSETTI's avatar Flavio TARSETTI

Merge branch '514_fix_front_page_stats' into 'django3_migration'

Fix front page stats

See merge request !386
parents a79f92df ea610b65
Pipeline #43087 passed with stage
in 15 minutes and 31 seconds
......@@ -31,6 +31,7 @@ from datetime import timedelta
from django.conf import settings
from django.db import models
from django.db.models import Q
from django.urls import reverse
from ..algorithms.models import Algorithm
......@@ -75,6 +76,17 @@ class AttestationManager(models.Manager):
def published(self):
return self.filter(locked=False)
def for_user(self, user, add_public=False):
if user.is_anonymous:
return self.published()
query = Q(experiment__author=user)
if add_public:
query |= Q(locked=False)
return self.filter(query).distinct()
class Attestation(models.Model):
......
......@@ -33,6 +33,7 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core import exceptions as django_exceptions
from django.db import models
from django.db.models import Q
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.encoding import force_text
......@@ -93,6 +94,17 @@ class ReportManager(models.Manager):
def published(self):
return self.filter(status=Report.PUBLISHED)
def for_user(self, user, add_public=False):
if user.is_anonymous:
return self.published()
query = Q(author=user)
if add_public:
query |= Q(status=Report.PUBLISHED)
return self.filter(query).distinct()
# ----------------------------------------------------------
......
......@@ -21,17 +21,17 @@
{% endcomment %}
<div id="{{panel_id}}">
<div class="list-group">
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'experiments:public-list' %}{% else %}{% url 'experiments:list' request.user.username %}{% endif %}" title="Show experiments" data-toggle="tooltip" data-placement="left">Experiments <span class="badge">{{ totals.experiments }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'toolchains:public-list' %}{% else %}{% url 'toolchains:list' request.user.username %}{% endif %}" title="Show toolchains" data-toggle="tooltip" data-placement="left">Toolchains <span class="badge">{{ totals.toolchains }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'algorithms:public-list' %}{% else %}{% url 'algorithms:list' request.user.username %}{% endif %}" title="Show algorithms" data-toggle="tooltip" data-placement="left">Algorithms <span class="badge">{{ totals.algorithms }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'libraries:public-list' %}{% else %}{% url 'libraries:list' request.user.username %}{% endif %}" title="Show libraries" data-toggle="tooltip" data-placement="left">Libraries <span class="badge">{{ totals.libraries }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'dataformats:public-list' %}{% else %}{% url 'dataformats:list' request.user.username %}{% endif %}" title="Show dataformats" data-toggle="tooltip" data-placement="left">Dataformats <span class="badge">{{ totals.dataformats }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'teams:public-list' %}{% else %}{% url 'teams:list' request.user.username %}{% endif %}" title="Show teams" data-toggle="tooltip" data-placement="left">Teams <span class="badge">{{ totals.teams }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'attestations:public-list' %}{% else %}{% url 'attestations:list' request.user.username %}{% endif %}" title="Show attestations" data-toggle="tooltip" data-placement="left">Attestations <span class="badge">{{ totals.attestations }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'search:public-list' %}{% else %}{% url 'search:list' request.user.username %}{% endif %}" title="Show searches" data-toggle="tooltip" data-placement="left">Searches <span class="badge">{{ totals.searches }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'reports:public-list' %}{% else %}{% url 'reports:list' request.user.username %}{% endif %}" title="Show reports" data-toggle="tooltip" data-placement="left">Reports <span class="badge">{{ totals.reports }}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'plotters:list' %}{% else %}{% url 'plotters:list' %}{% endif %}" title="Show plotters" data-toggle="tooltip" data-placement="left">Plotters <span class="badge">{{ totals.plotters}}</span></a>
<a class="list-group-item" href="{% if request.user.is_anonymous %}{% url 'plotters:plotterparameter-public-list' %}{% else %}{% url 'plotters:plotterparameter-list' request.user.username %}{% endif %}" title="Show plotters" data-toggle="tooltip" data-placement="left">Plotterparameters <span class="badge">{{ totals.plotterparameters}}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'experiments:public-list' %}{% else %}{% url 'experiments:list' user.username %}{% endif %}" title="Show experiments" data-toggle="tooltip" data-placement="left">Experiments <span class="badge">{{ totals.experiments }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'toolchains:public-list' %}{% else %}{% url 'toolchains:list' user.username %}{% endif %}" title="Show toolchains" data-toggle="tooltip" data-placement="left">Toolchains <span class="badge">{{ totals.toolchains }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'algorithms:public-list' %}{% else %}{% url 'algorithms:list' user.username %}{% endif %}" title="Show algorithms" data-toggle="tooltip" data-placement="left">Algorithms <span class="badge">{{ totals.algorithms }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'libraries:public-list' %}{% else %}{% url 'libraries:list' user.username %}{% endif %}" title="Show libraries" data-toggle="tooltip" data-placement="left">Libraries <span class="badge">{{ totals.libraries }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'dataformats:public-list' %}{% else %}{% url 'dataformats:list' user.username %}{% endif %}" title="Show dataformats" data-toggle="tooltip" data-placement="left">Dataformats <span class="badge">{{ totals.dataformats }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'teams:public-list' %}{% else %}{% url 'teams:list' user.username %}{% endif %}" title="Show teams" data-toggle="tooltip" data-placement="left">Teams <span class="badge">{{ totals.teams }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'attestations:public-list' %}{% else %}{% url 'attestations:list' user.username %}{% endif %}" title="Show attestations" data-toggle="tooltip" data-placement="left">Attestations <span class="badge">{{ totals.attestations }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'search:public-list' %}{% else %}{% url 'search:list' user.username %}{% endif %}" title="Show searches" data-toggle="tooltip" data-placement="left">Searches <span class="badge">{{ totals.searches }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'reports:public-list' %}{% else %}{% url 'reports:list' user.username %}{% endif %}" title="Show reports" data-toggle="tooltip" data-placement="left">Reports <span class="badge">{{ totals.reports }}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'plotters:list' %}{% else %}{% url 'plotters:list' %}{% endif %}" title="Show plotters" data-toggle="tooltip" data-placement="left">Plotters <span class="badge">{{ totals.plotters}}</span></a>
<a class="list-group-item" href="{% if user.is_anonymous %}{% url 'plotters:plotterparameter-public-list' %}{% else %}{% url 'plotters:plotterparameter-list' user.username %}{% endif %}" title="Show plotters" data-toggle="tooltip" data-placement="left">Plotterparameters <span class="badge">{{ totals.plotterparameters}}</span></a>
<a class="list-group-item" href="{% url 'databases:list' %}" title="Show databases" data-toggle="tooltip" data-placement="left">Databases <span class="badge">{{ totals.databases }}</span></a>
<div class="list-group-item">Users <span class="badge">{{ totals.users }}</span></div>
</div>
......
......@@ -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