def add_idea_to_synthesis(request): """Add an idea to an ExplictSubgraphView""" ctx = request.context graph_view = ctx.parent_instance if isinstance(graph_view, Synthesis) and not graph_view.is_next_synthesis: raise HTTPBadRequest("Synthesis is published") content = request.json idea_id = content.get('@id', None) if not idea_id: raise HTTPBadRequest("Post an idea with its @id") idea = Idea.get_instance(idea_id) if not idea: raise HTTPNotFound("Unknown idea") link = SubGraphIdeaAssociation(idea=idea, sub_graph=graph_view) duplicate = link.find_duplicate(False) if duplicate: link.delete() return duplicate.idea.generic_json() graph_view.db.add(link) graph_view.db.expire(graph_view, ["idea_assocs"]) graph_view.send_to_changes() # special location return Response( json.dumps(idea.generic_json()), 201, content_type='application/json', location=request.url + "/" + str(idea.id))
def add_idea_to_synthesis(request): """Add an idea to an ExplictSubgraphView""" ctx = request.context graph_view = ctx.parent_instance if isinstance(graph_view, Synthesis) and not graph_view.is_next_synthesis: raise HTTPBadRequest("Synthesis is published") content = request.json idea_id = content.get('@id', None) if not idea_id: raise HTTPBadRequest("Post an idea with its @id") idea = Idea.get_instance(idea_id) if not idea: raise HTTPNotFound("Unknown idea") link = SubGraphIdeaAssociation(idea=idea, sub_graph=graph_view) duplicate = link.find_duplicate(False) if duplicate: link.delete() return duplicate.idea.generic_json() graph_view.db.add(link) graph_view.db.expire(graph_view, ["idea_assocs"]) graph_view.send_to_changes() # special location return Response(json.dumps(idea.generic_json()), 201, content_type='application/json', location=request.url + "/" + str(idea.id))
def remove_idea_from_synthesis(request): """Remove an idea from an ExplictSubgraphView""" ctx = request.context graph_view = ctx.__parent__.parent_instance if isinstance(graph_view, Synthesis) and not graph_view.is_next_synthesis: raise HTTPBadRequest("Synthesis is published") idea = ctx._instance link = SubGraphIdeaAssociation(idea=idea, sub_graph=graph_view) duplicate = link.find_duplicate(True) link.delete() if duplicate: duplicate.delete() graph_view.db.expire(graph_view, ["idea_assocs"]) graph_view.send_to_changes() return {"@tombstone": idea.uri()} else: raise HTTPNotFound("Idea not in view")
def remove_idea_from_synthesis(request): ctx = request.context graph_view = ctx.__parent__.parent_instance if isinstance(graph_view, Synthesis) and not graph_view.is_next_synthesis: raise HTTPBadRequest("Synthesis is published") idea = ctx._instance link = SubGraphIdeaAssociation(idea=idea, sub_graph=graph_view) duplicate = link.find_duplicate(True) link.delete() if duplicate: duplicate.delete() graph_view.db.expire(graph_view, ["idea_assocs"]) graph_view.send_to_changes() return { "@tombstone": idea.uri() } else: raise HTTPNotFound("Idea not in view")