From 2373d73b375dd7ba7ed6d624be1854d4634269dd Mon Sep 17 00:00:00 2001 From: catborise Date: Sat, 21 Nov 2026 23:05:15 +0300 Subject: [PATCH] feat(ui): what a job, a tag or a backup names links to its page - A job's page and the Jobs list link what the job works on: a VM's page for who may see the VM (not when a copy on another host has its UUID); a host's, a backup target's, or the Computes page for a bulk migration, for a superuser (operations.views.link_resources). A backup's or a pool's job has none: a restore names the new VM, and a pool may be gone. - The Tags page's VM and host counts open the VM list or the Computes page with that tag only: a list with that tag takes ?tag=name, and the address loses it (the rest stays), so the list's own reload keeps what is chosen afterwards. The bulk bar sends back to the list's path. - A Backups row links its target, and a removed VM's badge the Removed VMs page while the VM is listed there. --- admin/templates/admin/tag_list.html | 5 ++- admin/tests/test_logs_page.py | 1 + admin/tests/test_views.py | 14 ++++++ instances/templates/instances/vm_list.html | 2 +- instances/tests/js/table_filter.test.js | 26 +++++++++-- operations/templates/operations/job.html | 2 +- operations/templates/operations/jobs.html | 4 +- .../templates/operations/resource_link.html | 1 + operations/tests/test_views.py | 31 +++++++++++++ operations/views.py | 43 +++++++++++++++++++ static/js/table_filter.js | 13 ++++++ vmbackups/templates/vmbackups/index.html | 4 +- vmbackups/tests/test_delete.py | 13 ++++++ vmbackups/views.py | 7 ++- 14 files changed, 154 insertions(+), 12 deletions(-) create mode 100644 operations/templates/operations/resource_link.html diff --git a/admin/templates/admin/tag_list.html b/admin/templates/admin/tag_list.html index b4bcab3e..6922e3ce 100644 --- a/admin/templates/admin/tag_list.html +++ b/admin/templates/admin/tag_list.html @@ -31,8 +31,9 @@ {% for tag in tags %} {% include 'common/tag_badge.html' with tag=tag.name %} - {{ tag.vm_count }} - {{ tag.host_count }} + {# the VM list or the Computes page, showing the tag's only #} + {% if tag.vm_count %}{{ tag.vm_count }}{% else %}0{% endif %} + {% if tag.host_count %}{{ tag.host_count }}{% else %}0{% endif %} {% trans "Rename" %} {% trans "Delete" %} diff --git a/admin/tests/test_logs_page.py b/admin/tests/test_logs_page.py index d371da17..08afa871 100644 --- a/admin/tests/test_logs_page.py +++ b/admin/tests/test_logs_page.py @@ -63,6 +63,7 @@ class LogsPageTests(TestCase): self.assertEqual(self.rows(page)[0][1], log.date.strftime("%Y-%m-%d %H:%M:%S")) def test_a_vm_row_links_the_vm_while_it_is_there(self): + # not its user or host: the row keeps their names, which another may take later page = self.page(q="alice") self.assertEqual(page.xpath("//tbody/tr/td/a/@href"), [reverse("instances:instance", args=[self.vm.pk])]) self.vm.delete() diff --git a/admin/tests/test_views.py b/admin/tests/test_views.py index 7af34103..9ab73342 100644 --- a/admin/tests/test_views.py +++ b/admin/tests/test_views.py @@ -139,6 +139,20 @@ class AdminTestCase(TestCase): self.assertEqual(said(self.client.post(reverse("admin:tag_update", args=[tag.id]), {"name": "new-name"})), ["Tag old-name renamed to new-name"]) + def test_a_tag_s_counts_link_its_vms_and_hosts(self): + from computes.models import Compute, Tag + from instances.models import Instance + + host = Compute.objects.create(name="tg-host", hostname="192.0.2.8", login="", password="", type=4) + tag = Tag.objects.create(name="web") + Instance.objects.create(compute=host, name="tg-vm", uuid="00000000-0000-4000-8000-0000000000cc").tags.add(tag) + page = html.fromstring(self.client.get(reverse("admin:tag_list")).content) + self.assertEqual(page.xpath("//tbody//td/a[not(contains(@class, 'btn'))]/@href"), [reverse("instances:index") + "?tag=web"]) + host.tags.add(tag) + page = html.fromstring(self.client.get(reverse("admin:tag_list")).content) + self.assertEqual(page.xpath("//tbody//td/a[not(contains(@class, 'btn'))]/@href"), + [reverse("instances:index") + "?tag=web", reverse("computes") + "?tag=web"]) + def test_users(self): response = self.client.get(reverse("admin:user_create")) self.assertEqual(response.status_code, 200) diff --git a/instances/templates/instances/vm_list.html b/instances/templates/instances/vm_list.html index 7cbbfa7f..f7679e68 100644 --- a/instances/templates/instances/vm_list.html +++ b/instances/templates/instances/vm_list.html @@ -22,7 +22,7 @@ {# and shows this bar at the foot of the window while any is chosen #}