From 37ccd499f3d1a56675ecc050a2a99227ed06e661 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 23 Mar 2010 11:54:14 +0100 Subject: [PATCH] cache the server version in the model, add a property to prettyprint it and display it in the admin. --- pyweb/mumble/admin.py | 9 ++++++++- pyweb/mumble/mmobjects.py | 2 +- pyweb/mumble/models.py | 17 +++++++++++++++-- pyweb/mumble/templates/mumble/mumble.html | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pyweb/mumble/admin.py b/pyweb/mumble/admin.py index 5a9f6a5..18fe52c 100644 --- a/pyweb/mumble/admin.py +++ b/pyweb/mumble/admin.py @@ -22,7 +22,7 @@ from mumble.forms import MumbleServerForm, MumbleAdminForm, MumbleUserAdminForm from mumble.models import MumbleServer, Mumble, MumbleUser class MumbleServerAdmin(admin.ModelAdmin): - list_display = [ 'dbus', 'get_murmur_online' ] + list_display = [ 'dbus', 'get_murmur_online', 'get_murmur_version' ] search_fields = [ 'dbus' ] ordering = [ 'dbus' ] @@ -33,6 +33,13 @@ class MumbleServerAdmin(admin.ModelAdmin): get_murmur_online.short_description = _('Master is running') 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): diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index bde32cc..d0aebd7 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -124,7 +124,7 @@ class mmChannel( object ): mumble://username@host:port/parentchans/self.name """ 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: chanlist = self.parent_channels() + [self.name]; diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index 86b7b96..d9d5df3 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -72,6 +72,7 @@ class MumbleServer( models.Model ): models.Model.__init__( self, *args, **kwargs ); self._ctl = None; self._conf = None; + self._version = None; def __unicode__( self ): return self.dbus; @@ -139,6 +140,17 @@ class MumbleServer( models.Model ): online = property( isOnline ) 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 ): @@ -475,7 +487,7 @@ class Mumble( models.Model ): if not self.netloc: return None from urlparse import urlunsplit - versionstr = "version=%d.%d.%d" % tuple(self.version[:3]); + versionstr = "version=%s" % self.prettyversion; if forUser is not None: netloc = "%s@%s" % ( forUser.name, self.netloc ); return urlunsplit(( "mumble", netloc, "", versionstr, "" )) @@ -484,7 +496,8 @@ class Mumble( models.Model ): 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 ): return { 'name': self.name, diff --git a/pyweb/mumble/templates/mumble/mumble.html b/pyweb/mumble/templates/mumble/mumble.html index 433d8ac..7581117 100644 --- a/pyweb/mumble/templates/mumble/mumble.html +++ b/pyweb/mumble/templates/mumble/mumble.html @@ -30,7 +30,7 @@ {% if DBaseObject.url %}
  • {% trans "Website" %}: {{ DBaseObject.url|urlize }}
  • {% endif %} -
  • {% trans "Server version" %}: {{ DBaseObject.version.0 }}.{{ DBaseObject.version.1 }}.{{ DBaseObject.version.2 }}
  • +
  • {% trans "Server version" %}: {{ DBaseObject.prettyversion }}
  • {% trans "Minimal view" %}