Refactoring: Simple is better than complex

Signed-off-by: Wilson Júnior <wilsonpjunior@gmail.com>
This commit is contained in:
Wilson Júnior
2014-11-29 23:48:58 -02:00
parent 80f80cd31f
commit 2b3bb81fae
3 changed files with 20 additions and 28 deletions

View File

@@ -68,7 +68,7 @@ class BaseDocument(object):
# Exception.
if not self._dynamic:
for var in values.keys():
if var not in self._fields.keys() + ['id', 'pk', '_cls']:
if var not in self._fields.keys() + ['id', 'pk', '_cls', '_text_score']:
msg = (
"The field '{0}' does not exist on the document '{1}'"
).format(var, self._class_name)
@@ -281,6 +281,16 @@ class BaseDocument(object):
"""
pass
def get_text_score(self):
"""
Get text score from text query
"""
if '_text_score' not in self._data:
raise InvalidDocumentError('This document is not originally built from a text query')
return self._data['_text_score']
def to_mongo(self, use_db_field=True, fields=[]):
"""
Return as SON data ready for use with MongoDB.