diff --git a/pyweb/mumble/forms.py b/pyweb/mumble/forms.py index c67aadc..adc878e 100644 --- a/pyweb/mumble/forms.py +++ b/pyweb/mumble/forms.py @@ -39,6 +39,9 @@ class PropertyModelForm( ModelForm ): for fldname in self.fields: if fldname not in instfields: self.fields[fldname].initial = getattr( self.instance, fldname ) + docstr = getattr( self.instance.__class__, fldname ).__doc__ + if docstr: + self.fields[fldname].label = _( docstr ) def save( self, commit=True ): inst = ModelForm.save( self, commit=commit ) @@ -65,12 +68,28 @@ def populate_channel_choices( form ): form.fields['defchan'].choices = choices -class MumbleAdminForm( ModelForm ): +class MumbleAdminForm( PropertyModelForm ): """ A Mumble Server admin form intended to be used by the server hoster. """ - defchan = forms.TypedChoiceField( choices=(), coerce=int ) + + url = forms.CharField( required=False ) + motd = forms.CharField( required=False, widget=forms.Textarea ) + passwd = forms.CharField( required=False, help_text=_( + "Password required to join. Leave empty for public servers.") ) + users = forms.IntegerField( required=False ) + bwidth = forms.IntegerField( required=False ) + sslcrt = forms.CharField( required=False, widget=forms.Textarea ) + sslkey = forms.CharField( required=False, widget=forms.Textarea ) + obfsc = forms.BooleanField( required=False, help_text=_( + "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=_( + "Enter the ID of the default channel here. The Channel viewer displays the ID to " + "server admins on the channel detail page.") ) + def __init__( self, *args, **kwargs ): - ModelForm.__init__( self, *args, **kwargs ) + PropertyModelForm.__init__( self, *args, **kwargs ) populate_channel_choices( self ) class Meta: diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index cf7ffb5..0ff4fc0 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -26,6 +26,14 @@ from mumble.mmobjects import mmChannel, mmPlayer from mumble.mctl import MumbleCtlBase +def mk_config_property( field, doc="" ): + """ Create a property for the given config field. """ + return property( + lambda self: self.getConf( field ), + lambda self, value: self.setConf( field, value ), + doc=doc + ) + class Mumble( models.Model ): """ Represents a Murmur server instance. @@ -51,24 +59,22 @@ class Mumble( models.Model ): "global server list.") ); port = models.IntegerField( _('Server Port'), default=settings.MUMBLE_DEFAULT_PORT, help_text=_( "Port number to bind to. Use -1 to auto assign one.") ); - url = models.CharField( _('Website URL'), max_length = 200, blank = True ); - motd = models.TextField( _('Welcome Message'), blank = True ); - passwd = models.CharField( _('Server Password'), max_length = 200, blank = True, help_text=_( - "Password required to join. Leave empty for public servers.") ); supw = models.CharField( _('Superuser Password'), max_length = 200, blank = True ); - users = models.IntegerField( _('Max. Users'), blank = True, null = True ); - bwidth = models.IntegerField( _('Bandwidth [Bps]'), blank = True, null = True ); - sslcrt = models.TextField( _('SSL Certificate'), blank = True ); - sslkey = models.TextField( _('SSL Key'), blank = True ); - obfsc = models.BooleanField( _('IP Obfuscation'), default = False, help_text=_( - "If on, IP adresses of the clients are not logged.") ); - player = models.CharField( _('Player name regex'), max_length=200, default=r'[-=\w\[\]\{\}\(\)\@\|\.]+' ); - channel = models.CharField( _('Channel name regex'), max_length=200, default=r'[ \-=\w\#\[\]\{\}\(\)\@\|]+' ); - defchan = models.IntegerField( _('Default channel'), default=0, help_text=_( - "Enter the ID of the default channel here. The Channel viewer displays the ID to " - "server admins on the channel detail page.")); booted = models.BooleanField( _('Boot Server'), default = True ); + + url = mk_config_property( "registerurl", "Website URL" ) + motd = mk_config_property( "welcometext", "Welcome Message" ) + passwd = mk_config_property( "password", "Server Password" ) + users = mk_config_property( "users", "Max. Users" ) + bwidth = mk_config_property( "bandwidth", "Bandwidth [Bps]" ) + sslcrt = mk_config_property( "certificate", "SSL Certificate" ) + sslkey = mk_config_property( "key", "SSL Key" ) + obfsc = mk_config_property( "obfuscate", "IP Obfuscation" ) + player = mk_config_property( "username", "Player name regex" ) + channel = mk_config_property( "channelname", "Channel name regex" ) + defchan = mk_config_property( "defaultchannel", "Default channel" ) + class Meta: unique_together = ( ( 'dbus', 'srvid' ), ( 'addr', 'port' ), ); verbose_name = _('Server instance'); @@ -176,6 +182,12 @@ class Mumble( models.Model ): ctl = property( getCtl, doc="Get a Control object for this server. The ctl is cached for later reuse." ); + def getConf( self, field ): + return self.ctl.getConf( self.srvid, field ) + + def setConf( self, field, value ): + return self.ctl.setConf( self.srvid, field, value ) + def configureFromMurmur( self ): default = self.ctl.getDefaultConf(); conf = self.ctl.getAllConf( self.srvid );