Dashboard dynamic content

* replaces static dummy values with database values
* renames 'Your own' into 'Shared with you' for clarification
* adds translation
This commit is contained in:
mipel
2021-07-28 08:50:53 +02:00
parent ea4cbcffff
commit 4a492ff0bc
5 changed files with 173 additions and 119 deletions

View File

@@ -1,5 +1,5 @@
{% extends 'base.html' %}
{% load i18n fontawesome_5 %}
{% load i18n fontawesome_5 humanize %}
{% block body %}
{% include 'news/dashboard-news.html' %}
@@ -21,11 +21,11 @@
<div class="col-sm">
<div class="col-md mb-2">
<div>{% trans 'Total' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{total_intervention_count}}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{total_intervention_count|intcomma}}</div>
</div>
<div class="col-md">
<div>{% trans 'Your own' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{user_intervention_count}}</div>
<div>{% trans 'Shared with you' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{user_intervention_count|intcomma}}</div>
</div>
</div>
</div>
@@ -59,11 +59,11 @@
<div class="col-sm">
<div class="col-md mb-2">
<div>{% trans 'Total' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{total_compensation_count}}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{total_compensation_count|intcomma}}</div>
</div>
<div class="col-md">
<div>{% trans 'Your own' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{user_compensation_count}}</div>
<div>{% trans 'Shared with you' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{user_compensation_count|intcomma}}</div>
</div>
</div>
</div>
@@ -98,11 +98,11 @@
<div class="col-sm">
<div class="col-md mb-2">
<div>{% trans 'Total' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{total_eco_count}}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{total_eco_count|intcomma}}</div>
</div>
<div class="col-md">
<div>{% trans 'Your own' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{user_eco_count}}</div>
<div>{% trans 'Shared with you' %}</div>
<div class="class badge badge-pill rlp-gd-outline w-100">{{user_eco_count|intcomma}}</div>
</div>
</div>
</div>

View File

@@ -13,6 +13,8 @@ from django.shortcuts import redirect, render, get_object_or_404
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from compensation.models import Compensation, EcoAccount
from intervention.models import Intervention
from konova.contexts import BaseContext
from konova.forms import RemoveModalForm
from konova.models import Document
@@ -47,6 +49,8 @@ def home_view(request: HttpRequest):
"""
template = "konova/home.html"
now = timezone.now()
user = request.user
# Fetch the four newest active and published ServerMessages
msgs = ServerMessage.objects.filter(
is_active=True,
@@ -56,14 +60,43 @@ def home_view(request: HttpRequest):
"-publish_on"
)[:4]
# First fetch all valid objects (undeleted, only newest versions)
interventions = Intervention.objects.filter(
deleted_on=None,
deleted_by=None,
next_version=None,
)
# Then fetch only user related ones
user_interventions = interventions.filter(
users__in=[user]
)
# Repeat for other objects
comps = Compensation.objects.filter(
deleted_on=None,
deleted_by=None,
next_version=None,
)
user_comps = comps.filter(
users__in=[user]
)
eco_accs = EcoAccount.objects.filter(
deleted_on=None,
deleted_by=None,
next_version=None,
)
user_ecco_accs = eco_accs.filter(
users__in=[user]
)
additional_context = {
"msgs": msgs,
"total_intervention_count": 123,
"user_intervention_count": 5,
"total_compensation_count": 123,
"user_compensation_count": 5,
"total_eco_count": 123,
"user_eco_count": 5,
"total_intervention_count": interventions.count(),
"user_intervention_count": user_interventions.count(),
"total_compensation_count": comps.count(),
"user_compensation_count": user_comps.count(),
"total_eco_count": eco_accs.count(),
"user_eco_count": user_ecco_accs.count(),
}
context = BaseContext(request, additional_context).context
return render(request, template, context)