Browse Source

display the server's default config in a TextArea in the Admin

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
15de0018ae
  1. 11
      pyweb/mumble/admin.py
  2. 25
      pyweb/mumble/forms.py
  3. 16
      pyweb/mumble/models.py

11
pyweb/mumble/admin.py

@ -17,9 +17,12 @@
from django.contrib import admin from django.contrib import admin
from django.utils.translation import ugettext_lazy as _ 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 from mumble.models import MumbleServer, Mumble, MumbleUser
class MumbleServerAdmin(admin.ModelAdmin):
form = MumbleServerForm
class MumbleAdmin(admin.ModelAdmin): class MumbleAdmin(admin.ModelAdmin):
""" Specification for the "Server administration" admin section. """ """ Specification for the "Server administration" admin section. """
@ -97,6 +100,6 @@ class MumbleUserAdmin(admin.ModelAdmin):
get_acl_admin.boolean = True 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 );

25
pyweb/mumble/forms.py

@ -22,7 +22,7 @@ from django.conf import settings
from django.forms import Form, ModelForm from django.forms import Form, ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from mumble.models import Mumble, MumbleUser
from mumble.models import MumbleServer, Mumble, MumbleUser
class PropertyModelForm( ModelForm ): class PropertyModelForm( ModelForm ):
@ -40,9 +40,9 @@ class PropertyModelForm( ModelForm ):
if fldname in instfields: if fldname in instfields:
continue continue
self.fields[fldname].initial = getattr( self.instance, fldname ) 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 ): def save( self, commit=True ):
inst = ModelForm.save( self, commit=commit ) inst = ModelForm.save( self, commit=commit )
@ -144,6 +144,23 @@ class MumbleAdminForm( MumbleForm ):
return None 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 ): class MumbleUserForm( ModelForm ):
""" The user registration form used to register an account. """ """ The user registration form used to register an account. """

16
pyweb/mumble/models.py

@ -69,7 +69,8 @@ class MumbleServer( models.Model ):
def __init__( self, *args, **kwargs ): def __init__( self, *args, **kwargs ):
models.Model.__init__( self, *args, **kwargs ); models.Model.__init__( self, *args, **kwargs );
self._ctl = None;
self._ctl = None;
self._conf = None;
def __unicode__( self ): def __unicode__( self ):
return self.dbus; return self.dbus;
@ -85,6 +86,17 @@ class MumbleServer( models.Model ):
return self._ctl; return self._ctl;
ctl = property( getCtl, doc="Get a Control object for this server. The ctl is cached for later reuse." ); 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 ): 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 " "Hostname or IP address to bind to. You should use a hostname here, because it will appear on the "
"global server list.") ); "global server list.") );
port = models.IntegerField( _('Server Port'), blank=True, null=True, help_text=_( 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=_( 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 " "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 " "to use in the Channel Viewer and for the global server list registration. If not given, the addr "

Loading…
Cancel
Save