Merge pull request #54 from alberanid/master

fix for integers longer than 8 bytes
This commit is contained in:
Davide Alberani 2015-04-22 23:35:57 +02:00
commit 80a4c70a7b
2 changed files with 22 additions and 9 deletions

View file

@ -80,7 +80,10 @@ class EventManDB(object):
except: except:
pass pass
try: try:
return int(obj) i_obj = int(obj)
if i_obj > 2**64 - 1:
return obj
return i_obj
except: except:
pass pass
return obj return obj

View file

@ -276,10 +276,16 @@ class EventsHandler(CollectionHandler):
collection = 'events' collection = 'events'
object_id = 'event_id' object_id = 'event_id'
def _get_person_data(self, person_id, persons): def _get_person_data(self, person_id_or_query, persons):
"""Filter a list of persons returning the first item with a given person_id
or which set of keys specified in a dictionary match their respective values."""
for person in persons: for person in persons:
if str(person.get('person_id')) == person_id: if isinstance(person_id_or_query, dict):
return person if all(person.get(k) == v for k, v in person_id_or_query.iteritems()):
return person
else:
if str(person.get('person_id')) == person_id_or_query:
return person
return {} return {}
def handle_get_persons(self, id_, resource_id=None): def handle_get_persons(self, id_, resource_id=None):
@ -316,10 +322,14 @@ class EventsHandler(CollectionHandler):
current_event = self.db.query(self.collection, query) current_event = self.db.query(self.collection, query)
if current_event: if current_event:
current_event = current_event[0] current_event = current_event[0]
old_person_data = self._get_person_data(person_id, current_event.get('persons') or []) else:
current_event = {}
old_person_data = self._get_person_data(person_id or self.arguments,
current_event.get('persons') or [])
merged, doc = self.db.update('events', query, merged, doc = self.db.update('events', query,
data, updateList='persons', create=False) data, updateList='persons', create=False)
new_person_data = self._get_person_data(person_id, doc.get('persons') or []) new_person_data = self._get_person_data(person_id or self.arguments,
doc.get('persons') or [])
env = self._dict2env(new_person_data) env = self._dict2env(new_person_data)
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,
@ -386,14 +396,14 @@ class EbCSVImportPersonsHandler(BaseHandler):
for person in persons: for person in persons:
person_data = dict([(k, person[k]) for k in self.keepPersonData person_data = dict([(k, person[k]) for k in self.keepPersonData
if k in person]) if k in person])
merged, person = self.db.update('persons', merged, stored_person = self.db.update('persons',
[('email',), ('name', 'surname')], [('email',), ('name', 'surname')],
person_data) person_data)
if merged: if merged:
reply['merged'] += 1 reply['merged'] += 1
if targetEvent and person: if targetEvent and stored_person:
event_id = targetEvent event_id = targetEvent
person_id = person['_id'] person_id = stored_person['_id']
registered_data = { registered_data = {
'person_id': person_id, 'person_id': person_id,
'attended': False, 'attended': False,