def nodes_delete(request, graph_slug, node_id): graph = get_object_or_404(Graph, slug=graph_slug) node = graph.nodes.get(node_id) nodetype = get_object_or_404(NodeType, id=node.label) # relationshiptype = get_object_or_404(RelationshipType, # id=relationshiptype_id) # count = len(graph.relationships.filter(label=relationshiptype.id, # properties=False)) # redirect_url = reverse("schema_edit", args=[graph.slug]) # if count == 0: # form = TypeDeleteConfirmForm() # if request.POST: # data = request.POST.copy() # form = TypeDeleteConfirmForm(data=data) # if form.is_valid(): # confirm = form.cleaned_data["confirm"] # if confirm: # relationshiptype.delete() # return redirect(redirect_url) # else: form = ItemDeleteConfirmForm() if request.POST: data = request.POST.copy() form = ItemDeleteConfirmForm(data=data) if form.is_valid(): confirm = form.cleaned_data["confirm"] if confirm: for relationship in node.relationships.all(): relationship.delete() media_node = None try: media_node = MediaNode.objects.get(node_id=node.id, data=graph.data) except MediaNode.DoesNotExist: pass except MediaNode.MultipleObjectsReturned: media_nodes = MediaNode.objects.filter(node_id=node.id, data=graph.data) media_node = media_nodes.latest("id") if media_node: media_node.delete() node.delete() redirect_url = reverse("nodes_list", args=[graph.slug]) return redirect(redirect_url) return render_to_response( 'nodes_delete.html', { "graph": graph, "item_type_label": _("Node"), "item_type": "node", "item_type_id": nodetype.id, "item_type_name": nodetype.name, "item_type_count": None, # count, "item_type_object": nodetype, "form": form, # form, "item": node, "action": _("Delete") }, context_instance=RequestContext(request))
def nodes_delete(request, graph_slug, node_id): graph = get_object_or_404(Graph, slug=graph_slug) node = graph.nodes.get(node_id) nodetype = get_object_or_404(NodeType, id=node.label) # relationshiptype = get_object_or_404(RelationshipType, # id=relationshiptype_id) # count = len(graph.relationships.filter(label=relationshiptype.id, # properties=False)) # redirect_url = reverse("schema_edit", args=[graph.slug]) # if count == 0: # form = TypeDeleteConfirmForm() # if request.POST: # data = request.POST.copy() # form = TypeDeleteConfirmForm(data=data) # if form.is_valid(): # confirm = form.cleaned_data["confirm"] # if confirm: # relationshiptype.delete() # return redirect(redirect_url) # else: form = ItemDeleteConfirmForm() if request.POST: data = request.POST.copy() form = ItemDeleteConfirmForm(data=data) if form.is_valid(): confirm = form.cleaned_data["confirm"] if confirm: for relationship in node.relationships.all(): relationship.delete() media_node = None try: media_node = MediaNode.objects.get(node_id=node.id, data=graph.data) except MediaNode.DoesNotExist: pass except MediaNode.MultipleObjectsReturned: media_nodes = MediaNode.objects.filter(node_id=node.id, data=graph.data) media_node = media_nodes.latest("id") if media_node: media_node.delete() node.delete() redirect_url = reverse("nodes_list", args=[graph.slug]) return redirect(redirect_url) return render_to_response('nodes_delete.html', {"graph": graph, "item_type_label": _("Node"), "item_type": "node", "item_type_id": nodetype.id, "item_type_name": nodetype.name, "item_type_count": None, # count, "item_type_object": nodetype, "form": form, # form, "item": node, "action": _("Delete") }, context_instance=RequestContext(request))
def nodes_delete(request, graph_slug, node_id): graph = get_object_or_404(Graph, slug=graph_slug) node = graph.nodes.get(node_id) nodetype = get_object_or_404(NodeType, id=node.label) # relationshiptype = get_object_or_404(RelationshipType, # id=relationshiptype_id) # count = len(graph.relationships.filter(label=relationshiptype.id, # properties=False)) # redirect_url = reverse("schema_edit", args=[graph.slug]) # if count == 0: # form = TypeDeleteConfirmForm() # if request.POST: # data = request.POST.copy() # form = TypeDeleteConfirmForm(data=data) # if form.is_valid(): # confirm = form.cleaned_data["confirm"] # if confirm: # relationshiptype.delete() # return redirect(redirect_url) # else: form = ItemDeleteConfirmForm() if request.POST: data = request.POST.copy() as_modal = bool(data.get("asModal", False)) form = ItemDeleteConfirmForm(data=data) if form.is_valid(): # We need to do a int() because without that the value is a string confirm = int(form.cleaned_data["confirm"]) if confirm: if as_modal: # Saving the id of the relationships before deleting the node old_relationship_ids = [] for rel in node.relationships.all(): source_id = rel.source.id target_id = rel.target.id if (source_id == node.id or target_id == node.id): old_relationship_ids.append(str(rel.id)) for relationship in node.relationships.all(): relationship.delete() media_node = None try: media_node = MediaNode.objects.get(node_id=node.id, data=graph.data) except MediaNode.DoesNotExist: pass except MediaNode.MultipleObjectsReturned: media_nodes = MediaNode.objects.filter(node_id=node.id, data=graph.data) media_node = media_nodes.latest("id") if media_node: media_node.delete() node.delete() if as_modal: response = {'type': 'data', 'action': 'delete', 'nodeId': node_id, 'nodeLabel': node.display, 'oldRelationshipIds': old_relationship_ids} return HttpResponse(json.dumps(response), status=200, content_type='application/json') else: redirect_url = reverse("nodes_list", args=[graph.slug]) return redirect(redirect_url) elif not confirm and as_modal: changes = {'action': 'nothing'} return HttpResponse(json.dumps(changes), status=200, content_type='application/json') else: as_modal = bool(request.GET.copy().get("asModal", False)) if as_modal: base_template = 'empty.html' render = render_to_string else: base_template = 'base.html' render = render_to_response delete_url = reverse("nodes_delete", args=[graph_slug, node_id]) broader_context = {"graph": graph, "item_type_label": _("Node"), "item_type": "node", "item_type_id": nodetype.id, "item_type_name": nodetype.name, "item_type_count": None, # count, "item_type_object": nodetype, "form": form, # form, "item": node, "action": _("Delete"), "base_template": base_template, "as_modal": as_modal, "delete_url": delete_url} response = render('nodes_delete.html', broader_context, context_instance=RequestContext(request)) if as_modal: response = {'type': 'html', 'action': 'delete', 'html': response} return HttpResponse(json.dumps(response), status=200, content_type='application/json') else: return response
def nodes_delete(request, graph_slug, node_id): graph = get_object_or_404(Graph, slug=graph_slug) node = graph.nodes.get(node_id) nodetype = get_object_or_404(NodeType, id=node.label) # relationshiptype = get_object_or_404(RelationshipType, # id=relationshiptype_id) # count = len(graph.relationships.filter(label=relationshiptype.id, # properties=False)) # redirect_url = reverse("schema_edit", args=[graph.slug]) # if count == 0: # form = TypeDeleteConfirmForm() # if request.POST: # data = request.POST.copy() # form = TypeDeleteConfirmForm(data=data) # if form.is_valid(): # confirm = form.cleaned_data["confirm"] # if confirm: # relationshiptype.delete() # return redirect(redirect_url) # else: form = ItemDeleteConfirmForm() if request.POST: data = request.POST.copy() as_modal = bool(data.get("asModal", False)) form = ItemDeleteConfirmForm(data=data) if form.is_valid(): # We need to do a int() because without that the value is a string confirm = int(form.cleaned_data["confirm"]) if confirm: if as_modal: # Saving the id of the relationships before deleting the node old_relationship_ids = [] for rel in node.relationships.all(): source_id = rel.source.id target_id = rel.target.id if (source_id == node.id or target_id == node.id): old_relationship_ids.append(str(rel.id)) for relationship in node.relationships.all(): relationship.delete() media_node = None try: media_node = MediaNode.objects.get(node_id=node.id, data=graph.data) except MediaNode.DoesNotExist: pass except MediaNode.MultipleObjectsReturned: media_nodes = MediaNode.objects.filter(node_id=node.id, data=graph.data) media_node = media_nodes.latest("id") if media_node: media_node.delete() node.delete() if as_modal: response = { 'type': 'data', 'action': 'delete', 'nodeId': node_id, 'nodeLabel': node.display, 'oldRelationshipIds': old_relationship_ids } return HttpResponse(json.dumps(response), status=200, content_type='application/json') else: redirect_url = reverse("nodes_list", args=[graph.slug]) return redirect(redirect_url) elif not confirm and as_modal: changes = {'action': 'nothing'} return HttpResponse(json.dumps(changes), status=200, content_type='application/json') else: as_modal = bool(request.GET.copy().get("asModal", False)) if as_modal: base_template = 'empty.html' render = render_to_string else: base_template = 'base.html' render = render_to_response delete_url = reverse("nodes_delete", args=[graph_slug, node_id]) broader_context = { "graph": graph, "item_type_label": _("Node"), "item_type": "node", "item_type_id": nodetype.id, "item_type_name": nodetype.name, "item_type_count": None, # count, "item_type_object": nodetype, "form": form, # form, "item": node, "action": _("Delete"), "base_template": base_template, "as_modal": as_modal, "delete_url": delete_url } response = render('nodes_delete.html', broader_context, context_instance=RequestContext(request)) if as_modal: response = {'type': 'html', 'action': 'delete', 'html': response} return HttpResponse(json.dumps(response), status=200, content_type='application/json') else: return response