Added mixins for reload development
This commit is contained in:
parent
4ab9258bbc
commit
94b449466a
1 changed files with 20 additions and 0 deletions
20
mixins.py
Normal file
20
mixins.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
class ReloadMixin():
|
||||
def cache(self, callback, do_save=True):
|
||||
cache_dict = {}
|
||||
if do_save:
|
||||
if self.save and callable(self.save):
|
||||
self.save()
|
||||
else:
|
||||
raise ValueError("This object does not have a save function, you must pass save=False for this object type.")
|
||||
|
||||
for key, value in self.__dict__.iteritems():
|
||||
if not callable(value):
|
||||
cache_dict[key] = value
|
||||
|
||||
callback(cache_dict)
|
||||
|
||||
def reload(self, cache):
|
||||
for key, value in cache.iteritems():
|
||||
if self.__dict__[key] != value:
|
||||
self.__dict__[key] = value
|
||||
Loading…
Add table
Add a link
Reference in a new issue