def post(self, request, graphid=None): ret = {} try: if self.action == 'import_graph': graph_file = request.FILES.get('importedGraph').read() graphs = JSONDeserializer().deserialize(graph_file)['graph'] ret = GraphImporter.import_graph(graphs) else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == 'new_graph': isresource = data['isresource'] if 'isresource' in data else False name = _('New Resource Model') if isresource else _('New Branch') author = request.user.first_name + ' ' + request.user.last_name ret = Graph.new(name=name,is_resource=isresource,author=author) elif self.action == 'update_node': graph.update_node(data) ret = graph graph.save() elif self.action == 'update_node_layer': nodeid = uuid.UUID(str(data.get('nodeid'))) node = graph.nodes[nodeid] node.config = data['config'] ret = graph node.save() elif self.action == 'append_branch': ret = graph.append_branch(data['property'], nodeid=data['nodeid'], graphid=data['graphid']) graph.save() elif self.action == 'move_node': ret = graph.move_node(data['nodeid'], data['property'], data['newparentnodeid']) graph.save() elif self.action == 'clone_graph': clone_data = graph.copy() ret = clone_data['copy'] ret.save() ret.copy_functions(graph, [clone_data['nodes'], clone_data['nodegroups']]) form_map = ret.copy_forms(graph, clone_data['cards']) ret.copy_reports(graph, [form_map, clone_data['cards'], clone_data['nodes']]) return JSONResponse(ret) except GraphValidationError as e: return JSONResponse({'status':'false','message':e.message, 'title':e.title}, status=500)
def post(self, request, graphid=None): ret = {} if self.action == 'import_graph': graph_file = request.FILES.get('importedGraph').read() graphs = JSONDeserializer().deserialize(graph_file)['graph'] GraphImporter.import_graph(graphs) for graph in graphs: ret = graph else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == 'new_graph': isresource = data['isresource'] if 'isresource' in data else False name = _('New Resource Model') if isresource else _('New Branch') author = request.user.first_name + ' ' + request.user.last_name ret = Graph.new(name=name,is_resource=isresource,author=author) elif self.action == 'update_node': graph.update_node(data) ret = graph graph.save() elif self.action == 'append_branch': ret = graph.append_branch(data['property'], nodeid=data['nodeid'], graphid=data['graphid']) graph.save() elif self.action == 'move_node': ret = graph.move_node(data['nodeid'], data['property'], data['newparentnodeid']) graph.save() elif self.action == 'clone_graph': ret = graph.copy() ret.save() return JSONResponse(ret)
def post(self, request, graphid=None): ret = {} try: if self.action == 'import_graph': graph_file = request.FILES.get('importedGraph').read() graphs = JSONDeserializer().deserialize(graph_file)['graph'] ret = GraphImporter.import_graph(graphs) else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == 'new_graph': isresource = data['isresource'] if 'isresource' in data else False name = _('New Resource Model') if isresource else _('New Branch') author = request.user.first_name + ' ' + request.user.last_name ret = Graph.new(name=name,is_resource=isresource,author=author) elif self.action == 'update_node': graph.update_node(data) ret = graph graph.save() elif self.action == 'append_branch': ret = graph.append_branch(data['property'], nodeid=data['nodeid'], graphid=data['graphid']) graph.save() elif self.action == 'move_node': ret = graph.move_node(data['nodeid'], data['property'], data['newparentnodeid']) graph.save() elif self.action == 'clone_graph': clone_data = graph.copy() ret = clone_data['copy'] ret.save() ret.copy_functions(graph, [clone_data['nodes'], clone_data['nodegroups']]) form_map = ret.copy_forms(graph, clone_data['cards']) ret.copy_reports(graph, [form_map, clone_data['cards'], clone_data['nodes']]) return JSONResponse(ret) except GraphValidationError as e: return JSONResponse({'status':'false','message':e.message, 'title':e.title}, status=500)
def post(self, request, graphid=None): ret = {} if self.action == 'import_graph': graph_file = request.FILES.get('importedGraph').read() graphs = JSONDeserializer().deserialize(graph_file)['graph'] ret = GraphImporter.import_graph(graphs) else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == 'new_graph': isresource = data[ 'isresource'] if 'isresource' in data else False name = _('New Resource Model') if isresource else _( 'New Branch') author = request.user.first_name + ' ' + request.user.last_name ret = Graph.new(name=name, is_resource=isresource, author=author) elif self.action == 'update_node': graph.update_node(data) ret = graph graph.save() elif self.action == 'append_branch': ret = graph.append_branch(data['property'], nodeid=data['nodeid'], graphid=data['graphid']) graph.save() elif self.action == 'move_node': ret = graph.move_node(data['nodeid'], data['property'], data['newparentnodeid']) graph.save() elif self.action == 'clone_graph': ret = graph.copy() ret.save() return JSONResponse(ret)
def post(self, request, graphid=None): ret = {} try: if self.action == "import_graph": graph_file = request.FILES.get("importedGraph").read() graphs = JSONDeserializer().deserialize(graph_file)["graph"] ret = GraphImporter.import_graph(graphs) else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == "new_graph": isresource = data[ "isresource"] if "isresource" in data else False name = _("New Resource Model") if isresource else _( "New Branch") author = request.user.first_name + " " + request.user.last_name ret = Graph.new(name=name, is_resource=isresource, author=author) elif self.action == "update_node": old_node_data = graph.nodes.get(uuid.UUID(data["nodeid"])) nodegroup_changed = str( old_node_data.nodegroup_id) != data["nodegroup_id"] updated_values = graph.update_node(data) if "nodeid" in data and nodegroup_changed is False: graph.save(nodeid=data["nodeid"]) else: graph.save() ret = JSONSerializer().serializeToPython(graph) ret["updated_values"] = updated_values ret["default_card_name"] = graph.temp_node_name elif self.action == "update_node_layer": nodeid = uuid.UUID(str(data.get("nodeid"))) node = graph.nodes[nodeid] node.config = data["config"] ret = graph node.save() elif self.action == "append_branch": ret = graph.append_branch(data["property"], nodeid=data["nodeid"], graphid=data["graphid"]) ret = ret.serialize() ret["nodegroups"] = graph.get_nodegroups() ret["cards"] = graph.get_cards() ret["widgets"] = graph.get_widgets() graph.save() elif self.action == "append_node": ret = graph.append_node(nodeid=data["nodeid"]) graph.save() elif self.action == "move_node": ret = graph.move_node(data["nodeid"], data["property"], data["newparentnodeid"]) graph.save() elif self.action == "export_branch": clone_data = graph.copy(root=data) clone_data["copy"].slug = None clone_data["copy"].save() ret = {"success": True, "graphid": clone_data["copy"].pk} elif self.action == "clone_graph": clone_data = graph.copy() ret = clone_data["copy"] ret.slug = None ret.save() ret.copy_functions( graph, [clone_data["nodes"], clone_data["nodegroups"]]) elif self.action == "reorder_nodes": json = request.body if json is not None: data = JSONDeserializer().deserialize(json) if "nodes" in data and len(data["nodes"]) > 0: sortorder = 0 with transaction.atomic(): for node in data["nodes"]: no = models.Node.objects.get( pk=node["nodeid"]) no.sortorder = sortorder no.save() sortorder = sortorder + 1 ret = data return JSONResponse(ret) except GraphValidationError as e: return JSONErrorResponse(e.title, e.message, {"status": "Failed"}) except ModelInactiveError as e: return JSONErrorResponse(e.title, e.message) except RequestError as e: return JSONErrorResponse( _("Elasticsearch indexing error"), _("""If you want to change the datatype of an existing node. Delete and then re-create the node, or export the branch then edit the datatype and re-import the branch.""" ), )
def post(self, request, graphid=None): ret = {} try: if self.action == 'import_graph': graph_file = request.FILES.get('importedGraph').read() graphs = JSONDeserializer().deserialize(graph_file)['graph'] ret = GraphImporter.import_graph(graphs) else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == 'new_graph': isresource = data[ 'isresource'] if 'isresource' in data else False name = _('New Resource Model') if isresource else _( 'New Branch') author = request.user.first_name + ' ' + request.user.last_name ret = Graph.new(name=name, is_resource=isresource, author=author) elif self.action == 'update_node': updated_values = graph.update_node(data) graph.save() ret = JSONSerializer().serializeToPython(graph) ret['updated_values'] = updated_values elif self.action == 'update_node_layer': nodeid = uuid.UUID(str(data.get('nodeid'))) node = graph.nodes[nodeid] node.config = data['config'] ret = graph node.save() elif self.action == 'append_branch': ret = graph.append_branch(data['property'], nodeid=data['nodeid'], graphid=data['graphid']) ret = ret.serialize() ret['nodegroups'] = graph.get_nodegroups() ret['cards'] = graph.get_cards() ret['widgets'] = graph.get_widgets() graph.save() elif self.action == 'append_node': ret = graph.append_node(nodeid=data['nodeid']) graph.save() elif self.action == 'move_node': ret = graph.move_node(data['nodeid'], data['property'], data['newparentnodeid']) graph.save() elif self.action == 'export_branch': clone_data = graph.copy(root=data) clone_data['copy'].save() ret = {'success': True, 'graphid': clone_data['copy'].pk} elif self.action == 'clone_graph': clone_data = graph.copy() ret = clone_data['copy'] ret.save() ret.copy_functions( graph, [clone_data['nodes'], clone_data['nodegroups']]) elif self.action == 'reorder_nodes': json = request.body if json is not None: data = JSONDeserializer().deserialize(json) if 'nodes' in data and len(data['nodes']) > 0: sortorder = 0 with transaction.atomic(): for node in data['nodes']: no = models.Node.objects.get( pk=node['nodeid']) no.sortorder = sortorder no.save() sortorder = sortorder + 1 ret = data return JSONResponse(ret) except GraphValidationError as e: return JSONResponse( { 'status': 'false', 'success': False, 'message': e.message, 'title': e.title }, status=500)
def post(self, request, graphid=None): ret = {} try: if self.action == "import_graph": graph_file = request.FILES.get("importedGraph").read() graphs = JSONDeserializer().deserialize(graph_file)["graph"] ret = GraphImporter.import_graph(graphs) else: if graphid is not None: graph = Graph.objects.get(graphid=graphid) data = JSONDeserializer().deserialize(request.body) if self.action == "new_graph": isresource = data[ "isresource"] if "isresource" in data else False name = _("New Resource Model") if isresource else _( "New Branch") author = request.user.first_name + " " + request.user.last_name ret = Graph.new(name=name, is_resource=isresource, author=author) elif self.action == "update_node": updated_values = graph.update_node(data) graph.save() ret = JSONSerializer().serializeToPython(graph) ret["updated_values"] = updated_values elif self.action == "update_node_layer": nodeid = uuid.UUID(str(data.get("nodeid"))) node = graph.nodes[nodeid] node.config = data["config"] ret = graph node.save() elif self.action == "append_branch": ret = graph.append_branch(data["property"], nodeid=data["nodeid"], graphid=data["graphid"]) ret = ret.serialize() ret["nodegroups"] = graph.get_nodegroups() ret["cards"] = graph.get_cards() ret["widgets"] = graph.get_widgets() graph.save() elif self.action == "append_node": ret = graph.append_node(nodeid=data["nodeid"]) graph.save() elif self.action == "move_node": ret = graph.move_node(data["nodeid"], data["property"], data["newparentnodeid"]) graph.save() elif self.action == "export_branch": clone_data = graph.copy(root=data) clone_data["copy"].save() ret = {"success": True, "graphid": clone_data["copy"].pk} elif self.action == "clone_graph": clone_data = graph.copy() ret = clone_data["copy"] ret.save() ret.copy_functions( graph, [clone_data["nodes"], clone_data["nodegroups"]]) elif self.action == "reorder_nodes": json = request.body if json is not None: data = JSONDeserializer().deserialize(json) if "nodes" in data and len(data["nodes"]) > 0: sortorder = 0 with transaction.atomic(): for node in data["nodes"]: no = models.Node.objects.get( pk=node["nodeid"]) no.sortorder = sortorder no.save() sortorder = sortorder + 1 ret = data return JSONResponse(ret) except GraphValidationError as e: return JSONResponse( { "status": "false", "success": False, "message": e.message, "title": e.title }, status=500)