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

feat: tag badges choose the tag, untagged rows, counts in the tag list

On the VM and host lists a tag's badge chooses it in the tag list, the
tag list offers "No tag" for the rows without one, and each choice says
how many of the listed rows it shows ("prod (42)"); an owner counts only
their own VMs.
This commit is contained in:
catborise 2026-11-18 22:08:02 +03:00
parent f8cb6f1e0f
commit 904dd860d0
15 changed files with 110 additions and 57 deletions

View file

@ -1,3 +1,4 @@
from collections import Counter
from ipaddress import ip_address
from django.core.exceptions import ValidationError
@ -30,6 +31,13 @@ class Tag(Model):
def __str__(self):
return self.name
@staticmethod
def counts(rows):
"""The tag list's choices for rows (VMs or hosts, their tags read):
[(name, how many have it)] by name, and how many have no tag."""
counts = Counter(tag.name for row in rows for tag in row.tags.all())
return sorted(counts.items()), sum(1 for row in rows if not row.tags.all())
@classmethod
def named(cls, names):
"""The tags of names, those not there yet made."""