exclude some fields from conversion

This commit is contained in:
Davide Alberani 2015-05-01 20:40:23 +02:00
parent 90b1a33a3d
commit 943aaa2bcb
2 changed files with 10 additions and 2 deletions

View file

@ -36,6 +36,11 @@ class EventManDB(object):
'increment': '$inc' 'increment': '$inc'
} }
_force_conversion = {
'seq_hex': str,
'persons.seq_hex': str
}
def __init__(self, url=None, dbName='eventman'): def __init__(self, url=None, dbName='eventman'):
"""Initialize the instance, connecting to the database. """Initialize the instance, connecting to the database.
@ -100,6 +105,9 @@ class EventManDB(object):
if isinstance(seq, dict): if isinstance(seq, dict):
d = {} d = {}
for key, item in seq.iteritems(): for key, item in seq.iteritems():
if key in self._force_conversion:
d[key] = self._force_conversion[key](item)
else:
d[key] = self.convert(item) d[key] = self.convert(item)
return d return d
if isinstance(seq, (list, tuple)): if isinstance(seq, (list, tuple)):

View file

@ -383,7 +383,7 @@ class EventsHandler(CollectionHandler):
doc.get('persons') or []) doc.get('persons') or [])
env = self._dict2env(new_person_data) env = self._dict2env(new_person_data)
if person_id is None: if person_id is None:
person_id = new_person_data.get('person_id') person_id = str(new_person_data.get('person_id'))
env.update({'PERSON_ID': person_id, 'EVENT_ID': id_, 'EVENT_TITLE': doc.get('title', '')}) env.update({'PERSON_ID': person_id, 'EVENT_ID': id_, 'EVENT_TITLE': doc.get('title', '')})
stdin_data = {'old': old_person_data, stdin_data = {'old': old_person_data,
'new': new_person_data, 'new': new_person_data,