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 <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-05-17 08:41:05 -07:00 committed by James Valleroy
parent 927e1dc822
commit 2fdbe9948d
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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'))