Browse Source

cache the server version in the model, add a property to prettyprint it and display it in the admin.

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
37ccd499f3
  1. 9
      pyweb/mumble/admin.py
  2. 2
      pyweb/mumble/mmobjects.py
  3. 17
      pyweb/mumble/models.py
  4. 2
      pyweb/mumble/templates/mumble/mumble.html

9
pyweb/mumble/admin.py

@ -22,7 +22,7 @@ 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): class MumbleServerAdmin(admin.ModelAdmin):
list_display = [ 'dbus', 'get_murmur_online' ]
list_display = [ 'dbus', 'get_murmur_online', 'get_murmur_version' ]
search_fields = [ 'dbus' ] search_fields = [ 'dbus' ]
ordering = [ 'dbus' ] ordering = [ 'dbus' ]
@ -34,6 +34,13 @@ class MumbleServerAdmin(admin.ModelAdmin):
get_murmur_online.short_description = _('Master is running') get_murmur_online.short_description = _('Master is running')
get_murmur_online.boolean = True get_murmur_online.boolean = True
def get_murmur_version( self, obj ):
if obj.online:
return obj.prettyversion
return "?"
get_murmur_version.short_description = _("Server version")
class MumbleAdmin(admin.ModelAdmin): class MumbleAdmin(admin.ModelAdmin):
""" Specification for the "Server administration" admin section. """ """ Specification for the "Server administration" admin section. """

2
pyweb/mumble/mmobjects.py

@ -124,7 +124,7 @@ class mmChannel( object ):
mumble://username@host:port/parentchans/self.name mumble://username@host:port/parentchans/self.name
""" """
from urlparse import urlunsplit from urlparse import urlunsplit
versionstr = "version=%d.%d.%d" % tuple(self.server.version[:3]);
versionstr = "version=%s" % self.server.prettyversion;
if self.parent is not None: if self.parent is not None:
chanlist = self.parent_channels() + [self.name]; chanlist = self.parent_channels() + [self.name];

17
pyweb/mumble/models.py

@ -72,6 +72,7 @@ class MumbleServer( models.Model ):
models.Model.__init__( self, *args, **kwargs ); models.Model.__init__( self, *args, **kwargs );
self._ctl = None; self._ctl = None;
self._conf = None; self._conf = None;
self._version = None;
def __unicode__( self ): def __unicode__( self ):
return self.dbus; return self.dbus;
@ -140,6 +141,17 @@ class MumbleServer( models.Model ):
online = property( isOnline ) online = property( isOnline )
defaultconf = property( getDefaultConf, doc="The default config dictionary." ) defaultconf = property( getDefaultConf, doc="The default config dictionary." )
def getVersion( self ):
""" Return the version of Murmur. """
if self._version is None:
self._version = self.ctl.getVersion()
return self._version
version = property( getVersion )
prettyversion = property( lambda self: '.'.join( map( str, self.version[:3] ) ),
doc="Pretty-Printed version" );
class Mumble( models.Model ): class Mumble( models.Model ):
""" Represents a Murmur server instance. """ Represents a Murmur server instance.
@ -475,7 +487,7 @@ class Mumble( models.Model ):
if not self.netloc: if not self.netloc:
return None return None
from urlparse import urlunsplit from urlparse import urlunsplit
versionstr = "version=%d.%d.%d" % tuple(self.version[:3]);
versionstr = "version=%s" % self.prettyversion;
if forUser is not None: if forUser is not None:
netloc = "%s@%s" % ( forUser.name, self.netloc ); netloc = "%s@%s" % ( forUser.name, self.netloc );
return urlunsplit(( "mumble", netloc, "", versionstr, "" )) return urlunsplit(( "mumble", netloc, "", versionstr, "" ))
@ -484,7 +496,8 @@ class Mumble( models.Model ):
connecturl = property( getURL ); connecturl = property( getURL );
version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." );
version = property( lambda self: self.server.version, doc="The version of Murmur." );
prettyversion = property( lambda self: self.server.prettyversion );
def asDict( self ): def asDict( self ):
return { 'name': self.name, return { 'name': self.name,

2
pyweb/mumble/templates/mumble/mumble.html

@ -30,7 +30,7 @@
{% if DBaseObject.url %} {% if DBaseObject.url %}
<li>{% trans "Website" %}: {{ DBaseObject.url|urlize }}</li> <li>{% trans "Website" %}: {{ DBaseObject.url|urlize }}</li>
{% endif %} {% endif %}
<li>{% trans "Server version" %}: {{ DBaseObject.version.0 }}.{{ DBaseObject.version.1 }}.{{ DBaseObject.version.2 }}</li>
<li>{% trans "Server version" %}: {{ DBaseObject.prettyversion }}</li>
<li><a href="{% url mumble.views.mobile_show DBaseObject.id %}">{% trans "Minimal view" %}</a></li> <li><a href="{% url mumble.views.mobile_show DBaseObject.id %}">{% trans "Minimal view" %}</a></li>
</ul> </ul>
<fieldset> <fieldset>

Loading…
Cancel
Save