From 8c6ec6a15b7f735bf5bdd3b71b5ee6f2c010c661 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 22 Apr 2015 22:59:56 +0200 Subject: [PATCH 1/2] fixes #53: do not convert integers longer than 8 bytes --- backend.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend.py b/backend.py index 6f74748..bc593e9 100644 --- a/backend.py +++ b/backend.py @@ -80,7 +80,10 @@ class EventManDB(object): except: pass try: - return int(obj) + i_obj = int(obj) + if i_obj > 2**64 - 1: + return obj + return i_obj except: pass return obj From 4e4b6c9e1cb84503d9cf69712e47a76d9c14c10f Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 22 Apr 2015 23:34:53 +0200 Subject: [PATCH 2/2] triggers honored also when the query does not contain the person_id --- eventman_server.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/eventman_server.py b/eventman_server.py index 8e1d4a4..7bfa184 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -276,10 +276,16 @@ class EventsHandler(CollectionHandler): collection = 'events' 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: - if str(person.get('person_id')) == person_id: - return person + if isinstance(person_id_or_query, dict): + 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 {} def handle_get_persons(self, id_, resource_id=None): @@ -316,10 +322,14 @@ class EventsHandler(CollectionHandler): current_event = self.db.query(self.collection, query) if current_event: 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, 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.update({'PERSON_ID': person_id, 'EVENT_ID': id_, 'EVENT_TITLE': doc.get('title', '')}) stdin_data = {'old': old_person_data, @@ -386,14 +396,14 @@ class EbCSVImportPersonsHandler(BaseHandler): for person in persons: person_data = dict([(k, person[k]) for k in self.keepPersonData if k in person]) - merged, person = self.db.update('persons', + merged, stored_person = self.db.update('persons', [('email',), ('name', 'surname')], person_data) if merged: reply['merged'] += 1 - if targetEvent and person: + if targetEvent and stored_person: event_id = targetEvent - person_id = person['_id'] + person_id = stored_person['_id'] registered_data = { 'person_id': person_id, 'attended': False,