Browse Source

add mk_registration_property helper to easily create properties for user registration fields

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
dd56f56429
  1. 34
      pyweb/mumble/models.py

34
pyweb/mumble/models.py

@ -434,6 +434,18 @@ class Mumble( models.Model ):
def mk_registration_property( field, doc="" ):
""" Create a property for the given registration field. """
def get_field( self ):
if "comment" in self.registration:
return self.registration["comment"];
else:
return None;
return property( get_field, doc=doc )
class MumbleUser( models.Model ): class MumbleUser( models.Model ):
""" Represents a User account in Murmur. """ Represents a User account in Murmur.
@ -528,6 +540,7 @@ class MumbleUser( models.Model ):
aclAdmin = property( getAdmin, setAdmin, doc='Admin on root channel' ); aclAdmin = property( getAdmin, setAdmin, doc='Admin on root channel' );
# Registration fetching # Registration fetching
def getRegistration( self ): def getRegistration( self ):
""" Retrieve a user's registration from Murmur as a dict. """ """ Retrieve a user's registration from Murmur as a dict. """
@ -537,26 +550,11 @@ class MumbleUser( models.Model ):
registration = property( getRegistration, doc=getRegistration.__doc__ ); registration = property( getRegistration, doc=getRegistration.__doc__ );
def getComment( self ):
""" Retrieve a user's comment, if any. """
if "comment" in self.registration:
return self.registration["comment"];
else:
return None;
comment = property( getComment, doc=getComment.__doc__ );
def getHash( self ):
""" Retrieve a user's hash, if any. """
if "hash" in self.registration:
return self.registration["hash"];
else:
return None;
comment = mk_registration_property( "comment", doc="The user's comment." );
hash = mk_registration_property( "comment", doc="The user's hash." );
hash = property( getHash, doc=getHash.__doc__ );
# Texture handlers # Texture handlers
def getTexture( self ): def getTexture( self ):
""" Get the user texture as a PIL Image. """ """ Get the user texture as a PIL Image. """
return self.server.ctl.getTexture(self.server.srvid, self.mumbleid); return self.server.ctl.getTexture(self.server.srvid, self.mumbleid);
@ -586,8 +584,8 @@ class MumbleUser( models.Model ):
textureUrl = property( getTextureUrl, doc=getTextureUrl.__doc__ ); textureUrl = property( getTextureUrl, doc=getTextureUrl.__doc__ );
# Deletion handler
# Deletion handler
@staticmethod @staticmethod
def pre_delete_listener( **kwargs ): def pre_delete_listener( **kwargs ):
kwargs['instance'].unregister(); kwargs['instance'].unregister();

Loading…
Cancel
Save