From 2fdbe9948dadb8ef836591125504ed50e6fbe18a Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sat, 17 May 2025 08:41:05 -0700 Subject: [PATCH] forms: Allow showing a None option during domain selection - To be used to show that no domain is initially selected in Home Assistant. And also to release a domain from dedicated use. Tests: - Install Matrix Synapse app in unstable VM. After install the setup form does not show None as an option. Selecting a domain works as expected. Reviewed-by: James Valleroy --- plinth/forms.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plinth/forms.py b/plinth/forms.py index 97ace3770..c0310f494 100644 --- a/plinth/forms.py +++ b/plinth/forms.py @@ -51,12 +51,18 @@ class UninstallForm(forms.Form): class DomainSelectionForm(forms.Form): """Form for selecting a domain name.""" - def __init__(self, *args, **kwargs): + def __init__(self, show_none=False, *args, **kwargs): super().__init__(*args, **kwargs) from plinth.modules.names.components import DomainName domains = list(DomainName.list_names()) - self.fields['domain_name'].choices = zip(domains, domains) + + choices = list(zip(domains, domains)) + if show_none: + choices = [('', _('(None)'))] + choices + self.fields['domain_name'].required = False + + self.fields['domain_name'].choices = choices domain_name = forms.ChoiceField( label=_('Select a domain name to be used with this application'))