8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Rename profil view in apps and count machines in user profil view

This commit is contained in:
grisel-davy 2020-10-18 14:51:58 +02:00 committed by Gabriel Detraz
parent 64ed0eb463
commit e2d9591dc8
6 changed files with 25 additions and 65 deletions

View file

@ -1312,11 +1312,11 @@ def index(request):
machines_list = re2o_paginator(request, machines_list, pagination_large_number)
return render(request, "machines/index.html", {"machines_list": machines_list})
# Canonic vie for displaying machines in users's profil
def profil(request, user):
# Canonic view for displaying machines in users's profil
def aff_profil(request, user):
"""View used to display the machines on a user's profile."""
machines = (
Machine.objects.filter(user=users)
Machine.objects.filter(user=user)
.select_related("user")
.prefetch_related("interface_set__domain__extension")
.prefetch_related("interface_set__ipv4__ip_type__extension")
@ -1329,17 +1329,18 @@ def profil(request, user):
request.GET.get("order"),
SortTable.MACHINES_INDEX,
)
nb_machines = machines.count()
pagination_large_number = GeneralOption.get_cached_value("pagination_large_number")
machines = re2o_paginator(request, machines, pagination_large_number)
nb_machines = machines.count()
context = {
"machines_list" = machines,
"nb_machines" = nb_machines,
"users":user,
"machines_list": machines,
"nb_machines":nb_machines,
}
return render_to_string(
"machines/profil.html",context=context,request=request,using=None
"machines/aff_profil.html",context=context,request=request,using=None
)

View file

@ -193,7 +193,7 @@ def aff_tickets(request):
# Canonic views for optional apps
def profil(request, user):
def aff_profil(request, user):
"""View used to display the tickets on a user's profile."""
tickets_list = Ticket.objects.filter(user=user).all().order_by("-date")
nbr_tickets = tickets_list.count()
@ -214,7 +214,7 @@ def profil(request, user):
"nbr_tickets_unsolved": nbr_tickets_unsolved,
}
return render_to_string(
"tickets/profil.html", context=context, request=request, using=None
"tickets/aff_profil.html", context=context, request=request, using=None
)

View file

@ -407,31 +407,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</div>
</div>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading clearfix profil" data-parent="#accordion" data-toggle="collapse"
data-target="#machines">
<h3 class="panel-title pull-left">
<i class="fa fa-desktop"></i>
{% trans "Machines" %}
<span class="badge">{{ nb_machines }}</span>
</h3>
</div>
<div id="machines" class="panel-collapse collapse">
<div class="panel-body">
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' users.id %}">
<i class="fa fa-desktop"></i>
{% trans "Add a machine" %}
</a>
</div>
<div class="panel-body">
{% if machines_list %}
{% include 'machines/aff_machines.html' with machines_list=machines_list %}
{% else %}
<p>{% trans "No machine" %}</p>
{% endif %}
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading clearfix profil" data-parent="#accordion" data-toggle="collapse"
data-target="#subscriptions">
@ -569,7 +544,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</div>
</div>
{% for template in optionnal_templates_list %}
{% for template in apps_templates_list %}
{{ template }}
{% endfor %}

View file

@ -77,7 +77,7 @@ from machines.models import Machine
from preferences.models import OptionalUser, GeneralOption, AssoOption
from importlib import import_module
from django.conf import settings
from re2o.settings_local import OPTIONNAL_APPS_RE2O
from re2o.settings import LOCAL_APPS, OPTIONNAL_APPS_RE2O
from re2o.views import form
from re2o.utils import all_has_access, permission_tree
from re2o.base import re2o_paginator, SortTable
@ -1346,33 +1346,18 @@ def profil(request, users, **_kwargs):
Returns:
Django User Profil Form.
"""
machines = (
Machine.objects.filter(user=users)
.select_related("user")
.prefetch_related("interface_set__domain__extension")
.prefetch_related("interface_set__ipv4__ip_type__extension")
.prefetch_related("interface_set__machine_type")
.prefetch_related("interface_set__domain__related_domain__extension")
)
machines = SortTable.sort(
machines,
request.GET.get("col"),
request.GET.get("order"),
SortTable.MACHINES_INDEX,
)
optionnal_apps = [import_module(app) for app in OPTIONNAL_APPS_RE2O]
optionnal_templates_list = [
app.views.profil(request, users)
for app in optionnal_apps
if hasattr(app.views, "profil")
# Generate the template list for all apps of re2o if relevant
apps = [import_module(app) for app in LOCAL_APPS + OPTIONNAL_APPS_RE2O]
apps_templates_list = [
app.views.aff_profil(request, users)
for app in apps
if hasattr(app.views, "aff_profil")
]
pagination_large_number = GeneralOption.get_cached_value("pagination_large_number")
nb_machines = machines.count()
machines = re2o_paginator(request, machines, pagination_large_number)
nb_machines = users.user_interfaces().count()
factures = Facture.objects.filter(user=users)
factures = SortTable.sort(
factures,
@ -1405,9 +1390,8 @@ def profil(request, users, **_kwargs):
"users/profil.html",
{
"users": users,
"machines_list": machines,
"nb_machines":nb_machines,
"optionnal_templates_list": optionnal_templates_list,
"apps_templates_list": apps_templates_list,
"facture_list": factures,
"ban_list": bans,
"white_list": whitelists,