1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 17:36:05 +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

@ -60,10 +60,10 @@
<tr>
{# date and time wrap apart on a phone #}
<td class="text-nowrap">{{ backup.created_at|date:"Y-m-d" }}<br class="d-sm-none"><span class="d-none d-sm-inline"> </span>{{ backup.created_at|date:"H:i" }}
<div class="small text-body-secondary text-nowrap" title="{% trans "Target" %}">{{ backup.target.name }}</div></td>
<div class="small text-nowrap" title="{% trans "Target" %}"><a class="link-secondary" href="{% url 'vmbackups:target' backup.target_id %}">{{ backup.target.name }}</a></div></td>
<td style="max-width: min(12rem, 30vw);">{# a long name is cut, whole on hover #}
{% if backup.instance %}<a class="d-inline-block text-truncate mw-100 align-bottom" title="{{ backup.vm_name }}" href="{% url 'instances:instance' backup.instance.id %}">{{ backup.vm_name }}</a>
{% else %}<span class="d-inline-block text-truncate mw-100 align-bottom" title="{{ backup.vm_name }}">{{ backup.vm_name }}</span> <span class="badge text-bg-secondary">{% trans "removed" %}</span>{% endif %}
{% else %}<span class="d-inline-block text-truncate mw-100 align-bottom" title="{{ backup.vm_name }}">{{ backup.vm_name }}</span> {% if backup.tombstone %}<a class="badge text-bg-secondary" href="{% url 'admin:tombstone_list' %}">{% trans "removed" %}</a>{% else %}<span class="badge text-bg-secondary">{% trans "removed" %}</span>{% endif %}{% endif %}
<div class="small text-body-secondary text-truncate">{{ backup.compute_name }}{% if backup.policy %}, <a href="{% url 'vmbackups:policy' backup.policy_id %}" title="{% trans "Schedule" %}">{{ backup.policy.name }}</a>{% endif %}</div>
</td>
<td class="d-none d-md-table-cell">{% include "vmbackups/consistency.html" %}</td>

View file

@ -244,6 +244,19 @@ class IndexTests(TransactionTestCase):
self.assertNotIn(reverse("vmbackups:restore_over", args=[ready.uuid]),
page.xpath("//table[@id='backups']//a/@href"))
def test_a_row_links_its_target_and_a_removed_vm_listed_as_removed(self):
from instances.models import InstanceTombstone
links = lambda page: set(page.xpath("//table[@id='backups']//td//a[not(contains(@class, 'dropdown-item'))]/@href"))
self.client.force_login(self.admin)
page = lxml_html.fromstring(self.client.get(reverse("vmbackups:index")).content)
self.assertTrue({reverse("vmbackups:target", args=[self.t1.pk]), reverse("vmbackups:target", args=[self.t2.pk])}
<= links(page))
self.assertNotIn(reverse("admin:tombstone_list"), links(page)) # db1 is not on the Removed VMs page
InstanceTombstone.objects.create(uuid="u2", name="db1", host="h1")
page = lxml_html.fromstring(self.client.get(reverse("vmbackups:index")).content)
self.assertIn(reverse("admin:tombstone_list"), links(page))
def test_the_list_shows_fifty_a_page_and_keeps_the_filter(self):
vm = Instance.objects.get(name="web1")
for _n in range(60):

View file

@ -17,7 +17,7 @@ from libvirt import libvirtError
from admin.decorators import superuser_only
from instances.jobs import unprotected
from instances.models import Instance
from instances.models import Instance, InstanceTombstone
from instances.views import get_instance
from logs.audit import audit
from operations import claims, jobs
@ -209,6 +209,11 @@ def index(request):
rows = rows.filter(state=Backup.READY).exclude(damage=[])
# schedules add a backup of each VM a night: the list is read a page at a time, as the jobs are
page = Paginator(rows, 50).get_page(request.GET.get("page"))
# a removed VM's badge links to the Removed VMs page while it is listed there
removed = set(InstanceTombstone.objects.filter(uuid__in={b.vm_uuid for b in page if not b.instance_id})
.values_list("uuid", flat=True))
for backup in page:
backup.tombstone = backup.vm_uuid in removed
return render(request, "vmbackups/index.html", {
"rows": page.object_list, "page": page, "targets": BackupTarget.objects.order_by("name"),
"vm": vm, "target": target, "state": state, "pending_deletes": pending_deletes(),