From 1aa360cf6c72394c4364831f479425b68afa9dc4 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 18 Dec 2009 09:02:41 +0100 Subject: [PATCH] add drafts for the mumpytz interface that is in planning --- pyweb/mumble/mmobjects.py | 40 ++++++++++++++++++++++++++++++++++++++- pyweb/mumble/models.py | 17 +++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/pyweb/mumble/mmobjects.py b/pyweb/mumble/mmobjects.py index db7072e..db58028 100644 --- a/pyweb/mumble/mmobjects.py +++ b/pyweb/mumble/mmobjects.py @@ -23,7 +23,6 @@ from os.path import join from django.utils.http import urlquote from django.conf import settings - def cmp_names( a, b ): return cmp( a.name, b.name ); @@ -143,6 +142,23 @@ class mmChannel( object ): lambda self: self.server.defchan == self.chanid, doc="True if this channel is the server's default channel." ); + + def as_dict( self ): + if self.parent: + parentid = self.parent.chanid; + else: + parentid = None; + + return { 'chanid': self.chanid, + 'description': self.description, + 'linked': [], + 'linkedIDs': [], + 'name': self.name, + 'parent': parentid, + 'players': [ pl.as_dict() for pl in self.players ], + 'subchans': [ sc.as_dict() for sc in self.subchans ] + }; + @@ -207,6 +223,28 @@ class mmPlayer( object ): def visit( self, callback, lvl = 0 ): """ Call callback on myself. """ callback( self, lvl ); + + def as_dict( self ): + comment = None; + texture = None; + if self.mumbleuser: + comment = self.mumbleuser.comment; + if self.mumbleuser.hasTexture(): + texture = self.mumbleuser.textureUrl; + + return { 'bytesPerSec': self.bytesPerSec, + 'dbaseid': self.dbaseid, + 'deafened': self.deafened, + 'muted': self.muted, + 'name': self.name, + 'onlinesince': self.onlinesince, + 'selfdeafened': self.selfdeafened, + 'selfmuted': self.selfmuted, + 'suppressed': self.suppressed, + 'userid': self.userid, + 'comment': comment, + 'texture': texture, + }; diff --git a/pyweb/mumble/models.py b/pyweb/mumble/models.py index fbde6e7..610c1d7 100644 --- a/pyweb/mumble/models.py +++ b/pyweb/mumble/models.py @@ -26,6 +26,7 @@ from mmobjects import * from mctl import * + class Mumble( models.Model ): """ Represents a Murmur server instance. @@ -364,6 +365,12 @@ class Mumble( models.Model ): connecturl = property( getURL, doc="A convenience wrapper for getURL()." ); version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." ); + + def as_dict( self ): + return { 'name': self.name, + 'id': self.id, + 'root': self.rootchan.as_dict() + }; @@ -508,6 +515,8 @@ class MumbleUser( models.Model ): """Read an image from the infile and install it as the user's texture.""" self.server.ctl.setTexture(self.server.srvid, self.mumbleid, infile) + texture = property( getTexture, setTexture, doc="Get the texture as a PIL Image or read from a file (pass the path)." ); + def hasTexture( self ): try: self.getTexture(); @@ -516,6 +525,14 @@ class MumbleUser( models.Model ): else: return True; + def getTextureUrl( self ): + """ Get a URL under which the texture can be retrieved. """ + from views import showTexture + from django.core.urlresolvers import reverse + return reverse( showTexture, kwargs={ 'server': self.server.id, 'userid': self.id } ); + + textureUrl = property( getTextureUrl, doc=getTextureUrl.__doc__ ); + # Deletion handler @staticmethod