Browse Source

transform mmObjects to use Murmur's data more directly, and change the templates accordingly

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
d925fec378
  1. 132
      pyweb/mumble/mmobjects.py
  2. 4
      pyweb/mumble/models.py
  3. 16
      template/mumble/mumble.htm
  4. 8
      template/mumble/player.htm

132
pyweb/mumble/mmobjects.py

@ -30,45 +30,26 @@ def cmp_names( a, b ):
class mmChannel( object ): class mmChannel( object ):
"""Represents a channel in Murmur.""" """Represents a channel in Murmur."""
# channels = list();
# subchans = list();
# chanid = int();
# name = str();
# parent = mmChannel();
# linked = list();
# linkedIDs = list();
def __init__( self, server, channelObj, parentChan = None ): def __init__( self, server, channelObj, parentChan = None ):
self.server = server; self.server = server;
self.players = list(); self.players = list();
self.subchans = list(); self.subchans = list();
self.linked = list(); self.linked = list();
self.chanid = channelObj.id;
self.name = channelObj.name;
parent = channelObj.parent;
self.linkedIDs = channelObj.links;
if hasattr( channelObj, "description" ):
self.description = channelObj.description;
else:
self.description = "";
if hasattr( channelObj, "temporary" ):
self.temporary = channelObj.temporary;
else:
self.temporary = False;
if hasattr( channelObj, "position" ):
self.position = channelObj.position;
else:
# None would be better imho, but Murmur reports 0 for unknown too.
self.position = 0;
self.channelObj = channelObj;
self.chanid = channelObj.id;
self.linkedIDs = channelObj.links;
self.parent = parentChan; self.parent = parentChan;
if self.parent is not None: if self.parent is not None:
self.parent.subchans.append( self ); self.parent.subchans.append( self );
# Lookup unknown attributes in self.channelObj to automatically include Murmur's fields
def __getattr__( self, key ):
if hasattr( self.channelObj, key ):
return getattr( self.channelObj, key );
else:
raise AttributeError( "'%s' object has no attribute '%s'" % ( self.__class__.__name__, key ) );
def parentChannels( self ): def parentChannels( self ):
"""Return the names of this channel's parents in the channel tree.""" """Return the names of this channel's parents in the channel tree."""
@ -154,23 +135,11 @@ class mmChannel( object ):
doc="True if this channel is the server's default channel." 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,
'temporary': self.temporary,
'position': self.position,
'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 ]
};
def asDict( self ):
chandata = self.channelObj.__dict__.copy();
chandata['players'] = [ pl.asDict() for pl in self.players ];
chandata['subchans'] = [ sc.asDict() for sc in self.subchans ];
return chandata;
@ -178,52 +147,34 @@ class mmChannel( object ):
class mmPlayer( object ): class mmPlayer( object ):
"""Represents a Player in Murmur.""" """Represents a Player in Murmur."""
# muted = bool;
# deafened = bool;
# suppressed = bool;
# selfmuted = bool;
# selfdeafened = bool;
# channel = mmChannel();
# dbaseid = int();
# userid = int();
# name = str();
# onlinesince = time();
# bytesPerSec = int();
# mumbleuser = models.MumbleUser();
def __init__( self, srvInstance, playerObj, playerChan ): def __init__( self, srvInstance, playerObj, playerChan ):
self.userid = playerObj.session;
self.muted = playerObj.mute;
self.deafened = playerObj.deaf;
self.suppressed = playerObj.suppress;
self.selfmuted = playerObj.selfMute;
self.selfdeafened = playerObj.selfDeaf;
chanID = playerObj.channel;
self.dbaseid = playerObj.userid;
self.name = playerObj.name;
onlinetime = playerObj.onlinesecs;
self.bytesPerSec = playerObj.bytespersec;
self.onlinesince = datetime.datetime.fromtimestamp( float( time() - onlinetime ) );
self.channel = playerChan;
self.playerObj = playerObj;
self.onlinesince = datetime.datetime.fromtimestamp( float( time() - playerObj.onlinesecs ) );
self.channel = playerChan;
self.channel.players.append( self ); self.channel.players.append( self );
if self.isAuthed: if self.isAuthed:
from models import Mumble, MumbleUser from models import Mumble, MumbleUser
try: try:
self.mumbleuser = MumbleUser.objects.get( mumbleid=self.dbaseid, server=srvInstance );
self.mumbleuser = MumbleUser.objects.get( mumbleid=self.userid, server=srvInstance );
except MumbleUser.DoesNotExist: except MumbleUser.DoesNotExist:
self.mumbleuser = None; self.mumbleuser = None;
else: else:
self.mumbleuser = None; self.mumbleuser = None;
# Lookup unknown attributes in self.playerObj to automatically include Murmur's fields
def __getattr__( self, key ):
if hasattr( self.playerObj, key ):
return getattr( self.playerObj, key );
else:
raise AttributeError( "'%s' object has no attribute '%s'" % ( self.__class__.__name__, key ) );
def __str__( self ): def __str__( self ):
return '<Player "%s" (%d, %d)>' % ( self.name, self.userid, self.dbaseid );
return '<Player "%s" (%d, %d)>' % ( self.name, self.session, self.userid );
isAuthed = property( isAuthed = property(
lambda self: self.dbaseid != -1,
lambda self: self.userid != -1,
doc="True if this player is authenticated (+A)." doc="True if this player is authenticated (+A)."
); );
@ -240,7 +191,7 @@ class mmPlayer( object ):
playerCount = property( lambda self: -1, doc="Exists only for compatibility to mmChannel." ); playerCount = property( lambda self: -1, doc="Exists only for compatibility to mmChannel." );
id = property( id = property(
lambda self: "player_%d"%self.userid,
lambda self: "player_%d"%self.session,
doc="A string ready to be used in an id property of an HTML tag." doc="A string ready to be used in an id property of an HTML tag."
); );
@ -248,27 +199,14 @@ class mmPlayer( object ):
""" Call callback on myself. """ """ Call callback on myself. """
callback( self, lvl ); callback( self, lvl );
def as_dict( self ):
comment = None;
texture = None;
def asDict( self ):
pldata = self.playerObj.__dict__.copy();
if self.mumbleuser: if self.mumbleuser:
comment = self.mumbleuser.comment;
if self.mumbleuser.hasTexture(): 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,
};
pldata['texture'] = self.mumbleuser.textureUrl;
return pldata;

4
pyweb/mumble/models.py

@ -366,10 +366,10 @@ class Mumble( models.Model ):
version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." ); version = property( lambda self: self.ctl.getVersion(), doc="The version of Murmur." );
def as_dict( self ):
def asDict( self ):
return { 'name': self.name, return { 'name': self.name,
'id': self.id, 'id': self.id,
'root': self.rootchan.as_dict()
'root': self.rootchan.asDict()
}; };

16
template/mumble/mumble.htm

@ -29,7 +29,7 @@
</ul> </ul>
<fieldset> <fieldset>
<legend>{% trans "Welcome message" %}</legend> <legend>{% trans "Welcome message" %}</legend>
{{ DBaseObject.motd|safe }}
{{ DBaseObject.motd|removetags:"script link meta html head body style"|safe }}
</fieldset> </fieldset>
</div> </div>
<div id="mumble_registration" class="mumble-ext"> <div id="mumble_registration" class="mumble-ext">
@ -105,10 +105,10 @@
<li>{% trans "Online since" %} {{ item.onlinesince|time }}</li> <li>{% trans "Online since" %} {{ item.onlinesince|time }}</li>
<li>{% blocktrans with item.isAuthed|yesno as authed %}Authenticated: {{ authed }}{% endblocktrans %}</li> <li>{% blocktrans with item.isAuthed|yesno as authed %}Authenticated: {{ authed }}{% endblocktrans %}</li>
<li>{% blocktrans with item.isAdmin|yesno as admin %}Admin: {{ admin }}{% endblocktrans %}</li> <li>{% blocktrans with item.isAdmin|yesno as admin %}Admin: {{ admin }}{% endblocktrans %}</li>
<li>{% blocktrans with item.muted|yesno as muted %}Muted: {{ muted }}{% endblocktrans %}</li>
<li>{% blocktrans with item.deafened|yesno as deafened %}Deafened: {{ deafened }}{% endblocktrans %}</li>
<li>{% blocktrans with item.selfmuted|yesno as selfmuted %}Muted by self: {{ selfmuted }}{% endblocktrans %}</li>
<li>{% blocktrans with item.selfdeafened|yesno as selfdeafened %}Deafened by self: {{ selfdeafened }}{% endblocktrans %}</li>
<li>{% blocktrans with item.mute|yesno as muted %}Muted: {{ muted }}{% endblocktrans %}</li>
<li>{% blocktrans with item.deaf|yesno as deafened %}Deafened: {{ deafened }}{% endblocktrans %}</li>
<li>{% blocktrans with item.selfMute|yesno as selfmuted %}Muted by self: {{ selfmuted }}{% endblocktrans %}</li>
<li>{% blocktrans with item.selfDeaf|yesno as selfdeafened %}Deafened by self: {{ selfdeafened }}{% endblocktrans %}</li>
</ul> </ul>
{% if item.mumbleuser and item.mumbleuser.owner %} {% if item.mumbleuser and item.mumbleuser.owner %}
<h2>{% trans "User" %} {{ item.mumbleuser.owner.username|capfirst }}</h2> <h2>{% trans "User" %} {{ item.mumbleuser.owner.username|capfirst }}</h2>
@ -120,10 +120,10 @@
<li>{% trans "Sign-up date" %}: {{ item.mumbleuser.owner.date_joined|date }}</li> <li>{% trans "Sign-up date" %}: {{ item.mumbleuser.owner.date_joined|date }}</li>
</ul> </ul>
{% endif %} {% endif %}
{% if item.mumbleuser and item.mumbleuser.comment %}
{% if item.comment %}
<fieldset> <fieldset>
<legend>{% trans "User Comment" %}</legend> <legend>{% trans "User Comment" %}</legend>
{{ item.mumbleuser.comment|safe }}
{{ item.comment|removetags:"script link meta html head body style"|safe }}
</fieldset> </fieldset>
{% endif %} {% endif %}
{% if item.mumbleuser and item.mumbleuser.hasTexture %} {% if item.mumbleuser and item.mumbleuser.hasTexture %}
@ -143,7 +143,7 @@
{% if item.description %} {% if item.description %}
<fieldset> <fieldset>
<legend>{% trans "Channel description" %}</legend> <legend>{% trans "Channel description" %}</legend>
{{ item.description|safe }}
{{ item.description|removetags:"script link meta html head body style"|safe }}
</fieldset> </fieldset>
{% endif %} {% endif %}
</div> </div>

8
template/mumble/player.htm

@ -4,16 +4,16 @@
{% if Player.isAuthed %} {% if Player.isAuthed %}
<img src="{{ MEDIA_URL }}/mumble/authenticated.png" alt="authed" title="Authenticated" /> <img src="{{ MEDIA_URL }}/mumble/authenticated.png" alt="authed" title="Authenticated" />
{% endif %} {% endif %}
{% if Player.muted or Player.suppressed %}
{% if Player.mute or Player.suppress %}
<img src="{{ MEDIA_URL }}/mumble/muted_server.png" alt="muted" title="Muted by server" /> <img src="{{ MEDIA_URL }}/mumble/muted_server.png" alt="muted" title="Muted by server" />
{% endif %} {% endif %}
{% if Player.deafened %}
{% if Player.deaf %}
<img src="{{ MEDIA_URL }}/mumble/deafened_server.png" alt="deafened" title="Deafened by server" /> <img src="{{ MEDIA_URL }}/mumble/deafened_server.png" alt="deafened" title="Deafened by server" />
{% endif %} {% endif %}
{% if Player.selfmuted %}
{% if Player.selfMute %}
<img src="{{ MEDIA_URL }}/mumble/muted_self.png" alt="self-muted" title="Muted by themselves" /> <img src="{{ MEDIA_URL }}/mumble/muted_self.png" alt="self-muted" title="Muted by themselves" />
{% endif %} {% endif %}
{% if Player.selfdeafened %}
{% if Player.selfDeaf %}
<img src="{{ MEDIA_URL }}/mumble/deafened_self.png" alt="self-deafened" title="Deafened by themselves" /> <img src="{{ MEDIA_URL }}/mumble/deafened_self.png" alt="self-deafened" title="Deafened by themselves" />
{% endif %} {% endif %}
</span> </span>

Loading…
Cancel
Save