From 15de0018ae54630821e6550cb3032c281dd6ff01 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Wed, 24 Feb 2010 22:08:19 +0100 Subject: [PATCH] display the server's default config in a TextArea in the Admin --- pyweb/mumble/admin.py | 11 +++++++---- pyweb/mumble/forms.py | 25 +++++++++++++++++++++---- pyweb/mumble/models.py | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/pyweb/mumble/admin.py b/pyweb/mumble/admin.py index 7f0e9f4..a37fe99 100644 --- a/pyweb/mumble/admin.py +++ b/pyweb/mumble/admin.py @@ -17,9 +17,12 @@ from django.contrib import admin from django.utils.translation import ugettext_lazy as _ -from mumble.forms import MumbleAdminForm, MumbleUserAdminForm +from mumble.forms import MumbleServerForm, MumbleAdminForm, MumbleUserAdminForm from mumble.models import MumbleServer, Mumble, MumbleUser +class MumbleServerAdmin(admin.ModelAdmin): + form = MumbleServerForm + class MumbleAdmin(admin.ModelAdmin): """ Specification for the "Server administration" admin section. """ @@ -97,6 +100,6 @@ class MumbleUserAdmin(admin.ModelAdmin): get_acl_admin.boolean = True -admin.site.register( MumbleServer ); -admin.site.register( Mumble, MumbleAdmin ); -admin.site.register( MumbleUser, MumbleUserAdmin ); +admin.site.register( MumbleServer, MumbleServerAdmin ); +admin.site.register( Mumble, MumbleAdmin ); +admin.site.register( MumbleUser, MumbleUserAdmin ); diff --git a/pyweb/mumble/forms.py b/pyweb/mumble/forms.py index b9d42ca..a2d8c0e 100644 --- a/pyweb/mumble/forms.py +++ b/pyweb/mumble/forms.py @@ -22,7 +22,7 @@ from django.conf import settings from django.forms import Form, ModelForm from django.utils.translation import ugettext_lazy as _ -from mumble.models import Mumble, MumbleUser +from mumble.models import MumbleServer, Mumble, MumbleUser class PropertyModelForm( ModelForm ): @@ -40,9 +40,9 @@ class PropertyModelForm( ModelForm ): if fldname in instfields: continue self.fields[fldname].initial = getattr( self.instance, fldname ) - docstr = getattr( self.instance.__class__, fldname ).__doc__ - if docstr: - self.fields[fldname].label = docstr + prop = getattr( self.instance.__class__, fldname ) + if prop.__doc__: + self.fields[fldname].label = prop.__doc__ def save( self, commit=True ): inst = ModelForm.save( self, commit=commit ) @@ -144,6 +144,23 @@ class MumbleAdminForm( MumbleForm ): return None +class MumbleServerForm( ModelForm ): + defaultconf = forms.CharField( required=False, widget=forms.Textarea ) + + def __init__( self, *args, **kwargs ): + ModelForm.__init__( self, *args, **kwargs ) + + if self.instance: + confstr = "" + conf = self.instance.defaultconf + for field in conf: + confstr += "%s: %s\n" % ( field, conf[field] ) + self.fields["defaultconf"].initial = confstr + + class Meta: + model = MumbleServer + + class MumbleUserForm( ModelForm ): """ The user registration form used to register an account. """ diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 676d851..c9e9d9a 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -69,7 +69,8 @@ class MumbleServer( models.Model ): def __init__( self, *args, **kwargs ): models.Model.__init__( self, *args, **kwargs ); - self._ctl = None; + self._ctl = None; + self._conf = None; def __unicode__( self ): return self.dbus; @@ -85,6 +86,17 @@ class MumbleServer( models.Model ): return self._ctl; ctl = property( getCtl, doc="Get a Control object for this server. The ctl is cached for later reuse." ); + + def getDefaultConf( self, field=None ): + if self._conf is None: + self._conf = self.ctl.getDefaultConf() + if field is None: + return self._conf + if field in self._conf: + return self._conf[field] + return None + + defaultconf = property( getDefaultConf, doc="The default config dictionary." ) class Mumble( models.Model ): @@ -109,7 +121,7 @@ class Mumble( models.Model ): "Hostname or IP address to bind to. You should use a hostname here, because it will appear on the " "global server list.") ); port = models.IntegerField( _('Server Port'), blank=True, null=True, help_text=_( - "Port number to bind to. Use -1 to auto assign one.") ); + "Port number to bind to. Leave empty to auto assign one.") ); display = models.CharField( _('Server Display Address'), max_length=200, blank=True, help_text=_( "This field is only relevant if you are located behind a NAT, and names the Hostname or IP address " "to use in the Channel Viewer and for the global server list registration. If not given, the addr "