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 authored and James Valleroy committed 2025-05-30 15:14:16 -04:00
1 parent 927e1dc822
commit 2fdbe9948d
1 file changed
+8 -2
+8 -2
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'))