From 9a42485c0adfa66373f23fcf97652e8874a556f5 Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Sun, 18 Oct 2020 13:28:32 +0200 Subject: [PATCH] Create profil template and corresponding view --- machines/templates/machines/profil.html | 271 ++++++++++++++++++++++++ machines/views.py | 34 +++ 2 files changed, 305 insertions(+) create mode 100644 machines/templates/machines/profil.html diff --git a/machines/templates/machines/profil.html b/machines/templates/machines/profil.html new file mode 100644 index 00000000..4b2650ed --- /dev/null +++ b/machines/templates/machines/profil.html @@ -0,0 +1,271 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Lara Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load acl %} +{% load logs_extra %} +{% load i18n %} + +
+
+

+ + {% trans "Machines" %} + {{ nb_machines }} +

+
+
+ +
+ {% if machines_list %} +
+ {% if machines_list.paginator %} + {% include 'pagination.html' with list=machines_list go_to_id="machines" %} + {% endif %} + + + + + + + + + + + {% trans "DNS name" as tr_dns_name %} + + + + + + + {% for machine in machines_list %} + + + + + {% for interface in machine.interface_set.all %} + + + + + + + + + + + {% if ipv6_enabled and interface.ipv6 != 'None' %} + + + + {% endif %} + {% if interface.domain.related_domain.all %} + + + + {% endif %} + {% endfor %} + + + + {% endfor %} + +
{% include 'buttons/sort.html' with prefix='machine' col='name' text=tr_dns_name %}{% trans "Type" %}{% trans "MAC address" %}{% trans "IP address" %}{% trans "Actions" %}
+ {% trans "No name" as tr_no_name %} + {% trans "View the profile" as tr_view_the_profile %} + {% if machine.active %} + + {% else %} + {% trans "Deactivated" %}: + {% endif %} + {{ machine.get_name|default:tr_no_name }} + + {{ machine.user }} + + + {% can_create Interface machine.id %} + {% trans "Create an interface" as tr_create_an_interface %} + {% include 'buttons/add.html' with href='machines:new-interface' id=machine.id desc=tr_create_an_interface %} + {% acl_end %} + {% history_button machine %} + {% can_delete machine %} + {% include 'buttons/suppr.html' with href='machines:del-machine' id=machine.id %} + {% acl_end %} +
+ {% if interface.domain.related_domain.all %} + {{ interface.domain }} + + {% else %} + {{ interface.domain }} + {% endif %} + + {{ interface.machine_type }} + + {{ interface.mac_address }} + + + IPv4 {{ interface.ipv4 }} +
+ {% if ipv6_enabled and interface.ipv6 != 'None' %} + IPv6 + + {% endif %} +
+
+
+ + +
+ {% history_button interface %} + {% can_delete interface %} + {% include 'buttons/suppr.html' with href='machines:del-interface' id=interface.id %} + {% acl_end %} +
+
+
+
    +
  • + {{ interface.get_vendor }} +
  • +
+
+
+
+
    + {% for ipv6 in interface.ipv6.all %} +
  • + {{ ipv6 }} +
  • + {% endfor %} +
+
+
+
+
    + {% for al in interface.domain.related_domain.all %} +
  • + + {{ al }} + + +
  • + {% endfor %} +
+
+
+ + + + {% if machines_list.paginator %} + {% include 'pagination.html' with list=machines_list go_to_id="machines" %} + {% endif %} +
+ {% else %} +

{% trans "No machine" %}

+ {% endif %} +
+
+
diff --git a/machines/views.py b/machines/views.py index 15f59e00..8a93d0e9 100644 --- a/machines/views.py +++ b/machines/views.py @@ -39,6 +39,7 @@ from django.db import IntegrityError from django.forms import modelformset_factory from django.http import HttpResponse from django.shortcuts import render, redirect +from django.template.loader import render_to_string from django.urls import reverse from django.utils.translation import ugettext as _ from django.views.decorators.csrf import csrf_exempt @@ -1311,6 +1312,39 @@ 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): + """View used to display the machines on a user's profile.""" + 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, + ) + 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, + } + + return render_to_string( + "machines/profil.html",context=context,request=request,using=None + ) + + + + @login_required @can_view_all(IpType)