From c2f7c2e36d42cf30b0448554d35cf8431ff95be1 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 29 Dec 2025 18:13:07 -0300 Subject: [PATCH] Cluster settings update --- cluster/forms.py | 40 ++++++++++++------- cluster/migrations/0005_alter_worker_token.py | 20 ++++++++++ cluster/models.py | 2 +- templates/cluster/workers_list.html | 30 ++++++-------- 4 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 cluster/migrations/0005_alter_worker_token.py diff --git a/cluster/forms.py b/cluster/forms.py index 52a5643..bc6848b 100644 --- a/cluster/forms.py +++ b/cluster/forms.py @@ -10,7 +10,7 @@ from .models import ClusterSettings, Worker class WorkerForm(forms.ModelForm): class Meta: model = Worker - fields = ['name', 'enabled', 'ip_lock', 'ip_address', 'country', 'city', 'hostname'] + fields = ['name', 'enabled', 'ip_lock', 'ip_address', 'country', 'city', 'hostname', 'token'] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -21,6 +21,7 @@ class WorkerForm(forms.ModelForm): self.fields['country'].label = _("Country") self.fields['city'].label = _("City") self.fields['hostname'].label = _("Hostname") + self.fields['token'].label = _("Token") back_label = _("Back") delete_label = _("Delete") @@ -35,18 +36,29 @@ class WorkerForm(forms.ModelForm): self.helper.layout = Layout( Row( Column('name', css_class='form-group col-md-6 mb-0'), - Column('enabled', css_class='form-group col-md-6 mb-0'), + Column('hostname', css_class='form-group col-md-6 mb-0'), css_class='form-row' ), Row( - Column('ip_lock', css_class='form-group col-md-6 mb-0'), + Column('country', css_class='form-group col-md-6 mb-0'), + Column('city', css_class='form-group col-md-6 mb-0'), + + ), + Row( + + Column('token', css_class='form-group col-md-12 mb-0'), + css_class='form-row' + ), + Row( + Column(css_class='form-group col-md-6 mb-0'), Column('ip_address', css_class='form-group col-md-6 mb-0'), css_class='form-row' ), Row( - Column('country', css_class='form-group col-md-4 mb-0'), - Column('city', css_class='form-group col-md-4 mb-0'), - Column('hostname', css_class='form-group col-md-4 mb-0'), + + Column('enabled', css_class='form-group col-md-6 mb-0'), + Column('ip_lock', css_class='form-group col-md-6 mb-0'), + css_class='form-row' ), Row( @@ -67,7 +79,7 @@ class WorkerForm(forms.ModelForm): if Worker.objects.filter(name=name).exclude(pk=self.instance.pk if self.instance else None).exists(): raise ValidationError(_("A worker with that name already exists.")) - + if ip_lock and not ip_address: raise ValidationError(_("IP Address is required when IP Lock is enabled.")) @@ -78,7 +90,7 @@ class ClusterSettingsForm(forms.ModelForm): class Meta: model = ClusterSettings fields = [ - 'enabled', 'primary_enable_wireguard', 'stats_sync_interval', + 'enabled', 'primary_enable_wireguard', 'stats_sync_interval', 'stats_cache_interval', 'cluster_mode', 'restart_mode', 'worker_display' ] @@ -91,11 +103,11 @@ class ClusterSettingsForm(forms.ModelForm): self.fields['cluster_mode'].label = _("Cluster Mode") self.fields['restart_mode'].label = _("Restart Mode") self.fields['worker_display'].label = _("Worker Display") - + back_label = _("Back") self.helper = FormHelper() self.helper.form_method = 'post' - + self.helper.layout = Layout( Row( Column('enabled', css_class='form-group col-md-6 mb-0'), @@ -130,10 +142,10 @@ class ClusterSettingsForm(forms.ModelForm): stats_sync_interval = cleaned_data.get('stats_sync_interval') stats_cache_interval = cleaned_data.get('stats_cache_interval') - if stats_sync_interval and stats_sync_interval < 10: - raise ValidationError(_("Stats sync interval must be at least 10 seconds.")) + if stats_sync_interval and stats_sync_interval < 60: + raise ValidationError(_("Stats sync interval must be at least 60 seconds.")) - if stats_cache_interval and stats_cache_interval < 10: - raise ValidationError(_("Stats cache interval must be at least 10 seconds.")) + if stats_cache_interval and stats_cache_interval < 60: + raise ValidationError(_("Stats cache interval must be at least 60 seconds.")) return cleaned_data \ No newline at end of file diff --git a/cluster/migrations/0005_alter_worker_token.py b/cluster/migrations/0005_alter_worker_token.py new file mode 100644 index 0000000..071505c --- /dev/null +++ b/cluster/migrations/0005_alter_worker_token.py @@ -0,0 +1,20 @@ +# Generated by Django 5.2.9 on 2025-12-29 20:59 + +import uuid + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cluster', '0004_alter_clustersettings_cluster_mode'), + ] + + operations = [ + migrations.AlterField( + model_name='worker', + name='token', + field=models.UUIDField(default=uuid.uuid4, unique=True), + ), + ] diff --git a/cluster/models.py b/cluster/models.py index 1c23b93..01c8f8c 100644 --- a/cluster/models.py +++ b/cluster/models.py @@ -30,7 +30,7 @@ class ClusterSettings(models.Model): class Worker(models.Model): name = models.CharField(max_length=100, unique=True) enabled = models.BooleanField(default=True) - token = models.UUIDField(default=uuid.uuid4) + token = models.UUIDField(default=uuid.uuid4, unique=True) ip_lock = models.BooleanField(default=False) ip_address = models.GenericIPAddressField(blank=True, null=True) diff --git a/templates/cluster/workers_list.html b/templates/cluster/workers_list.html index f4ca92a..4023c0c 100644 --- a/templates/cluster/workers_list.html +++ b/templates/cluster/workers_list.html @@ -8,10 +8,10 @@ {% trans 'Name' %} {% trans 'Status' %} {% trans 'IP Address' %} - {% trans 'Location' %} - {% trans 'Last Seen' %} - {% trans 'Config Version' %} - {% trans 'Options' %} + + + + @@ -21,9 +21,9 @@ {{ worker.name }} {% if worker.enabled %} - {% trans 'Enabled' %} + {% else %} - {% trans 'Disabled' %} + {% endif %} @@ -57,26 +57,20 @@ {% endif %} {% else %} - 0 - {% endif %} - - - {% if worker.force_reload %} - - {% endif %} - - - {% if worker.force_restart %} - + {% endif %} + + + + {% empty %} - {% trans 'No workers configured' %} + {% trans 'No workers configured' %} {% endfor %}