mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Removed .typeclass and .dbobj references in codebase.
This commit is contained in:
parent
1130dc5757
commit
70da53569d
23 changed files with 60 additions and 127 deletions
|
|
@ -104,7 +104,6 @@ class AttackTimer(Script):
|
|||
"Called every self.interval seconds."
|
||||
if self.obj.db.inactive:
|
||||
return
|
||||
#print "attack timer: at_repeat", self.dbobj.id, self.ndb.twisted_task,
|
||||
# id(self.ndb.twisted_task)
|
||||
if self.obj.db.roam_mode:
|
||||
self.obj.roam()
|
||||
|
|
@ -382,4 +381,4 @@ class Enemy(Mob):
|
|||
string = self.db.respawn_text
|
||||
if not string:
|
||||
string = "%s fades into existence from out of thin air. It's looking pissed." % self.key
|
||||
self.location.msg_contents(string)
|
||||
self.location.msg_contents(string)
|
||||
|
|
|
|||
|
|
@ -44,10 +44,7 @@ class Object(DefaultObject):
|
|||
aliases (list of strings) - aliases to the object. Will be saved to
|
||||
database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
dbobj (Object, read-only) - link to database model. dbobj.typeclass points
|
||||
back to this class
|
||||
typeclass (Object, read-only) - this links back to this class as an
|
||||
identified only. Use self.swap_typeclass() to switch.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,6 @@ class Player(DefaultPlayer):
|
|||
name (string)- wrapper for user.username
|
||||
aliases (list of strings) - aliases to the object. Will be saved to database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
dbobj (Player, read-only) - link to database model. dbobj.typeclass points back to this class
|
||||
typeclass (Player, read-only) - this links back to this class as an identified only. Use self.swap_typeclass() to switch.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
|
|
|
|||
|
|
@ -35,10 +35,6 @@ class ExampleScript(BaseScript):
|
|||
aliases (list of strings) - aliases to the object. Will be saved
|
||||
to database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
dbobj (Object, read-only) - link to database model. dbobj.typeclass
|
||||
points back to this class
|
||||
typeclass (Object, read-only) - this links back to this class as an
|
||||
identified only. Use self.swap_typeclass() to switch.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ class CmdSetObjAlias(MuxCommand):
|
|||
old_aliases = obj.aliases.all()
|
||||
if old_aliases:
|
||||
caller.msg("Cleared aliases from %s: %s" % (obj.key, ", ".join(old_aliases)))
|
||||
obj.dbobj.aliases.clear()
|
||||
obj.aliases.clear()
|
||||
else:
|
||||
caller.msg("No aliases to clear.")
|
||||
return
|
||||
|
|
@ -447,10 +447,10 @@ class CmdCreate(ObjManipCommand):
|
|||
continue
|
||||
if aliases:
|
||||
string = "You create a new %s: %s (aliases: %s)."
|
||||
string = string % (obj.typeclass.typename, obj.name, ", ".join(aliases))
|
||||
string = string % (obj.typename, obj.name, ", ".join(aliases))
|
||||
else:
|
||||
string = "You create a new %s: %s."
|
||||
string = string % (obj.typeclass.typename, obj.name)
|
||||
string = string % (obj.typename, obj.name)
|
||||
# set a default desc
|
||||
if not obj.db.desc:
|
||||
obj.db.desc = "You see nothing special."
|
||||
|
|
@ -1401,7 +1401,7 @@ class CmdTypeclass(MuxCommand):
|
|||
# current one instead.
|
||||
if hasattr(obj, "typeclass"):
|
||||
string = "%s's current typeclass is '%s' (%s)." % (obj.name,
|
||||
obj.typeclass.typename, obj.typeclass.path)
|
||||
obj.typename, obj.path)
|
||||
else:
|
||||
string = "%s is not a typed object." % obj.name
|
||||
caller.msg(string)
|
||||
|
|
@ -1427,7 +1427,7 @@ class CmdTypeclass(MuxCommand):
|
|||
ok = obj.swap_typeclass(typeclass, clean_attributes=reset)
|
||||
if ok:
|
||||
if is_same:
|
||||
string = "%s updated its existing typeclass (%s).\n" % (obj.name, obj.typeclass.path)
|
||||
string = "%s updated its existing typeclass (%s).\n" % (obj.name, obj.path)
|
||||
else:
|
||||
string = "%s changed typeclass from %s to %s.\n" % (obj.name,
|
||||
old_typeclass_path,
|
||||
|
|
@ -1677,7 +1677,7 @@ class CmdExamine(ObjManipCommand):
|
|||
string += "\n{wPlayer Perms{n: %s" % (", ".join(perms))
|
||||
if obj.player.attributes.has("_quell"):
|
||||
string += " {r(quelled){n"
|
||||
string += "\n{wTypeclass{n: %s (%s)" % (obj.typeclass.typename,
|
||||
string += "\n{wTypeclass{n: %s (%s)" % (obj.typename,
|
||||
obj.typeclass_path)
|
||||
if hasattr(obj, "location"):
|
||||
string += "\n{wLocation{n: %s" % obj.location
|
||||
|
|
@ -1928,7 +1928,7 @@ class CmdFind(MuxCommand):
|
|||
else:
|
||||
result=result[0]
|
||||
string += "\n{g %s(%s) - %s{n" % (result.key, result.dbref,
|
||||
result.typeclass.path)
|
||||
result.path)
|
||||
else:
|
||||
# Not a player/dbref search but a wider search; build a queryset.
|
||||
# Searchs for key and aliases
|
||||
|
|
@ -1946,7 +1946,7 @@ class CmdFind(MuxCommand):
|
|||
|
||||
if nresults:
|
||||
# convert result to typeclasses.
|
||||
results = [result.typeclass for result in results]
|
||||
results = [result for result in results]
|
||||
if "room" in switches:
|
||||
results = [obj for obj in results if inherits_from(obj, ROOM_TYPECLASS)]
|
||||
if "exit" in switches:
|
||||
|
|
|
|||
|
|
@ -792,7 +792,7 @@ class CmdIRC2Chan(MuxCommand):
|
|||
|
||||
if 'list' in self.switches:
|
||||
# show all connections
|
||||
ircbots = [bot.typeclass for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="ircbot-")]
|
||||
ircbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="ircbot-")]
|
||||
if ircbots:
|
||||
from src.utils.evtable import EvTable
|
||||
table = EvTable("{wdbid{n", "{wbotname{n", "{wev-channel{n", "{wirc-channel{n", maxwidth=78)
|
||||
|
|
@ -842,7 +842,7 @@ class CmdIRC2Chan(MuxCommand):
|
|||
bot = PlayerDB.objects.filter(username__iexact=botname)
|
||||
if bot:
|
||||
# re-use an existing bot
|
||||
bot = bot[0].typeclass
|
||||
bot = bot[0]
|
||||
if not bot.is_bot:
|
||||
self.msg("Player '%s' already exists and is not a bot." % botname)
|
||||
return
|
||||
|
|
@ -901,7 +901,7 @@ class CmdRSS2Chan(MuxCommand):
|
|||
|
||||
if 'list' in self.switches:
|
||||
# show all connections
|
||||
rssbots = [bot.typeclass for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")]
|
||||
rssbots = [bot for bot in PlayerDB.objects.filter(db_is_bot=True, username__startswith="rssbot-")]
|
||||
if rssbots:
|
||||
from src.utils.evtable import EvTable
|
||||
table = EvTable("{wdbid{n", "{wupdate rate{n", "{wev-channel", "{wRSS feed URL{n", border="cells", maxwidth=78)
|
||||
|
|
@ -938,7 +938,7 @@ class CmdRSS2Chan(MuxCommand):
|
|||
bot = PlayerDB.objects.filter(username__iexact=botname)
|
||||
if bot:
|
||||
# re-use existing bot
|
||||
bot = bot[0].typeclass
|
||||
bot = bot[0]
|
||||
if not bot.is_bot:
|
||||
self.msg("Player '%s' already exists and is not a bot." % botname)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ class CmdNick(MuxCommand):
|
|||
string = ""
|
||||
for switch in switches:
|
||||
oldnick = caller.nicks.get(key=nick, category=switch)
|
||||
#oldnick = Nick.objects.filter(db_obj=caller.dbobj, db_nick__iexact=nick, db_type__iexact=switch)
|
||||
if not real:
|
||||
# removal of nick
|
||||
if oldnick:
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ class ChannelDBManager(TypedObjectManager):
|
|||
"""
|
||||
Return all channels a given player is subscribed to
|
||||
"""
|
||||
return player.dbobj.subscription_set.all()
|
||||
return player.__dbclass__.subscription_set.all()
|
||||
|
||||
@returns_typeclass_list
|
||||
def channel_search(self, ostring, exact=True):
|
||||
|
|
|
|||
|
|
@ -223,8 +223,9 @@ class Msg(SharedMemoryModel):
|
|||
def __channels_set(self, value):
|
||||
"""
|
||||
Setter. Allows for self.channels = value.
|
||||
Requires a channel to be added."""
|
||||
for val in (v.dbobj for v in make_iter(value) if v):
|
||||
Requires a channel to be added.
|
||||
"""
|
||||
for val in (v for v in make_iter(value) if v):
|
||||
self.db_receivers_channels.add(val)
|
||||
|
||||
#@channels.deleter
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ def self(accessing_obj, accessed_obj, *args, **kwargs):
|
|||
This can be used to lock specifically only to
|
||||
the same object that the lock is defined on.
|
||||
"""
|
||||
return accessing_obj.typeclass == accessed_obj.typeclass
|
||||
return accessing_obj == accessed_obj
|
||||
|
||||
|
||||
def perm(accessing_obj, accessed_obj, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -119,7 +119,6 @@ class ObjectDBAdmin(admin.ModelAdmin):
|
|||
obj.save()
|
||||
if not change:
|
||||
# adding a new object
|
||||
obj = obj.typeclass
|
||||
obj.basetype_setup()
|
||||
obj.basetype_posthook_setup()
|
||||
obj.at_object_creation()
|
||||
|
|
|
|||
|
|
@ -156,8 +156,6 @@ class ObjectDBManager(TypedObjectManager):
|
|||
if isinstance(property_name, basestring):
|
||||
if not property_name.startswith('db_'):
|
||||
property_name = "db_%s" % property_name
|
||||
if hasattr(property_value, 'dbobj'):
|
||||
property_value = property_value.dbobj
|
||||
querykwargs = {property_name:property_value}
|
||||
cand_restriction = candidates != None and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
|
||||
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||
|
|
@ -299,7 +297,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
|
||||
if candidates:
|
||||
# Convenience check to make sure candidates are really dbobjs
|
||||
candidates = [cand.dbobj for cand in make_iter(candidates) if cand]
|
||||
candidates = [cand for cand in make_iter(candidates) if cand]
|
||||
if typeclass:
|
||||
candidates = [cand for cand in candidates
|
||||
if _GA(cand, "db_typeclass_path") in typeclass]
|
||||
|
|
@ -309,7 +307,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
# Easiest case - dbref matching (always exact)
|
||||
dbref_match = self.dbref_search(dbref)
|
||||
if dbref_match:
|
||||
if not candidates or dbref_match.dbobj in candidates:
|
||||
if not candidates or dbref_match in candidates:
|
||||
return [dbref_match]
|
||||
else:
|
||||
return []
|
||||
|
|
@ -402,7 +400,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
|
||||
# copy over all scripts, if any
|
||||
for script in original_object.scripts.all():
|
||||
ScriptDB.objects.copy_script(script, new_obj=new_object.dbobj)
|
||||
ScriptDB.objects.copy_script(script, new_obj=new_object)
|
||||
|
||||
return new_object
|
||||
|
||||
|
|
|
|||
|
|
@ -115,10 +115,6 @@ class DefaultObject(ObjectDB):
|
|||
aliases (list of strings) - aliases to the object. Will be saved to
|
||||
database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
dbobj (Object, read-only) - link to database model. dbobj.typeclass
|
||||
points back to this class
|
||||
typeclass (Object, read-only) - this links back to this class as an
|
||||
identified only. Use self.swap_typeclass() to switch.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
|
|
@ -886,6 +882,16 @@ class DefaultObject(ObjectDB):
|
|||
if cdict.get("location"):
|
||||
cdict["location"].at_object_receive(self, None)
|
||||
self.at_after_move(None)
|
||||
|
||||
if cdict.get("attributes"):
|
||||
# this should be a dict of attrname:value
|
||||
keys, values = cdict["attributes"].keys(), cdict["attributes"].values()
|
||||
self.attributes.batch_add(keys, values)
|
||||
if cdict.get("nattributes"):
|
||||
# this should be a dict of nattrname:value
|
||||
for key, value in cdict["nattributes"].items():
|
||||
self.nattributes.add(key, value)
|
||||
|
||||
del self._createdict
|
||||
|
||||
self.basetype_posthook_setup()
|
||||
|
|
@ -1437,8 +1443,8 @@ class DefaultExit(DefaultObject):
|
|||
"get:false()"])) # noone can pick up the exit
|
||||
|
||||
# an exit should have a destination (this is replaced at creation time)
|
||||
if self.dbobj.location:
|
||||
self.destination = self.dbobj.location
|
||||
if self.location:
|
||||
self.destination = self.location
|
||||
|
||||
def at_cmdset_get(self, **kwargs):
|
||||
"""
|
||||
|
|
@ -1452,7 +1458,7 @@ class DefaultExit(DefaultObject):
|
|||
|
||||
if "force_init" in kwargs or not self.cmdset.has_cmdset("_exitset", must_be_default=True):
|
||||
# we are resetting, or no exit-cmdset was set. Create one dynamically.
|
||||
self.cmdset.add_default(self.create_exit_cmdset(self.dbobj), permanent=False)
|
||||
self.cmdset.add_default(self.create_exit_cmdset(self), permanent=False)
|
||||
|
||||
# this and other hooks are what usually can be modified safely.
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ class PlayerDBAdmin(BaseUserAdmin):
|
|||
obj.save()
|
||||
if not change:
|
||||
#calling hooks for new player
|
||||
ply = obj.typeclass
|
||||
ply = obj
|
||||
ply.basetype_setup()
|
||||
ply.at_player_creation()
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class CmdBotListen(Command):
|
|||
key = "bot_data_in"
|
||||
def func(self):
|
||||
"Relay to typeclass"
|
||||
self.obj.typeclass.execute_cmd(self.args.strip(), sessid=self.sessid)
|
||||
self.obj.execute_cmd(self.args.strip(), sessid=self.sessid)
|
||||
|
||||
class BotCmdSet(CmdSet):
|
||||
"Holds the BotListen command"
|
||||
|
|
@ -196,9 +196,9 @@ class IRCBot(Bot):
|
|||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if "from_channel" in kwargs and text and self.ndb.ev_channel.dbid == kwargs["from_channel"]:
|
||||
if "from_obj" not in kwargs or kwargs["from_obj"] != [self.dbobj.id]:
|
||||
if "from_obj" not in kwargs or kwargs["from_obj"] != [self.id]:
|
||||
text = "bot_data_out %s" % text
|
||||
self.dbobj.msg(text=text)
|
||||
self.msg(text=text)
|
||||
|
||||
def execute_cmd(self, text=None, sessid=None):
|
||||
"""
|
||||
|
|
@ -209,7 +209,7 @@ class IRCBot(Bot):
|
|||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if self.ndb.ev_channel:
|
||||
self.ndb.ev_channel.msg(text, senders=self.dbobj.id)
|
||||
self.ndb.ev_channel.msg(text, senders=self.id)
|
||||
|
||||
|
||||
# RSS
|
||||
|
|
@ -258,7 +258,7 @@ class RSSBot(Bot):
|
|||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if self.ndb.ev_channel:
|
||||
self.ndb.ev_channel.msg(text, senders=self.dbobj.id)
|
||||
self.ndb.ev_channel.msg(text, senders=self.id)
|
||||
|
||||
class IMC2Bot(Bot):
|
||||
"""
|
||||
|
|
@ -318,9 +318,9 @@ class IMC2Bot(Bot):
|
|||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if "from_channel" in kwargs and text and self.ndb.ev_channel.dbid == kwargs["from_channel"]:
|
||||
if "from_obj" not in kwargs or kwargs["from_obj"] != [self.dbobj.id]:
|
||||
if "from_obj" not in kwargs or kwargs["from_obj"] != [self.id]:
|
||||
text = "bot_data_out %s" % text
|
||||
self.dbobj.msg(text=text)
|
||||
self.msg(text=text)
|
||||
|
||||
def execute_cmd(self, text=None, sessid=None):
|
||||
"""
|
||||
|
|
@ -330,5 +330,5 @@ class IMC2Bot(Bot):
|
|||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if self.ndb.ev_channel:
|
||||
self.ndb.ev_channel.msg(text, senders=self.dbobj.id)
|
||||
self.ndb.ev_channel.msg(text, senders=self.id)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,10 +55,6 @@ class DefaultPlayer(PlayerDB):
|
|||
aliases (list of strings) - aliases to the object. Will be saved to
|
||||
database as AliasDB entries but returned as strings.
|
||||
dbref (int, read-only) - unique #id-number. Also "id" can be used.
|
||||
dbobj (Player, read-only) - link to database model. dbobj.typeclass
|
||||
points back to this class
|
||||
typeclass (Player, read-only) - this links back to this class as an
|
||||
identified only. Use self.swap_typeclass() to switch.
|
||||
date_created (string) - time stamp of object creation
|
||||
permissions (list of strings) - list of permission strings
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class ScriptHandler(object):
|
|||
definition)
|
||||
autostart - start the script upon adding it
|
||||
"""
|
||||
if self.obj.dbobj.__class__.__name__ == "PlayerDB":
|
||||
if self.obj.__class__.__name__ == "PlayerDB":
|
||||
# we add to a Player, not an Object
|
||||
script = create.create_script(scriptclass, key=key, player=self.obj,
|
||||
autostart=autostart)
|
||||
|
|
|
|||
|
|
@ -202,19 +202,10 @@ class TickerHandler(object):
|
|||
is a boolean True if obj was a database object,
|
||||
False otherwise.
|
||||
"""
|
||||
try:
|
||||
obj = obj.typeclass
|
||||
except AttributeError:
|
||||
pass
|
||||
dbobj = None
|
||||
try:
|
||||
dbobj = obj.dbobj
|
||||
except AttributeError:
|
||||
pass
|
||||
isdb = True
|
||||
if dbobj:
|
||||
if hasattr(obj, "db_key"):
|
||||
# create a store_key using the database representation
|
||||
objkey = pack_dbobj(dbobj)
|
||||
objkey = pack_dbobj(obj)
|
||||
isdb = True
|
||||
else:
|
||||
# non-db object, look for a property "key" on it, otherwise
|
||||
# use its memory location.
|
||||
|
|
|
|||
|
|
@ -83,10 +83,6 @@ class TrackerHandler(object):
|
|||
This is initiated and stored on the object as a
|
||||
property _trackerhandler.
|
||||
"""
|
||||
try:
|
||||
obj = obj.dbobj
|
||||
except AttributeError:
|
||||
pass
|
||||
self.obj = obj
|
||||
self.ntrackers = 0
|
||||
# initiate store only with valid on-object fieldnames
|
||||
|
|
@ -194,10 +190,6 @@ class ReportAttributeTracker(TrackerBase):
|
|||
|
||||
def update(self, new_value, *args, **kwargs):
|
||||
"Called by cache when attribute's db_value field updates"
|
||||
try:
|
||||
new_value = new_value.dbobj
|
||||
except AttributeError:
|
||||
new_value = to_str(new_value, force_string=True)
|
||||
kwargs[self.attrname] = new_value
|
||||
# this is a wrapper call for sending oob data back to session
|
||||
self.oobhandler.msg(self.sessid, "report", *args, **kwargs)
|
||||
|
|
@ -282,11 +274,6 @@ class OOBHandler(object):
|
|||
named as propname, this will be used as the property name when assigning
|
||||
the OOB to obj, otherwise tracker_key is used as the property name.
|
||||
"""
|
||||
try:
|
||||
obj = obj.dbobj
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
if not "_trackerhandler" in _GA(obj, "__dict__"):
|
||||
# assign trackerhandler to object
|
||||
_SA(obj, "_trackerhandler", TrackerHandler(obj))
|
||||
|
|
@ -305,10 +292,6 @@ class OOBHandler(object):
|
|||
Remove the OOB from obj. If oob implements an
|
||||
at_delete hook, this will be called with args, kwargs
|
||||
"""
|
||||
try:
|
||||
obj = obj.dbobj
|
||||
except AttributeError:
|
||||
pass
|
||||
try:
|
||||
# call at_remove hook on the trackerclass
|
||||
_GA(obj, "_trackerhandler").remove(propname, trackerclass, *args, **kwargs)
|
||||
|
|
@ -348,10 +331,6 @@ class OOBHandler(object):
|
|||
Object and name in a way the Attribute expects.
|
||||
"""
|
||||
# get the attribute object if we can
|
||||
try:
|
||||
attrobj = obj.dbobj
|
||||
except AttributeError:
|
||||
pass
|
||||
attrobj = obj.attributes.get(attr_name, return_obj=True)
|
||||
#print "track_attribute attrobj:", attrobj, id(attrobj)
|
||||
if attrobj:
|
||||
|
|
@ -361,10 +340,6 @@ class OOBHandler(object):
|
|||
"""
|
||||
Shortcut for deactivating tracking for a given attribute.
|
||||
"""
|
||||
try:
|
||||
obj = obj.dbobj
|
||||
except AttributeError:
|
||||
pass
|
||||
attrobj = obj.attributes.get(attr_name, return_obj=True)
|
||||
if attrobj:
|
||||
self._untrack(attrobj, sessid, "db_value", trackerclass, attr_name)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Attribute(SharedMemoryModel):
|
|||
db_model = models.CharField(
|
||||
'model', max_length=32, db_index=True, blank=True, null=True,
|
||||
help_text="Which model of object this attribute is attached to (A "
|
||||
"natural key like objects.dbobject). You should not change "
|
||||
"natural key like 'objects.dbobject'). You should not change "
|
||||
"this value unless you know what you are doing.")
|
||||
# subclass of Attribute (None or nick)
|
||||
db_attrtype = models.CharField(
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ _GA = object.__getattribute__
|
|||
_SA = object.__setattr__
|
||||
_FROM_MODEL_MAP = None
|
||||
_TO_MODEL_MAP = None
|
||||
_TO_TYPECLASS = lambda o: hasattr(o, 'typeclass') and o.typeclass or o
|
||||
_IS_PACKED_DBOBJ = lambda o: type(o) == tuple and len(o) == 4 and o[0] == '__packed_dbobj__'
|
||||
if uses_database("mysql") and ServerConfig.objects.get_mysql_db_version() < '5.6.4':
|
||||
# mysql <5.6.4 don't support millisecond precision
|
||||
|
|
@ -214,7 +213,7 @@ def pack_dbobj(item):
|
|||
("__packed_dbobj__", key, creation_time, id)
|
||||
"""
|
||||
_init_globals()
|
||||
obj = hasattr(item, 'dbobj') and item.dbobj or item
|
||||
obj = item
|
||||
natural_key = _FROM_MODEL_MAP[hasattr(obj, "id") and hasattr(obj, "db_date_created") and
|
||||
hasattr(obj, '__dbclass__') and obj.__dbclass__.__name__.lower()]
|
||||
# build the internal representation as a tuple
|
||||
|
|
@ -232,16 +231,12 @@ def unpack_dbobj(item):
|
|||
"""
|
||||
_init_globals()
|
||||
try:
|
||||
obj = item[3] and _TO_TYPECLASS(_TO_MODEL_MAP[item[1]].objects.get(id=item[3]))
|
||||
obj = item[3] and _TO_MODEL_MAP[item[1]].objects.get(id=item[3])
|
||||
except ObjectDoesNotExist:
|
||||
return None
|
||||
# even if we got back a match, check the sanity of the date (some
|
||||
# databases may 're-use' the id)
|
||||
try:
|
||||
dbobj = obj.dbobj
|
||||
except AttributeError:
|
||||
dbobj = obj
|
||||
return _TO_DATESTRING(dbobj) == item[2] and obj or None
|
||||
return _TO_DATESTRING(obj) == item[2] and obj or None
|
||||
|
||||
#
|
||||
# Access methods
|
||||
|
|
|
|||
|
|
@ -137,33 +137,17 @@ def _batch_create_object(*objparams):
|
|||
#dbobjs = _ObjectDB.objects.bulk_create(dbobjs)
|
||||
|
||||
objs = []
|
||||
for iobj, dbobj in enumerate(dbobjs):
|
||||
for iobj, obj in enumerate(dbobjs):
|
||||
# call all setup hooks on each object
|
||||
objparam = objparams[iobj]
|
||||
obj = dbobj.typeclass # this saves dbobj if not done already
|
||||
obj.basetype_setup()
|
||||
obj.at_object_creation()
|
||||
|
||||
if objparam[1]:
|
||||
# permissions
|
||||
obj.permissions.add(objparam[1])
|
||||
if objparam[2]:
|
||||
# locks
|
||||
obj.locks.add(objparam[2])
|
||||
if objparam[3]:
|
||||
# aliases
|
||||
obj.aliases.add(objparam[3])
|
||||
if objparam[4]:
|
||||
# nattributes
|
||||
for key, value in objparam[4].items():
|
||||
obj.nattributes.add(key, value)
|
||||
if objparam[5]:
|
||||
# attributes
|
||||
keys, values = objparam[5].keys(), objparam[5].values()
|
||||
obj.attributes.batch_add(keys, values)
|
||||
|
||||
obj.basetype_posthook_setup()
|
||||
objs.append(obj)
|
||||
# setup
|
||||
obj._createdict = {"pernmissions": objparam[1],
|
||||
"locks": objparam[2],
|
||||
"aliases": objparam[3],
|
||||
"attributes": objparam[4],
|
||||
"nattributes": objparam[5]}
|
||||
# this triggers all hooks
|
||||
obj.save()
|
||||
return objs
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -584,7 +584,6 @@ def clean_object_caches(obj):
|
|||
#print "recaching:", obj
|
||||
if not obj:
|
||||
return
|
||||
obj = hasattr(obj, "dbobj") and obj.dbobj or obj
|
||||
# contents cache
|
||||
try:
|
||||
_SA(obj, "_contents_cache", None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue