From 18239ecf0fb098c8b3cea23a3d155e23e1553ecf Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sun, 14 Feb 2010 19:45:35 +0100 Subject: [PATCH] add view to feed Antiarc's AJAX channel viewer (http://tinyurl.com/ydun45e) with data. --- pyweb/mumble/urls.py | 5 +++++ pyweb/mumble/views.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py index 5e3d5d9..9857b49 100644 --- a/pyweb/mumble/urls.py +++ b/pyweb/mumble/urls.py @@ -20,10 +20,15 @@ urlpatterns = patterns( 'mumble.views', ( r'djangousers', 'djangousers' ), ( r'(?P\d+)/users', 'users' ), + ( r'(?P\d+)/(?P\d+)/texture.png', 'showTexture' ), ( r'(?P\d+)/texture.png', 'showTexture' ), + + ( r'murmur/tree/(?P\d+)', 'mmng_tree' ), + ( r'mobile/(?P\d+)', 'mobile_show' ), ( r'mobile/?$', 'mobile_mumbles' ), + ( r'(?P\d+)', 'show' ), ( r'$', 'mumbles' ), ) diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 5e4ff15..2be0afc 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -322,3 +322,45 @@ def djangousers( request ): ); +def mmng_tree( request, server ): + """ JSONify the channel tree to initialize the client's tree structure. """ + + srv = get_object_or_404( Mumble, id=int(server) ); + + chanlist = [] + userlist = [] + + for chanid in srv.channels: + channel = srv.channels[chanid] + state = None # "removed" + chanlist.append({ + "type": "channel", + "id": channel.chanid, + "name": channel.name, + "parent": channel.parent and channel.parent.chanid or -1, + "position": channel.position, + "state": state == None and (channel.temporary and "temporary" or "permanent") or state + }) + + for sessionid in srv.players: + user = srv.players[sessionid] + userlist.append({ + "type": "player", + "name": user.name, + "channel": user.channel.chanid, + "mute": user.mute or user.selfMute or user.suppress, + "deaf": user.deaf or user.selfDeaf or user.suppress, + "online": user.onlinesecs, + "state": "online" # "offline" + }) + + if "callback" in request.GET: + prefix = request.GET["callback"] + else: + prefix = "" + + return HttpResponse( + prefix + "(" + simplejson.dumps( { 'channels': chanlist, 'users': userlist } ) + ")", + mimetype='text/javascript' + ); +