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

fix(tags): at most 12 characters; "…" does not move the columns

- A new or renamed tag has at most 12 characters (computes.models.TAG_LENGTH,
  a validator: the column keeps 32, so names made before the limit stay
  usable until renamed and the migration changes no SQL); the tag box
  offers no longer name.
- The tags "…" shows in a table's cell go below the others within the
  cell's width as it is, so the list's columns no longer move.
This commit is contained in:
catborise 2026-11-19 09:34:07 +03:00
parent 0e711ec058
commit bc1894e4d8
12 changed files with 115 additions and 78 deletions

View file

@ -2,7 +2,7 @@ from collections import Counter
from ipaddress import ip_address
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
from django.core.validators import MaxLengthValidator, RegexValidator
from django.db import IntegrityError, transaction
from django.db.models import CharField, DateTimeField, IntegerField, ManyToManyField, Model, Q, UniqueConstraint
from django.utils.functional import cached_property
@ -16,6 +16,9 @@ from vrtManager.connection import connection_manager
from vrtManager.hostdetails import wvmHostDetails
# a new or renamed tag's length, so its badge stays short in a list's row; the
# column keeps 32: names made before the limit stay until renamed
TAG_LENGTH = MaxLengthValidator(12, _("A tag has at most %(limit_value)d characters"))
TAG_NAME = RegexValidator(r"^[a-z0-9][a-z0-9._-]*\Z",
_("A tag is letters a-z, digits, dots, dashes and underscores, and begins with a letter or digit"))
@ -23,7 +26,7 @@ TAG_NAME = RegexValidator(r"^[a-z0-9][a-z0-9._-]*\Z",
class Tag(Model):
"""A name given to VMs and hosts, kept in lower case: one name is one tag."""
name = CharField(_("name"), max_length=32, unique=True, validators=[TAG_NAME])
name = CharField(_("name"), max_length=32, unique=True, validators=[TAG_NAME, TAG_LENGTH])
class Meta:
ordering = ["name"]