Commit d73f94d5 authored by sim's avatar sim

Better handling of hyperdata modification

parent 6ebdc37e
...@@ -10,6 +10,9 @@ from .users import User ...@@ -10,6 +10,9 @@ from .users import User
__all__ = ['Node', 'NodeNode', 'CorpusNode', 'DocumentNode'] __all__ = ['Node', 'NodeNode', 'CorpusNode', 'DocumentNode']
_UNDEFINED = object()
class NodeType(TypeDecorator): class NodeType(TypeDecorator):
"""Define a new type of column to describe a Node's type. """Define a new type of column to describe a Node's type.
Internally, this column type is implemented as an SQL integer. Internally, this column type is implemented as an SQL integer.
...@@ -102,14 +105,21 @@ class Node(ValidatorMixin, Base): ...@@ -102,14 +105,21 @@ class Node(ValidatorMixin, Base):
Base.__init__(self, **kwargs) Base.__init__(self, **kwargs)
def __getitem__(self, key): def __getitem__(self, key):
"""Allow direct access to hyperdata via the bracket operator. """Allow direct access to hyperdata via the bracket operator."""
"""
return self.hyperdata[key] return self.hyperdata[key]
def __setitem__(self, key, value): def __setitem__(self, key, value):
"""Allow direct access to hyperdata via the bracket operator. """Allow direct access to hyperdata via the bracket operator."""
""" old_value = self.hyperdata.get(key, _UNDEFINED)
self.hyperdata[key] = value if old_value != value:
self.hyperdata[key] = value
flag_modified(self, 'hyperdata')
def __delitem(self, key):
"""Allow direct access to hyperdata via the bracket operator."""
if key in self.hyperdata:
del self.hyperdata[key]
flag_modified(self, 'hyperdata')
def __repr__(self): def __repr__(self):
return '<{0.__class__.__name__}(id={0.id}, typename={0.typename!r}, ' \ return '<{0.__class__.__name__}(id={0.id}, typename={0.typename!r}, ' \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment