parent
b7b91fa6d6
commit
daa56ba7ac
@ -0,0 +1,25 @@
|
||||
class Editable:
|
||||
def make_copy(self):
|
||||
# delete old copy
|
||||
if hasattr(self, "_copy"):
|
||||
if self._copy is not None:
|
||||
self._copy = None
|
||||
|
||||
# make new copy
|
||||
self._copy = JSON.parse(JSON.stringify(self))
|
||||
|
||||
def copy(self):
|
||||
# check if even initialized
|
||||
if hasattr(self, "_copy"):
|
||||
return self._copy
|
||||
else:
|
||||
return None
|
||||
|
||||
def overwrite_with_copy(self):
|
||||
for key, value in dict(self._copy).items():
|
||||
if key == "_copy":
|
||||
continue
|
||||
setattr(self, key, value)
|
||||
|
||||
self._copy = None
|
||||
|
Loading…
Reference in new issue