diff --git a/machines/templates/machines/profil.html b/machines/templates/machines/aff_profil.html similarity index 100% rename from machines/templates/machines/profil.html rename to machines/templates/machines/aff_profil.html diff --git a/machines/views.py b/machines/views.py index 8a93d0e9..76d12eca 100644 --- a/machines/views.py +++ b/machines/views.py @@ -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) + machines = ( + 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 ) diff --git a/tickets/templates/tickets/profil.html b/tickets/templates/tickets/aff_profil.html similarity index 100% rename from tickets/templates/tickets/profil.html rename to tickets/templates/tickets/aff_profil.html diff --git a/tickets/views.py b/tickets/views.py index c1796f8d..a87285ae 100644 --- a/tickets/views.py +++ b/tickets/views.py @@ -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 ) diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index ad0605c7..b9fbc621 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -407,31 +407,6 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %} -
-
-

- - {% trans "Machines" %} - {{ nb_machines }} -

-
-
- -
- {% if machines_list %} - {% include 'machines/aff_machines.html' with machines_list=machines_list %} - {% else %} -

{% trans "No machine" %}

- {% endif %} -
-
-
@@ -569,7 +544,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
- {% for template in optionnal_templates_list %} + {% for template in apps_templates_list %} {{ template }} {% endfor %} diff --git a/users/views.py b/users/views.py index 54f67b77..96d32136 100644 --- a/users/views.py +++ b/users/views.py @@ -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 @@ -1314,8 +1314,8 @@ def index_serviceusers(request): def mon_profil(request): """Shortcuts view to profil view, with correct arguments. Returns the view profil with users argument, users is set to - default request.user. - + default request.user. + Parameters: request (django request): Standard django request. @@ -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, + "nb_machines":nb_machines, + "apps_templates_list": apps_templates_list, "facture_list": factures, "ban_list": bans, "white_list": whitelists,