def put(self): data = request.form user_data = UserData.get_from_username(data['username']) if not user_data: raise Exception("I don't know that person") event = Event.get_from_name(data['event_name']) if not event: raise Exception("I don't know that event") point_record = PointRecord.query(PointRecord.event_name == event.name, PointRecord.username == user_data.username).get() # TODO (phillip): this might allow me to not create new records every time a # new event or user is created because a record will be created when # the client tries to modify a record that should exist # Create a point record if one does not exist if not point_record: # TODO (phillip): does this work with the user key as the ancestor? point_record = PointRecord(parent=user_data.key) point_record.event_name = event.name point_record.username = user_data.username point_record.points_earned = float(data['points-earned']) point_record.put() # TODO (phillip): A put request (and really any other request that creates or # updates an object) should return the new representation of that # object so clients don't need to make more API calls response = jsonify() response.status_code = 204 return response