keys starting with underscore are not part of the document

This commit is contained in:
Noah Levitt 2017-02-24 16:40:33 -08:00
parent abdecc46b8
commit 3c1faded3c
2 changed files with 14 additions and 11 deletions

View File

@ -178,20 +178,24 @@ class Document(dict, object):
rethinker.table_create(cls.table).run()
def __init__(self, rethinker, d={}):
dict.__setattr__(self, '_r', rethinker)
dict.__setattr__(self, '_pk', None)
self._r = rethinker
self._pk = None
self._clear_updates()
for k in d:
self[k] = watch(d[k], callback=self._updated, field=k)
def _clear_updates(self):
dict.__setattr__(self, '_updates', {})
dict.__setattr__(self, '_deletes', set())
self._updates = {}
self._deletes = set()
def __setitem__(self, key, value):
dict.__setitem__(
self, key, watch(value, callback=self._updated, field=key))
self._updated(key)
# keys starting with underscore are not part of the document
if key[:1] == '_':
dict.__setattr__(self, key, value)
else:
dict.__setitem__(
self, key, watch(value, callback=self._updated, field=key))
self._updated(key)
__setattr__ = __setitem__
__getattr__ = dict.__getitem__
@ -223,7 +227,7 @@ class Document(dict, object):
pk = self._r.db('rethinkdb').table('table_config').filter({
'db': self._r.dbname, 'name': self.table}).get_field(
'primary_key')[0].run()
dict.__setattr__(self, '_pk', pk)
self._pk = pk
except Exception as e:
raise Exception(
'problem determining primary key for table %s.%s: %s',
@ -293,4 +297,3 @@ class Document(dict, object):
dict.__setitem__(
self, k, watch(d[k], callback=self._updated, field=k))

View File

@ -3,7 +3,7 @@ import codecs
setuptools.setup(
name='rethinkstuff',
version='0.2.0.dev60',
version='0.2.0.dev61',
packages=['rethinkstuff'],
classifiers=[
'Programming Language :: Python :: 2.7',
@ -15,7 +15,7 @@ setuptools.setup(
url='https://github.com/nlevitt/rethinkstuff',
author='Noah Levitt',
author_email='nlevitt@archive.org',
description='Rudimentary rethinkdb python library with some smarts, perhaps some dumbs',
description='rethinkdb python library',
long_description=codecs.open(
'README.rst', mode='r', encoding='utf-8').read(),
)