From 2ca503a9459c3c604878874f847cc99d0540b304 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Fri, 15 Dec 2023 09:58:44 +0100 Subject: [PATCH] filter servers on databases, show only database servers --- orchestra/contrib/databases/forms.py | 10 ++++++++++ orchestra/contrib/databases/settings.py | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/orchestra/contrib/databases/forms.py b/orchestra/contrib/databases/forms.py index cba56642..031160f0 100644 --- a/orchestra/contrib/databases/forms.py +++ b/orchestra/contrib/databases/forms.py @@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _ from orchestra.core import validators from .models import DatabaseUser, Database +from .settings import DATABASES_SERVERS class DatabaseUserCreationForm(forms.ModelForm): @@ -22,6 +23,11 @@ class DatabaseUserCreationForm(forms.ModelForm): model = DatabaseUser fields = ('username', 'account', 'type') + def __init__(self, *args, **kwargs): + super(DatabaseUserCreationForm, self).__init__(*args, **kwargs) + qsServer = self.fields['target_server'].queryset.filter(name__in=DATABASES_SERVERS) + self.fields['target_server'].queryset = qsServer + def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") @@ -74,6 +80,10 @@ class DatabaseCreationForm(DatabaseUserCreationForm): def __init__(self, *args, **kwargs): super(DatabaseCreationForm, self).__init__(*args, **kwargs) account_id = self.initial.get('account', self.initial_account) + + qsServer = self.fields['target_server'].queryset.filter(name__in=DATABASES_SERVERS) + self.fields['target_server'].queryset = qsServer + if account_id: qs = self.fields['user'].queryset.filter(account=account_id).order_by('username') choices = [ (u.pk, "%s (%s) (%s)" % (u, u.get_type_display(), str(u.target_server.name) )) for u in qs ] diff --git a/orchestra/contrib/databases/settings.py b/orchestra/contrib/databases/settings.py index 473c48a8..41623659 100644 --- a/orchestra/contrib/databases/settings.py +++ b/orchestra/contrib/databases/settings.py @@ -27,3 +27,12 @@ DATABASES_DEFAULT_HOST = Setting('DATABASES_DEFAULT_HOST', DATABASES_MYSQL_DB_DIR = Setting('DATABASES_MYSQL_DB_DIR', '/var/lib/mysql', ) + + +DATABASES_SERVERS = Setting('DATABASES_SERVERS', ( + 'wpmu', + 'mysql.pangea.lan', + 'web-11.pangea.lan', + 'web-12.pangea.lan', + ) +) \ No newline at end of file