From 410ff9c5a866d688f0bcf99f33577a01c1967b17 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 16 Feb 2010 20:09:46 +0100 Subject: [PATCH] fix the default channel selector breaking the "Add server" form --- pyweb/mumble/forms.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pyweb/mumble/forms.py b/pyweb/mumble/forms.py index 9fd1af8..ac60e79 100644 --- a/pyweb/mumble/forms.py +++ b/pyweb/mumble/forms.py @@ -84,7 +84,7 @@ class MumbleForm( PropertyModelForm ): "If on, IP adresses of the clients are not logged.") ) player = forms.CharField( required=False ) channel = forms.CharField( required=False ) - defchan = forms.TypedChoiceField( choices=(), coerce=int, help_text=_( + defchan = forms.TypedChoiceField( choices=(), coerce=int, required=False, help_text=_( "Enter the ID of the default channel here. The Channel viewer displays the ID to " "server admins on the channel detail page.") ) @@ -94,11 +94,13 @@ class MumbleForm( PropertyModelForm ): # Populate the `default channel' field's choices choices = [ ('', '----------') ] - def add_item( item, level ): - if item.is_server or item.is_channel: - choices.append( ( str(item.chanid), ( "-"*level + " " + item.name ) ) ) + if self.instance and self.instance.srvid is not None and self.instance.booted: + def add_item( item, level ): + if item.is_server or item.is_channel: + choices.append( ( str(item.chanid), ( "-"*level + " " + item.name ) ) ) + + self.instance.rootchan.visit(add_item) - self.instance.rootchan.visit(add_item) self.fields['defchan'].choices = choices class Meta: