Merge pull request #1813 from volundmush/copy_hook

Added at_object_creation_copy hook to DefaultObject.
This commit is contained in:
Griatch 2019-04-16 18:46:51 +02:00 committed by GitHub
commit 6807d3c658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -933,7 +933,7 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
return obj, errors
def copy(self, new_key=None):
def copy(self, new_key=None, **kwargs):
"""
Makes an identical copy of this object, identical except for a
new dbref in the database. If you want to customize the copy
@ -959,7 +959,22 @@ class DefaultObject(with_metaclass(TypeclassBase, ObjectDB)):
if obj.key.startswith(key) and obj.key.lstrip(key).isdigit())
return "%s%03i" % (key, num)
new_key = new_key or find_clone_key()
return ObjectDB.objects.copy_object(self, new_key=new_key)
new_obj = ObjectDB.objects.copy_object(self, new_key=new_key, **kwargs)
self.at_object_post_copy(new_obj, **kwargs)
return new_obj
def at_object_post_copy(self, new_obj, **kwargs):
"""
Called by DefaultObject.copy(). Meant to be overloaded. In case there's extra data not covered by
.copy(), this can be used to deal with it.
Args:
new_obj (Object): The new Copy of this object.
Returns:
None
"""
pass
def delete(self):
"""