Permalink
Browse files

Fix missing delta changes when adding, updating, and removing items.

  • Loading branch information...
1 parent 29e3c40 commit cac99cc05b6aa71020d7fd007a0b7d90fabc4e42 Ben Weaver committed Apr 14, 2010
Showing with 12 additions and 7 deletions.
  1. +1 −1 examples/demo-server.py
  2. +5 −2 mdb/db/api.py
  3. +6 −4 mdb/db/tree.py
View
@@ -63,7 +63,7 @@ def set_item_create(self, data):
yield folder
def set_item_save(self, data):
- yield db.resolve(data['_path']).update(without_underscores(data))
+ yield db.save(db.resolve(data['_path']), without_underscores(data))
def set_item_remove(self, data):
yield db.remove(db.resolve(data['_path']))
View
@@ -90,8 +90,11 @@ def __init__(self, message, source, mark):
def new(self, cls, state):
key = (state.pop('key', None)
or _tree.Key.make(cls.__kind__, state.pop('key_name', None)))
- obj = cls(**state).update(_key=key)
- self._data[str(key)] = obj
+ return self.changed(cls(**state).update(_key=key))
+
+ def changed(self, *objects):
+ for obj in objects:
+ self._data[str(obj.key)] = obj
return obj
def get(self, key):
View
@@ -14,7 +14,7 @@
__all__ = _tree.__all__ + (
'Item', 'Folder', 'Site', 'Subdomain', 'Page',
'root', 'query', 'path', 'resolve',
- 'make', 'add', 'remove'
+ 'make', 'add', 'save', 'remove'
)
@@ -153,13 +153,15 @@ def make(cls, **kw):
return add(folder, item) if folder else item
def add(folder, item):
- folder.add(item)
- return item
+ return api.branch().changed(folder.add(item), item)
+
+def save(item, *args, **kw):
+ return api.branch().changed(item.update(*args, **kw))
def remove(child):
if child == root():
raise ValueError('Cannot remove the root item.')
- folder = child.parent.remove(child)
+ folder = api.branch().changed(child.parent.remove(child))
api._delete(list(walk(child)))
return folder

0 comments on commit cac99cc

Please sign in to comment.