Added Channels to new proxy system.

This commit is contained in:
Griatch 2014-12-25 17:08:12 +01:00
parent 9af9f94fa0
commit dd20740e73
3 changed files with 44 additions and 27 deletions

View file

@ -18,6 +18,34 @@ class Channel(ChannelDB):
__metaclass__ = TypeclassBase __metaclass__ = TypeclassBase
objects = ChannelManager() objects = ChannelManager()
def at_first_save(self):
"""
Called by the typeclass system the very first time the channel
is saved to the database. Generally, don't overload this but
the hooks called by this method.
"""
self.at_channel_creation()
if hasattr(self, "_createdict"):
# this is only set if the channel was created
# with the utils.create.create_channel function.
cdict = self._createdict
if not cdict["key"]:
self.db_key = "#i" % self.dbid
elif cdict["key"] and self.key != cdict["key"]:
self.key = cdict["key"]
if cdict["keep_log"]:
self.db_keep_log = cdict["keep_log"]
if cdict["aliases"]:
self.aliases.add(cdict["aliases"])
if cdict["locks"]:
self.locks.add(cdict["locks"])
if cdict["keep_log"]:
self.attributes.add("keep_log", cdict["keep_log"])
if cdict["desc"]:
self.attributes.add("desc", cdict["desc"])
# helper methods, for easy overloading # helper methods, for easy overloading
def channel_prefix(self, msg=None, emit=False): def channel_prefix(self, msg=None, emit=False):

View file

@ -346,7 +346,6 @@ class ChannelDB(TypedObject):
key - main name for channel key - main name for channel
desc - optional description of channel desc - optional description of channel
aliases - alternative names for the channel aliases - alternative names for the channel
keep_log - bool if the channel should remember messages
permissions - perm strings permissions - perm strings
""" """

View file

@ -271,33 +271,23 @@ def create_channel(key, aliases=None, desc=None,
aliases - list of alternative (likely shorter) keynames. aliases - list of alternative (likely shorter) keynames.
locks - lock string definitions locks - lock string definitions
""" """
global _ChannelDB, _channelhandler typeclass = typeclass if typeclass else settings.BASE_CHANNEL_TYPECLASS
if not _ChannelDB:
from src.comms.models import ChannelDB as _ChannelDB if isinstance(typeclass, basestring):
if not _channelhandler: # a path is given. Load the actual typeclass
from src.comms import channelhandler as _channelhandler typeclass = class_from_module(typeclass, settings.CHANNEL_TYPECLASS_PATHS)
if not typeclass:
typeclass = settings.BASE_CHANNEL_TYPECLASS # create new instance
try: new_channel = typeclass(db_key=key)
new_channel = _ChannelDB(typeclass=typeclass, db_key=key)
new_channel.save() # store call signature for the signal
new_channel = new_channel.typeclass new_channel._createdict = {"key":key, "aliases":aliases,
if aliases: "desc":desc, "locks":locks, "keep_log":keep_log}
if not utils.is_iter(aliases):
aliases = [aliases] # this will trigger the save signal which in turn calls the
new_channel.aliases.add(aliases) # at_first_save hook on the typeclass, where the _createdict can be
new_channel.save() # used.
new_channel.db.desc = desc
new_channel.db.keep_log = keep_log
except IntegrityError:
string = "Could not add channel: key '%s' already exists." % key
logger.log_errmsg(string)
return None
if locks:
new_channel.locks.add(locks)
new_channel.save() new_channel.save()
_channelhandler.CHANNELHANDLER.add_channel(new_channel)
new_channel.at_channel_create()
return new_channel return new_channel
channel = create_channel channel = create_channel