Various fixes and debugging of weak-ref changes
This commit is contained in:
parent
0030530021
commit
63c099c22f
6 changed files with 24 additions and 81 deletions
|
|
@ -168,78 +168,6 @@ class SharedMemoryModelBase(ModelBase):
|
|||
create_wrapper(cls, fieldname, wrappername, editable=field.editable, foreignkey=foreignkey)
|
||||
return super(SharedMemoryModelBase, cls).__new__(cls, classname, bases, classdict, *args, **kwargs)
|
||||
|
||||
#def __init__(cls, *args, **kwargs):
|
||||
# """
|
||||
# Field shortcut creation:
|
||||
# Takes field names db_* and creates property wrappers named without the db_ prefix. So db_key -> key
|
||||
# This wrapper happens on the class level, so there is no overhead when creating objects. If a class
|
||||
# already has a wrapper of the given name, the automatic creation is skipped. Note: Remember to
|
||||
# document this auto-wrapping in the class header, this could seem very much like magic to the user otherwise.
|
||||
# """
|
||||
# super(SharedMemoryModelBase, cls).__init__(*args, **kwargs)
|
||||
# def create_wrapper(cls, fieldname, wrappername, editable=True):
|
||||
# "Helper method to create property wrappers with unique names (must be in separate call)"
|
||||
# def _get(cls, fname):
|
||||
# "Wrapper for getting database field"
|
||||
# value = _GA(cls, fieldname)
|
||||
# if type(value) in (basestring, int, float, bool):
|
||||
# return value
|
||||
# elif hasattr(value, "typeclass"):
|
||||
# return _GA(value, "typeclass")
|
||||
# return value
|
||||
# def _set_nonedit(cls, fname, value):
|
||||
# "Wrapper for blocking editing of field"
|
||||
# raise FieldError("Field %s cannot be edited." % fname)
|
||||
# def _set(cls, fname, value):
|
||||
# "Wrapper for setting database field"
|
||||
# #print "_set:", fname
|
||||
# if hasattr(value, "dbobj"):
|
||||
# value = _GA(value, "dbobj")
|
||||
# elif isinstance(value, basestring) and (value.isdigit() or value.startswith("#")):
|
||||
# # we also allow setting using dbrefs, if so we try to load the matching object.
|
||||
# # (we assume the object is of the same type as the class holding the field, if
|
||||
# # not a custom handler must be used for that field)
|
||||
# dbid = dbref(value, reqhash=False)
|
||||
# if dbid:
|
||||
# try:
|
||||
# value = cls._default_manager.get(id=dbid)
|
||||
# except ObjectDoesNotExist:
|
||||
# # maybe it is just a name that happens to look like a dbid
|
||||
# from src.utils.logger import log_trace
|
||||
# log_trace()
|
||||
# #print "_set wrapper:", fname, value, type(value), cls._get_pk_val(cls._meta)
|
||||
# _SA(cls, fname, value)
|
||||
# # only use explicit update_fields in save if we actually have a
|
||||
# # primary key assigned already (won't be set when first creating object)
|
||||
# update_fields = [fname] if _GA(cls, "_get_pk_val")(_GA(cls, "_meta")) is not None else None
|
||||
# _GA(cls, "save")(update_fields=update_fields)
|
||||
# def _del_nonedit(cls, fname):
|
||||
# "wrapper for not allowing deletion"
|
||||
# raise FieldError("Field %s cannot be edited." % fname)
|
||||
# def _del(cls, fname):
|
||||
# "Wrapper for clearing database field - sets it to None"
|
||||
# _SA(cls, fname, None)
|
||||
# update_fields = [fname] if _GA(cls, "_get_pk_val")(_GA(cls, "_meta")) is not None else None
|
||||
# _GA(cls, "save")(update_fields=update_fields)
|
||||
|
||||
# # create class field wrappers
|
||||
# fget = lambda cls: _get(cls, fieldname)
|
||||
# fset = lambda cls, val: _set(cls, fieldname, val) if editable else _set_nonedit(cls, fieldname, val)
|
||||
# fdel = lambda cls: _del(cls, fieldname) if editable else _del_nonedit(cls,fieldname)
|
||||
# type(cls).__setattr__(cls, wrappername, property(fget, fset, fdel))#, doc))
|
||||
|
||||
# # exclude some models that should not auto-create wrapper fields
|
||||
# if cls.__name__ in ("ServerConfig", "TypeNick"):
|
||||
# return
|
||||
# # dynamically create the wrapper properties for all fields not already handled
|
||||
# for field in cls._meta.fields:
|
||||
# fieldname = field.name
|
||||
# if fieldname.startswith("db_"):
|
||||
# wrappername = "dbid" if fieldname == "id" else fieldname.replace("db_", "")
|
||||
# if not hasattr(cls, wrappername):
|
||||
# # makes sure not to overload manually created wrappers on the model
|
||||
# #print "wrapping %s -> %s" % (fieldname, wrappername)
|
||||
# create_wrapper(cls, fieldname, wrappername, editable=field.editable)
|
||||
|
||||
class SharedMemoryModel(Model):
|
||||
# CL: setting abstract correctly to allow subclasses to inherit the default
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue