1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

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.
This commit is contained in:
catborise 2026-11-21 23:05:15 +03:00
parent fb81e7adca
commit 2373d73b37
14 changed files with 154 additions and 12 deletions

View file

@ -31,8 +31,9 @@
{% for tag in tags %}
<tr data-search="{{ tag.name }}">
<td>{% include 'common/tag_badge.html' with tag=tag.name %}</td>
<td>{{ tag.vm_count }}</td>
<td>{{ tag.host_count }}</td>
{# the VM list or the Computes page, showing the tag's only #}
<td>{% if tag.vm_count %}<a href="{% url 'instances:index' %}?tag={{ tag.name|urlencode }}">{{ tag.vm_count }}</a>{% else %}0{% endif %}</td>
<td>{% if tag.host_count %}<a href="{% url 'computes' %}?tag={{ tag.name|urlencode }}">{{ tag.host_count }}</a>{% else %}0{% endif %}</td>
<td class="text-end text-nowrap">
<a class="btn btn-sm btn-outline-secondary" href="{% url 'admin:tag_update' tag.id %}">{% trans "Rename" %}</a>
<a class="btn btn-sm btn-outline-danger" href="{% url 'admin:tag_delete' tag.id %}">{% trans "Delete" %}</a>

View file

@ -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()

View file

@ -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)