def delete(self, id): """Delete the location for the given id.""" location = self._authorize_location_by_id(id) try: app.db.locations.remove(location['_id'], safe=True) return Response(status=204, content_type='application/json') except OperationFailure as e: return server_error(str(e))
def put(self, id): """Update the location for the given id.""" self._authorize_location_by_id(id) updated = self._location_from_json_or_400(request.json, required_id=id) try: app.db.locations.save(updated, safe=True) return jsonify(Location.flatten(updated)) except OperationFailure as e: return server_error(str(e))
def post(self): """Create a new location.""" location = self._location_from_json_or_400(request.json) try: app.db.locations.insert(location, safe=True) location = Location.flatten(location) resp = jsonify(location) resp.status_code = 201 resp.headers['Location'] = url_for('.location_view', _method='GET', id=location['id']) return resp except OperationFailure as e: return server_error(str(e))