1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 08:56:07 +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

@ -40,7 +40,7 @@ class TagAdminTests(TestCase):
def test_a_name_taken_or_bad_is_refused(self):
Tag.objects.create(name="db")
for name in ("DB", "two words"):
for name in ("DB", "two words", "x" * 13):
with self.subTest(name):
response = self.client.post(reverse("admin:tag_update", args=[self.prod.pk]), {"name": name})
self.assertEqual(response.status_code, 200)

View file

@ -3,7 +3,7 @@ from django.db import transaction
from django.utils.translation import gettext_lazy as _
from vrtManager.connection import CONN_SOCKET, CONN_SSH, CONN_TCP, CONN_TLS
from computes.models import TAG_NAME, Compute, Tag
from computes.models import TAG_LENGTH, TAG_NAME, Compute, Tag
from computes.utils import lock_ownership
from .validators import validate_hostname
@ -60,9 +60,10 @@ class TagsField(forms.Field):
return set(self.to_python(initial)) != set(self.to_python(data))
def validate(self, value):
existing = set(Tag.objects.filter(name__in=value).values_list("name", flat=True))
for name in value:
if len(name) > 32:
raise forms.ValidationError(_("A tag has at most 32 characters"))
if name not in existing: # a tag made before the limit can still be given
TAG_LENGTH(name)
TAG_NAME(name)

View file

@ -0,0 +1,19 @@
# Generated by Django 5.2.18 on 2026-11-19 06:31
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('computes', '0012_tags'),
]
operations = [
migrations.AlterField(
model_name='tag',
name='name',
field=models.CharField(max_length=32, unique=True, validators=[django.core.validators.RegexValidator('^[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'), django.core.validators.MaxLengthValidator(12, 'A tag has at most %(limit_value)d characters')], verbose_name='name'),
),
]

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"]

View file

@ -23,7 +23,11 @@ class TagsFieldTests(TestCase):
self.assertEqual(TagsField().clean(["Prod", "db", "prod"]), ["prod", "db"])
def test_a_name_is_letters_digits_and_dot_dash_underscore(self):
for bad in ("two words", "-lead", "ç", "x" * 33):
self.assertEqual(TagsField().clean(["x" * 12]), ["x" * 12])
# a tag made before the limit can still be given
Tag.objects.create(name="y" * 20)
self.assertEqual(TagsField().clean(["y" * 20]), ["y" * 20])
for bad in ("two words", "-lead", "ç", "x" * 13):
with self.subTest(bad), self.assertRaises(forms.ValidationError):
TagsField().clean([bad])

Binary file not shown.

View file

@ -11,7 +11,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-19 05:32+0000\n"
"POT-Creation-Date: 2026-11-19 06:32+0000\n"
"PO-Revision-Date: 2020-11-04 12:00+0000\n"
"Last-Translator: catborise <muhammetalisag@gmail.com>, 2020\n"
"Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n"
@ -157,8 +157,8 @@ msgstr "en fazla yedek boyutu (GiB)"
msgid "Can change password"
msgstr "Parola değiştirebilir"
#: accounts/models.py:98 appsettings/models.py:9 computes/models.py:26
#: computes/models.py:52 instances/models.py:33
#: accounts/models.py:98 appsettings/models.py:9 computes/models.py:29
#: computes/models.py:55 instances/models.py:33
msgid "name"
msgstr "ad"
@ -2032,11 +2032,7 @@ msgstr "Kayıtlı, korumak için boş bırakın"
msgid "Add tag %(tag)s"
msgstr "Etiket ekle: %(tag)s"
#: computes/forms.py:65
msgid "A tag has at most 32 characters"
msgstr "Bir etiket en fazla 32 karakterdir"
#: computes/forms.py:96 computes/templates/computes/instances.html:53
#: computes/forms.py:97 computes/templates/computes/instances.html:53
#: instances/templates/instances/settings_tab.html:872
#: instances/templates/instances/settings_tab.html:904
#: instances/templates/instances/snapshots_tab.html:27
@ -2044,43 +2040,43 @@ msgstr "Bir etiket en fazla 32 karakterdir"
msgid "Description"
msgstr "Tanım"
#: computes/forms.py:97
#: computes/forms.py:98
msgid "Shown on the hosts list"
msgstr "Sunucu listesinde gösterilir"
#: computes/forms.py:98
#: computes/forms.py:99
msgid "SASL login"
msgstr "SASL kullanıcı adı"
#: computes/forms.py:98
#: computes/forms.py:99
msgid "SASL password"
msgstr "SASL parolası"
#: computes/forms.py:104 computes/templates/create_comp_block.html:10
#: computes/forms.py:105 computes/templates/create_comp_block.html:10
msgid "libvirt over TCP, with a SASL login"
msgstr "TCP üzerinden libvirt, SASL girişiyle"
#: computes/forms.py:118 computes/templates/create_comp_block.html:14
#: computes/forms.py:119 computes/templates/create_comp_block.html:14
msgid "libvirt over SSH, with the panel's SSH key"
msgstr "SSH üzerinden libvirt, panelin SSH anahtarıyla"
#: computes/forms.py:119
#: computes/forms.py:120
msgid "FQDN/IP"
msgstr "FQDN/IP"
#: computes/forms.py:124
#: computes/forms.py:125
msgid "SSH user"
msgstr "SSH kullanıcısı"
#: computes/forms.py:132 computes/templates/create_comp_block.html:18
#: computes/forms.py:133 computes/templates/create_comp_block.html:18
msgid "libvirt over TLS, with certificates"
msgstr "TLS üzerinden libvirt, sertifikalarla"
#: computes/forms.py:145 computes/templates/create_comp_block.html:21
#: computes/forms.py:146 computes/templates/create_comp_block.html:21
msgid "Local"
msgstr "Yerel"
#: computes/forms.py:146 computes/templates/create_comp_block.html:22
#: computes/forms.py:147 computes/templates/create_comp_block.html:22
msgid "the libvirt of the host the panel runs on, by its socket"
msgstr "panelin çalıştığı sunucunun libvirt'i, soketi üzerinden"
@ -2148,7 +2144,12 @@ msgstr "Dengele"
msgid "%(compute)s is in maintenance: Balance leaves it out"
msgstr "%(compute)s bakımda: Dengele onu hesaba katmaz"
#: computes/models.py:20
#: computes/models.py:21
#, python-format
msgid "A tag has at most %(limit_value)d characters"
msgstr "Bir etiket en fazla %(limit_value)d karakterdir"
#: computes/models.py:23
msgid ""
"A tag is letters a-z, digits, dots, dashes and underscores, and begins with a"
" letter or digit"
@ -2156,27 +2157,27 @@ msgstr ""
"Etiket a-z harfleri, rakamlar, nokta, tire ve alt çizgiden oluşur ve harf ya "
"da rakamla başlar"
#: computes/models.py:53
#: computes/models.py:56
msgid "hostname"
msgstr "sunucuadı"
#: computes/models.py:54
#: computes/models.py:57
msgid "login"
msgstr "kullanıcı"
#: computes/models.py:55
#: computes/models.py:58
msgid "password"
msgstr "parola"
#: computes/models.py:56
#: computes/models.py:59
msgid "details"
msgstr "detaylar"
#: computes/models.py:59
#: computes/models.py:62
msgid "migration address"
msgstr "taşıma adresi"
#: computes/models.py:65
#: computes/models.py:68
msgid ""
"IP address or host name the other hosts send migrating VMs to; empty: the "
"address the panel reaches the host at"
@ -2184,11 +2185,11 @@ msgstr ""
"Diğer sunucuların taşınan sanal makineleri gönderdiği IP adresi veya ana "
"bilgisayar adı; boş: panelin bu sunucuya ulaştığı adres"
#: computes/models.py:70 computes/templates/computes/form.html:41
#: computes/models.py:73 computes/templates/computes/form.html:41
msgid "gstfsd key"
msgstr "gstfsd anahtarı"
#: computes/models.py:76
#: computes/models.py:79
msgid ""
"GSTFSD_KEY in the host's /etc/default/webvirt-gstfsd: the panel sets the root"
" password and SSH key of a shut-off VM with it; empty: they cannot be set "
@ -2198,16 +2199,16 @@ msgstr ""
"sanal makinenin root parolasını ve SSH anahtarını bununla ayarlar; boş: bu "
"sunucuda ayarlanamazlar"
#: computes/models.py:90 instances/models.py:38
#: computes/models.py:93 instances/models.py:38
msgid "tags"
msgstr "etiketler"
#: computes/models.py:106 computes/templates/computes/instances.html:12
#: computes/models.py:109 computes/templates/computes/instances.html:12
#, python-format
msgid "%(compute)s is in maintenance: no new VM or migration comes to it"
msgstr "%(compute)s bakımda: ona yeni sanal makine ya da taşıma gelmez"
#: computes/models.py:112
#: computes/models.py:115
#, python-format
msgid ""
"%(compute)s is in maintenance: its VMs cannot be started there; migrate the "
@ -2216,12 +2217,12 @@ msgstr ""
"%(compute)s bakımda: sanal makineleri orada başlatılamaz; başka bir sunucuda "
"başlatmak için sanal makineyi taşıyın"
#: computes/models.py:239
#: computes/models.py:242
#, python-format
msgid "This host is already added as %(name)s"
msgstr "Bu sunucu zaten %(name)s olarak ekli"
#: computes/models.py:242
#: computes/models.py:245
#, python-format
msgid ""
"The panel cannot reach the host to tell that its VMs are there: %(error)s"
@ -2229,7 +2230,7 @@ msgstr ""
"Panel sunucuya ulaşamadığı için VM'lerinin orada olduğunu doğrulayamıyor: "
"%(error)s"
#: computes/models.py:249
#: computes/models.py:252
msgid ""
"The host its VMs are on is not known yet: change the connection when the "
"panel has reached the host at its current one"
@ -2237,7 +2238,7 @@ msgstr ""
"VM'lerinin bulunduğu sunucu henüz bilinmiyor: bağlantıyı, panel sunucuya "
"mevcut bağlantısından ulaştıktan sonra değiştirin"
#: computes/models.py:252
#: computes/models.py:255
msgid "This is another host than the one its VMs are on: add it as a new host"
msgstr ""
"Bu, VM'lerinin bulunduğu sunucudan başka bir sunucu: yeni bir sunucu olarak "

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-19 05:32+0000\n"
"POT-Creation-Date: 2026-11-19 06:32+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@ -154,8 +154,8 @@ msgstr "最大备份大小 (GiB)"
msgid "Can change password"
msgstr "可修改密码"
#: accounts/models.py:98 appsettings/models.py:9 computes/models.py:26
#: computes/models.py:52 instances/models.py:33
#: accounts/models.py:98 appsettings/models.py:9 computes/models.py:29
#: computes/models.py:55 instances/models.py:33
msgid "name"
msgstr "名称"
@ -1956,11 +1956,7 @@ msgstr "已保存,留空则保持不变"
msgid "Add tag %(tag)s"
msgstr "添加标签:%(tag)s"
#: computes/forms.py:65
msgid "A tag has at most 32 characters"
msgstr "标签最多 32 个字符"
#: computes/forms.py:96 computes/templates/computes/instances.html:53
#: computes/forms.py:97 computes/templates/computes/instances.html:53
#: instances/templates/instances/settings_tab.html:872
#: instances/templates/instances/settings_tab.html:904
#: instances/templates/instances/snapshots_tab.html:27
@ -1968,43 +1964,43 @@ msgstr "标签最多 32 个字符"
msgid "Description"
msgstr "描述"
#: computes/forms.py:97
#: computes/forms.py:98
msgid "Shown on the hosts list"
msgstr "显示在主机列表中"
#: computes/forms.py:98
#: computes/forms.py:99
msgid "SASL login"
msgstr "SASL 登录名"
#: computes/forms.py:98
#: computes/forms.py:99
msgid "SASL password"
msgstr "SASL 密码"
#: computes/forms.py:104 computes/templates/create_comp_block.html:10
#: computes/forms.py:105 computes/templates/create_comp_block.html:10
msgid "libvirt over TCP, with a SASL login"
msgstr "通过 TCP 连接 libvirt,使用 SASL 登录"
#: computes/forms.py:118 computes/templates/create_comp_block.html:14
#: computes/forms.py:119 computes/templates/create_comp_block.html:14
msgid "libvirt over SSH, with the panel's SSH key"
msgstr "通过 SSH 连接 libvirt,使用面板的 SSH 密钥"
#: computes/forms.py:119
#: computes/forms.py:120
msgid "FQDN/IP"
msgstr "FQDN/IP"
#: computes/forms.py:124
#: computes/forms.py:125
msgid "SSH user"
msgstr "SSH 用户"
#: computes/forms.py:132 computes/templates/create_comp_block.html:18
#: computes/forms.py:133 computes/templates/create_comp_block.html:18
msgid "libvirt over TLS, with certificates"
msgstr "通过 TLS 连接 libvirt,使用证书"
#: computes/forms.py:145 computes/templates/create_comp_block.html:21
#: computes/forms.py:146 computes/templates/create_comp_block.html:21
msgid "Local"
msgstr "本地"
#: computes/forms.py:146 computes/templates/create_comp_block.html:22
#: computes/forms.py:147 computes/templates/create_comp_block.html:22
msgid "the libvirt of the host the panel runs on, by its socket"
msgstr "面板所在主机的 libvirt,通过其套接字连接"
@ -2066,43 +2062,48 @@ msgstr "均衡"
msgid "%(compute)s is in maintenance: Balance leaves it out"
msgstr "%(compute)s 正在维护:均衡不包括它"
#: computes/models.py:20
#: computes/models.py:21
#, python-format
msgid "A tag has at most %(limit_value)d characters"
msgstr "标签最多 %(limit_value)d 个字符"
#: computes/models.py:23
msgid ""
"A tag is letters a-z, digits, dots, dashes and underscores, and begins with a"
" letter or digit"
msgstr "标签由字母 a-z、数字、点、短横线和下划线组成,并以字母或数字开头"
#: computes/models.py:53
#: computes/models.py:56
msgid "hostname"
msgstr "主机名"
#: computes/models.py:54
#: computes/models.py:57
msgid "login"
msgstr "登录名"
#: computes/models.py:55
#: computes/models.py:58
msgid "password"
msgstr "密码"
#: computes/models.py:56
#: computes/models.py:59
msgid "details"
msgstr "详情"
#: computes/models.py:59
#: computes/models.py:62
msgid "migration address"
msgstr "迁移地址"
#: computes/models.py:65
#: computes/models.py:68
msgid ""
"IP address or host name the other hosts send migrating VMs to; empty: the "
"address the panel reaches the host at"
msgstr "其他主机向此主机迁移虚拟机时使用的 IP 地址或主机名;留空:使用面板连接该主机的地址"
#: computes/models.py:70 computes/templates/computes/form.html:41
#: computes/models.py:73 computes/templates/computes/form.html:41
msgid "gstfsd key"
msgstr "gstfsd 密钥"
#: computes/models.py:76
#: computes/models.py:79
msgid ""
"GSTFSD_KEY in the host's /etc/default/webvirt-gstfsd: the panel sets the root"
" password and SSH key of a shut-off VM with it; empty: they cannot be set "
@ -2111,40 +2112,40 @@ msgstr ""
"主机 /etc/default/webvirt-gstfsd 中的 GSTFSD_KEY:面板用它为已关机的虚拟机设置 root 密码和 SSH "
"密钥;留空:无法在此设置"
#: computes/models.py:90 instances/models.py:38
#: computes/models.py:93 instances/models.py:38
msgid "tags"
msgstr "标签"
#: computes/models.py:106 computes/templates/computes/instances.html:12
#: computes/models.py:109 computes/templates/computes/instances.html:12
#, python-format
msgid "%(compute)s is in maintenance: no new VM or migration comes to it"
msgstr "%(compute)s 正在维护:不会在其上创建新虚拟机,也不会迁移虚拟机到它"
#: computes/models.py:112
#: computes/models.py:115
#, python-format
msgid ""
"%(compute)s is in maintenance: its VMs cannot be started there; migrate the "
"VM to start it on another host"
msgstr "%(compute)s 正在维护:其虚拟机无法在其上启动;请将虚拟机迁移到其他主机后再启动"
#: computes/models.py:239
#: computes/models.py:242
#, python-format
msgid "This host is already added as %(name)s"
msgstr "此主机已作为 %(name)s 添加"
#: computes/models.py:242
#: computes/models.py:245
#, python-format
msgid ""
"The panel cannot reach the host to tell that its VMs are there: %(error)s"
msgstr "面板无法连接该主机,因此无法确认其虚拟机在那里:%(error)s"
#: computes/models.py:249
#: computes/models.py:252
msgid ""
"The host its VMs are on is not known yet: change the connection when the "
"panel has reached the host at its current one"
msgstr "其虚拟机所在的主机尚不明确:请在面板通过当前连接访问到该主机后再更改连接"
#: computes/models.py:252
#: computes/models.py:255
msgid "This is another host than the one its VMs are on: add it as a new host"
msgstr "这不是其虚拟机所在的主机:请将其添加为新主机"

View file

@ -314,6 +314,13 @@ fieldset:not(:has(input[value="set"]:checked)) > .console-new-password {
.tag-badge {
white-space: normal;
}
/* the tags "…" shows in a table's cell: below the others, within the cell's width as it is
(no width of their own), so the table's columns do not move */
td .tag-more {
display: block;
width: 0;
min-width: 100%;
}
/* a VM's or host's tags: smaller than other badges, so a row with several stays narrow */
.tag-badge {
font-size: 0.65rem;

View file

@ -8,14 +8,15 @@ document.querySelectorAll("select[data-searchable]").forEach(function (select) {
});
// A <select multiple data-tags>: the tags there are, and a new one typed (the
// server checks it), in lower case as the tags are kept: "Prod" is "prod".
// server checks it), in lower case as the tags are kept: "Prod" is "prod";
// a new one of at most 12 characters (computes.models.TAG_LENGTH).
document.querySelectorAll("select[data-tags]").forEach(function (select) {
new TomSelect(select, {
create: function (input) {
return {value: input.toLowerCase(), text: input.toLowerCase()};
},
createFilter: function (input) {
return /^[A-Za-z0-9][A-Za-z0-9._-]{0,31}$/.test(input) && !this.options[input.toLowerCase()];
return /^[A-Za-z0-9][A-Za-z0-9._-]{0,11}$/.test(input) && !this.options[input.toLowerCase()];
},
persist: false,
render: {

View file

@ -4,5 +4,5 @@
{% for tag in tags %}{% include 'common/tag_badge.html' %} {% endfor %}
{% if more %}
<button type="button" class="badge tag-badge text-bg-light border" data-show-tags title="{{ more|join:", " }}">…<span class="visually-hidden"> {% trans "more tags" %}</span></button>
<span hidden tabindex="-1">{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}</span>
<span class="tag-more" hidden tabindex="-1">{% for tag in more %}{% include 'common/tag_badge.html' %} {% endfor %}</span>
{% endif %}