Removed .typeclass and .dbobj references in codebase.

This commit is contained in:
Griatch 2015-01-02 20:48:34 +01:00
parent 1130dc5757
commit 70da53569d
23 changed files with 60 additions and 127 deletions

View file

@ -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

View file

@ -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

View file

@ -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)