Browse Source

add draft for an XML serialization for mumbleviewer-ng <http://bitbucket.org/nodefab/mumbleviewer-ng>

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
8ec67e9e0c
  1. 1
      .hgignore
  2. 21
      pyweb/mumble/mmobjects.py
  3. 6
      pyweb/mumble/models.py
  4. 1
      pyweb/mumble/urls.py
  5. 11
      pyweb/mumble/views.py

1
.hgignore

@ -7,3 +7,4 @@ syntax: glob
*~
.directory
.secret.txt
htdocs/mviewtest

21
pyweb/mumble/mmobjects.py

@ -22,6 +22,7 @@ from time import time
from django.utils.http import urlquote
from django.conf import settings
def cmp_names( left, rite ):
""" Compare two objects by their name property. """
return cmp( left.name, rite.name );
@ -147,7 +148,18 @@ class mmChannel( object ):
chandata['players'] = [ pl.asDict() for pl in self.players ];
chandata['subchans'] = [ sc.asDict() for sc in self.subchans ];
return chandata;
def asXml( self, parentnode ):
from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "item" , id=self.id, rel='channel' )
content = SubElement( me, "content" )
name = SubElement( content , "name" )
name.text = self.name
for sc in self.subchans:
sc.asXml(me)
for pl in self.players:
pl.asXml(me)
@ -234,6 +246,13 @@ class mmPlayer( object ):
pldata['texture'] = self.mumbleuser.textureUrl;
return pldata;
def asXml( self, parentnode ):
from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "item" , id=self.id, rel='user' )
content = SubElement( me, "content" )
name = SubElement( content , "name" )
name.text = self.name

6
pyweb/mumble/models.py

@ -460,6 +460,12 @@ class Mumble( models.Model ):
'root': self.rootchan.asDict()
};
def asXml( self ):
from xml.etree.cElementTree import Element
root = Element("root")
self.rootchan.asXml(root)
return root
# "server" field protection
def __setattr__( self, name, value ):
if name == 'server':

1
pyweb/mumble/urls.py

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

11
pyweb/mumble/views.py

@ -59,9 +59,11 @@ def redir( request ):
else:
return HttpResponseRedirect( reverse( mumbles ) );
def mobile_mumbles( request ):
return mumbles( request, mobile=True );
def mumbles( request, mobile=False ):
""" Display a list of all configured Mumble servers, or redirect if only one configured. """
mms = Mumble.objects.all().order_by( "name" );
@ -382,3 +384,12 @@ def mmng_tree( request, server ):
mimetype='text/javascript'
);
def mumbleviewer_tree_xml( request, server ):
from xml.etree.cElementTree import tostring as xml_to_string
srv = get_object_or_404( Mumble, id=int(server) );
return HttpResponse(
xml_to_string( srv.asXml(), encoding='utf-8' ),
mimetype='text/xml'
);
Loading…
Cancel
Save