Browse Source

add a JSON data source for mumbleviewer-ng.

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
f595868302
  1. 34
      pyweb/mumble/mmobjects.py
  2. 9
      pyweb/mumble/models.py
  3. 1
      pyweb/mumble/urls.py
  4. 16
      pyweb/mumble/views.py

34
pyweb/mumble/mmobjects.py

@ -149,7 +149,8 @@ class mmChannel( object ):
chandata['subchans'] = [ sc.asDict() for sc in self.subchans ]; chandata['subchans'] = [ sc.asDict() for sc in self.subchans ];
return chandata; return chandata;
def asXml( self, parentnode ):
def asMvXml( self, parentnode ):
""" Return an XML tree for this channel suitable for MumbleViewer-ng. """
from xml.etree.cElementTree import SubElement from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "item" , id=self.id, rel='channel' ) me = SubElement( parentnode, "item" , id=self.id, rel='channel' )
content = SubElement( me, "content" ) content = SubElement( me, "content" )
@ -157,9 +158,23 @@ class mmChannel( object ):
name.text = self.name name.text = self.name
for sc in self.subchans: for sc in self.subchans:
sc.asXml(me)
sc.asMvXml(me)
for pl in self.players: for pl in self.players:
pl.asXml(me)
pl.asMvXml(me)
def asMvJson( self ):
""" Return a Dict for this channel suitable for MumbleViewer-ng. """
return {
"attributes": {
"href": self.connecturl,
"id": self.id,
"rel": "channel",
},
'data': self.name,
'children': [ sc.asMvJson() for sc in self.subchans ] + \
[ pl.asMvJson() for pl in self.players ],
'state': { False: "closed", True: "open" }[self.top_or_not_empty],
}
@ -247,13 +262,24 @@ class mmPlayer( object ):
return pldata; return pldata;
def asXml( self, parentnode ):
def asMvXml( self, parentnode ):
""" Return an XML node for this player suitable for MumbleViewer-ng. """
from xml.etree.cElementTree import SubElement from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "item" , id=self.id, rel='user' ) me = SubElement( parentnode, "item" , id=self.id, rel='user' )
content = SubElement( me, "content" ) content = SubElement( me, "content" )
name = SubElement( content , "name" ) name = SubElement( content , "name" )
name.text = self.name name.text = self.name
def asMvJson( self ):
""" Return a Dict for this player suitable for MumbleViewer-ng. """
return {
"attributes": {
"id": self.id,
"rel": "user",
},
'data': self.name,
}
class mmACL( object ): class mmACL( object ):

9
pyweb/mumble/models.py

@ -492,12 +492,17 @@ class Mumble( models.Model ):
'root': self.rootchan.asDict() 'root': self.rootchan.asDict()
}; };
def asXml( self ):
def asMvXml( self ):
""" Return an XML tree for this server suitable for MumbleViewer-ng. """
from xml.etree.cElementTree import Element from xml.etree.cElementTree import Element
root = Element("root") root = Element("root")
self.rootchan.asXml(root)
self.rootchan.asMvXml(root)
return root return root
def asMvJson( self ):
""" Return a Dict for this server suitable for MumbleViewer-ng. """
return self.rootchan.asMvJson()
# "server" field protection # "server" field protection
def __setattr__( self, name, value ): def __setattr__( self, name, value ):
if name == 'server': if name == 'server':

1
pyweb/mumble/urls.py

@ -26,6 +26,7 @@ urlpatterns = patterns(
( r'murmur/tree/(?P<server>\d+)', 'mmng_tree' ), ( r'murmur/tree/(?P<server>\d+)', 'mmng_tree' ),
( r'mumbleviewer/(?P<server>\d+).xml', 'mumbleviewer_tree_xml' ), ( r'mumbleviewer/(?P<server>\d+).xml', 'mumbleviewer_tree_xml' ),
( r'mumbleviewer/(?P<server>\d+).json', 'mumbleviewer_tree_json'),
( r'mobile/(?P<server>\d+)', 'mobile_show' ), ( r'mobile/(?P<server>\d+)', 'mobile_show' ),
( r'mobile/?$', 'mobile_mumbles' ), ( r'mobile/?$', 'mobile_mumbles' ),

16
pyweb/mumble/views.py

@ -392,10 +392,24 @@ def mmng_tree( request, server ):
def mumbleviewer_tree_xml( request, server ): def mumbleviewer_tree_xml( request, server ):
""" Get the XML tree from the server and serialize it to the client. """
from xml.etree.cElementTree import tostring as xml_to_string from xml.etree.cElementTree import tostring as xml_to_string
srv = get_object_or_404( Mumble, id=int(server) ); srv = get_object_or_404( Mumble, id=int(server) );
return HttpResponse( return HttpResponse(
xml_to_string( srv.asXml(), encoding='utf-8' ),
xml_to_string( srv.asMvXml(), encoding='utf-8' ),
mimetype='text/xml' mimetype='text/xml'
); );
def mumbleviewer_tree_json( request, server ):
""" Get the Dict from the server and serialize it as JSON to the client. """
srv = get_object_or_404( Mumble, id=int(server) );
if "jsonp_callback" in request.GET:
prefix = request.GET["jsonp_callback"]
else:
prefix = ""
return HttpResponse(
prefix + "(" + simplejson.dumps( srv.asMvJson() ) + ")",
mimetype='text/javascript'
);
Loading…
Cancel
Save