diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index d93fca7..cb2355f 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -128,7 +128,7 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person', Event.personAttended({ _id: $stateParams.id, person_id: person.person_id, - 'persons.$.attended': attended + 'attended': attended }, function(data) { $log.debug('EventDetailsCtrl.personAttended.data'); @@ -212,10 +212,10 @@ eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', ' Event.personAttended({ _id: event._id, person_id: $stateParams.id, - 'persons.$.attended': attended + 'attended': attended }, function(data) { - $scope.events = data = Person.getEvents({_id: $stateParams.id, all: true}); + $scope.events = Person.getEvents({_id: $stateParams.id, all: true}); } ); }; diff --git a/backend.py b/backend.py index 57b9520..df24814 100644 --- a/backend.py +++ b/backend.py @@ -171,7 +171,8 @@ class EventManDB(object): continue return _or - def update(self, collection, _id_or_query, data, operation='update', create=True): + def update(self, collection, _id_or_query, data, operation='update', + updateList=None, create=True): """Update an existing document or create it, if requested. _id_or_query can be an ID, a dict representing a query or a list of tuples. In the latter case, the tuples are put in OR; a tuple match if all of its @@ -185,6 +186,8 @@ class EventManDB(object): :type data: dict :param operation: operation used to update the document or a portion of it, like a list (update, append, appendUnique, delete) :type operation: str + :param updateList: if set, it's considered the name of a list (the first matching element will be updated) + :type updateList: str :param create: if True, the document is created if no document matches :type create: bool @@ -201,6 +204,11 @@ class EventManDB(object): if '_id' in data: del data['_id'] operator = self._operations.get(operation) + if updateList: + newData = {} + for key, value in data.iteritems(): + newData['%s.$.%s' % (updateList, key)] = value + data = newData res = db[collection].find_and_modify(query=_id_or_query, update={operator: data}, full_response=True, new=True, upsert=create) lastErrorObject = res.get('lastErrorObject') or {} diff --git a/eventman_server.py b/eventman_server.py index 5f86453..0ac438a 100755 --- a/eventman_server.py +++ b/eventman_server.py @@ -191,7 +191,7 @@ class EventsHandler(CollectionHandler): # Update an existing entry for a person registered at this event. merged, doc = self.db.update('events', {'_id': id_, 'persons.person_id': person_id}, - data, create=False) + data, updateList='persons', create=False) return {'event': doc} def handle_delete_persons(self, id_, person_id):