示例#1
0
def schema_relationshiptype_delete(request, graph_slug, relationshiptype_id):
    graph = get_object_or_404(Graph, slug=graph_slug)
    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 = bool(int(form.cleaned_data["confirm"]))
                if confirm:
                    relationshiptype.delete()
                    return redirect(redirect_url)
    else:
        form = TypeDeleteForm(count=count)
        if request.POST:
            data = request.POST.copy()
            form = TypeDeleteForm(data=data, count=count)
            if form.is_valid():
                option = form.cleaned_data["option"]
                if option == ON_DELETE_CASCADE:
                    graph.relationships.delete(label=relationshiptype.id)
                relationshiptype.delete()
                return redirect(redirect_url)
    return render_to_response('schemas_item_delete.html', {
        "graph": graph,
        "item_type_label": _("Allowed Relationship"),
        "item_type": "relationship",
        "item_type_id": relationshiptype_id,
        "item_type_name": relationshiptype.name,
        "item_type_count": count,
        "item_type_object": relationshiptype,
        "form": form,
        "type_id": relationshiptype_id
    },
                              context_instance=RequestContext(request))
示例#2
0
def schema_nodetype_delete(request, graph_slug, nodetype_id):
    graph = get_object_or_404(Graph, slug=graph_slug)
    nodetype = get_object_or_404(NodeType, id=nodetype_id)
    count = graph.nodes.count(label=nodetype.id)
    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 = bool(int(form.cleaned_data["confirm"]))
                if confirm:
                    nodetype.delete()
                    return redirect(redirect_url)
    else:
        form = TypeDeleteForm(count=count)
        if request.POST:
            data = request.POST.copy()
            form = TypeDeleteForm(data=data, count=count)
            if form.is_valid():
                option = form.cleaned_data["option"]
                if option == ON_DELETE_CASCADE:
                    graph.nodes.delete(label=nodetype.id)
                nodetype.delete()
                return redirect(redirect_url)
    return render_to_response('schemas_item_delete.html', {
        "graph": graph,
        "item_type_label": _("Type"),
        "item_type": "node",
        "item_type_id": nodetype_id,
        "item_type_name": nodetype.name,
        "item_type_count": count,
        "item_type_object": nodetype,
        "form": form,
        "type_id": nodetype_id
    },
                              context_instance=RequestContext(request))
示例#3
0
def schema_relationshiptype_delete(request, graph_slug,
                                   relationshiptype_id):
    graph = get_object_or_404(Graph, slug=graph_slug)
    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 = bool(int(form.cleaned_data["confirm"]))
                if confirm:
                    relationshiptype.delete()
                    return redirect(redirect_url)
    else:
        form = TypeDeleteForm(count=count)
        if request.POST:
            data = request.POST.copy()
            form = TypeDeleteForm(data=data, count=count)
            if form.is_valid():
                option = form.cleaned_data["option"]
                if option == ON_DELETE_CASCADE:
                    graph.relationships.delete(label=relationshiptype.id)
                relationshiptype.delete()
                return redirect(redirect_url)
    return render_to_response('schemas_item_delete.html',
                              {"graph": graph,
                               "item_type_label": _("Allowed Relationship"),
                               "item_type": "relationship",
                               "item_type_id": relationshiptype_id,
                               "item_type_name": relationshiptype.name,
                               "item_type_count": count,
                               "item_type_object": relationshiptype,
                               "form": form,
                               "type_id": relationshiptype_id},
                              context_instance=RequestContext(request))
示例#4
0
文件: views.py 项目: cirocco/Sylva
def schema_nodetype_delete(request, graph_slug, nodetype_id):
    graph = get_object_or_404(Graph, slug=graph_slug)
    nodetype = get_object_or_404(NodeType, id=nodetype_id)
    count = graph.nodes.count(label=nodetype.id)
    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 = bool(int(form.cleaned_data["confirm"]))
                if confirm:
                    nodetype.delete()
                    return redirect(redirect_url)
    else:
        form = TypeDeleteForm(count=count)
        if request.POST:
            data = request.POST.copy()
            form = TypeDeleteForm(data=data, count=count)
            if form.is_valid():
                option = form.cleaned_data["option"]
                if option == ON_DELETE_CASCADE:
                    graph.nodes.delete(label=nodetype.id)
                nodetype.delete()
                return redirect(redirect_url)
    return render_to_response('schemas_item_delete.html',
                              {"graph": graph,
                               "item_type_label": _("Type"),
                               "item_type": "node",
                               "item_type_id": nodetype_id,
                               "item_type_name": nodetype.name,
                               "item_type_count": count,
                               "item_type_object": nodetype,
                               "form": form,
                               "type_id": nodetype_id},
                              context_instance=RequestContext(request))
示例#5
0
文件: views.py 项目: kundeng/Sylva
def schema_nodetype_delete(request, graph_slug, nodetype_id):
    graph = get_object_or_404(Graph, slug=graph_slug)
    nodetype = get_object_or_404(NodeType, id=nodetype_id)
    # We get the modal variable
    as_modal = bool(request.GET.get("asModal", False))
    count = graph.nodes.count(label=nodetype.id)
    redirect_url = reverse("schema_edit", args=[graph.slug])
    if count == 0:
        form = TypeDeleteConfirmForm()
        if request.POST:
            data = request.POST.copy()
            as_modal = bool(data.get("asModal", False))
            form = TypeDeleteConfirmForm(data=data)
            if form.is_valid():
                confirm = bool(int(form.cleaned_data["confirm"]))
                if confirm:
                    nodetype.delete()
                    if as_modal:
                        response = {'type': 'data',
                                    'action': 'schema_main'}
                        return HttpResponse(json.dumps(response), status=200,
                                            content_type='application/json')
                    else:
                        return redirect(redirect_url)
    else:
        form = TypeDeleteForm(count=count)
        if request.POST:
            data = request.POST.copy()
            as_modal = bool(data.get("asModal", False))
            form = TypeDeleteForm(data=data, count=count)
            if form.is_valid():
                option = form.cleaned_data["option"]
                if option == ON_DELETE_CASCADE:
                    graph.nodes.delete(label=nodetype.id)
                nodetype.delete()
                if as_modal:
                    response = {'type': 'data',
                                'action': 'schema_main'}
                    return HttpResponse(json.dumps(response), status=200,
                                        content_type='application/json')
                else:
                    return redirect(redirect_url)
    if as_modal:
        base_template = 'empty.html'
        render = render_to_string
    else:
        base_template = 'base.html'
        render = render_to_response
    add_url = reverse("schema_nodetype_delete", args=[graph_slug, nodetype_id])
    broader_context = {"graph": graph,
                       "item_type_label": _("Type"),
                       "item_type": "node",
                       "item_type_id": nodetype_id,
                       "item_type_name": nodetype.name,
                       "item_type_count": count,
                       "item_type_object": nodetype,
                       "form": form,
                       "type_id": nodetype_id,
                       "base_template": base_template,
                       "add_url": add_url,
                       "schema_main_url": redirect_url,
                       "as_modal": as_modal}
    response = render('schemas_item_delete.html', broader_context,
                      context_instance=RequestContext(request))
    if as_modal:
        response = {'type': 'html',
                    'action': 'schema_nodetype_delete',
                    'html': response}
        return HttpResponse(json.dumps(response), status=200,
                            content_type='application/json')
    else:
        return response
示例#6
0
文件: views.py 项目: kundeng/Sylva
def schema_nodetype_delete(request, graph_slug, nodetype_id):
    graph = get_object_or_404(Graph, slug=graph_slug)
    nodetype = get_object_or_404(NodeType, id=nodetype_id)
    # We get the modal variable
    as_modal = bool(request.GET.get("asModal", False))
    count = graph.nodes.count(label=nodetype.id)
    redirect_url = reverse("schema_edit", args=[graph.slug])
    if count == 0:
        form = TypeDeleteConfirmForm()
        if request.POST:
            data = request.POST.copy()
            as_modal = bool(data.get("asModal", False))
            form = TypeDeleteConfirmForm(data=data)
            if form.is_valid():
                confirm = bool(int(form.cleaned_data["confirm"]))
                if confirm:
                    nodetype.delete()
                    if as_modal:
                        response = {'type': 'data', 'action': 'schema_main'}
                        return HttpResponse(json.dumps(response),
                                            status=200,
                                            content_type='application/json')
                    else:
                        return redirect(redirect_url)
    else:
        form = TypeDeleteForm(count=count)
        if request.POST:
            data = request.POST.copy()
            as_modal = bool(data.get("asModal", False))
            form = TypeDeleteForm(data=data, count=count)
            if form.is_valid():
                option = form.cleaned_data["option"]
                if option == ON_DELETE_CASCADE:
                    graph.nodes.delete(label=nodetype.id)
                nodetype.delete()
                if as_modal:
                    response = {'type': 'data', 'action': 'schema_main'}
                    return HttpResponse(json.dumps(response),
                                        status=200,
                                        content_type='application/json')
                else:
                    return redirect(redirect_url)
    if as_modal:
        base_template = 'empty.html'
        render = render_to_string
    else:
        base_template = 'base.html'
        render = render_to_response
    add_url = reverse("schema_nodetype_delete", args=[graph_slug, nodetype_id])
    broader_context = {
        "graph": graph,
        "item_type_label": _("Type"),
        "item_type": "node",
        "item_type_id": nodetype_id,
        "item_type_name": nodetype.name,
        "item_type_count": count,
        "item_type_object": nodetype,
        "form": form,
        "type_id": nodetype_id,
        "base_template": base_template,
        "add_url": add_url,
        "schema_main_url": redirect_url,
        "as_modal": as_modal
    }
    response = render('schemas_item_delete.html',
                      broader_context,
                      context_instance=RequestContext(request))
    if as_modal:
        response = {
            'type': 'html',
            'action': 'schema_nodetype_delete',
            'html': response
        }
        return HttpResponse(json.dumps(response),
                            status=200,
                            content_type='application/json')
    else:
        return response