コード例 #1
0
ファイル: views.py プロジェクト: andrewrk/truthfinder
def add_arg(request, node_id, arg_type):
    parent = get_object_or_404(TruthNode, pk=int(node_id))
    if request.method == 'POST':
        form = CreateNodeForm(request.POST)
        if form.is_valid():
            node = TruthNode()
            node.title = form.cleaned_data.get('title')
            node.content = form.cleaned_data.get('content')
            node.save()

            relate = createRelationship(node, parent, arg_type)

            change = ChangeNotification()
            change.change_type = ChangeNotification.ADD
            change.user = users.get_current_user().nickname()
            change.node = relate.child_node
            change.node_title = relate.child_node.title
            change.pin_type = relate.relationship
            change.parent_node = relate.parent_node
            change.parent_node_title = relate.parent_node.title
            change.save()


            return HttpResponseRedirect(reverse('node', args=[parent.id]))
    else:
        form = CreateNodeForm()

    context = {
        'parent': parent,
        'arg_type': arg_type,
        'arg_type_text': node_relationship_choices[arg_type],
        'form': form,
    }
    return render_to_response('arg.html', context,
        context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: andrewrk/truthfinder
def pin_node(request, node_id):
    child_node = get_object_or_404(TruthNode, pk=int(node_id))
    if request.method == 'POST':
        form = NodeRelationshipForm(request.POST)
        if form.is_valid():
            relate = createRelationship(
                form.cleaned_data.get('child_node'),
                form.cleaned_data.get('parent_node'),
                form.cleaned_data.get('relationship'),
                form.cleaned_data.get('invert_child'))

            change = ChangeNotification()
            change.change_type = ChangeNotification.PIN
            change.user = users.get_current_user().nickname()
            change.node = relate.child_node
            change.node_title = relate.child_node.title
            change.pin_type = relate.relationship
            change.parent_node = relate.parent_node
            change.parent_node_title = relate.parent_node.title
            change.save()

            return HttpResponseRedirect(reverse("node", args=[relate.parent_node.id]))
    else:
        form = NodeRelationshipForm()
    return render_to_response('pin.html', locals(),
        context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: andrewrk/truthfinder
def edit_node(request, node_id):
    node = get_object_or_404(TruthNode, pk=int(node_id))
    if request.method == 'POST':
        form = CreateNodeForm(request.POST)
        if form.is_valid():
            change = ChangeNotification()
            change.change_type = ChangeNotification.EDIT
            change.user = users.get_current_user().nickname()
            change.node = node
            change.node_title = node.title
            change.save()

            node.title = form.cleaned_data.get('title')
            node.content = form.cleaned_data.get('content')
            node.save()

            return HttpResponseRedirect(reverse('node', args=[node.id]))
    else:
        form = CreateNodeForm(initial={
            'title': node.title,
            'content': node.content,
        })

    return render_to_response('add.html', {'form': form}, 
        context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: andrewrk/truthfinder
def delete_node(request, node_id):
    node = get_object_or_404(TruthNode, pk=int(node_id))
    parent_rels = NodeRelationship.objects.filter(child_node__pk=node.pk)
    child_rels = NodeRelationship.objects.filter(parent_node__pk=node.pk)
    rel_types = node_relationship_choices

    if request.method == 'POST':
        change = ChangeNotification()
        change.change_type = ChangeNotification.DELETE
        change.user = users.get_current_user().nickname()
        change.node_title = node.title
        change.save()

        deleteNode(node, parent_rels=parent_rels, child_rels=child_rels)

        return HttpResponseRedirect(reverse('home'))
    else:
        return render_to_response('delete.html', locals(), 
            context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: andrewrk/truthfinder
def unpin_node(request, node_rel_id):
    relationship = get_object_or_404(NodeRelationship, pk=int(node_rel_id))

    if request.method == 'POST':
        change = ChangeNotification()
        change.change_type = ChangeNotification.UNPIN
        change.user = users.get_current_user().nickname()
        change.node = relationship.child_node
        change.node_title = relationship.child_node.title
        change.pin_type = relationship.relationship
        change.parent_node = relationship.parent_node
        change.parent_node_title = relationship.parent_node.title
        change.save()

        deleteRelationship(relationship)

        return HttpResponseRedirect(reverse('node', args=[relationship.parent_node.id]))
    else:
        context = {
            'relationship': relationship,
            'relationship_choices': node_relationship_choices,
        }
        return render_to_response('unpin.html', context,
            context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: andrewrk/truthfinder
def add_node(request):
    if request.method == 'POST':
        form = CreateNodeForm(request.POST)
        if form.is_valid():
            node = TruthNode()
            node.title = form.cleaned_data.get('title')
            node.content = form.cleaned_data.get('content')
            node.save()

            createRelationship(child=node, parent=TruthNode.objects.get(pk=settings.ORPHANS_ID), rel_type=NodeRelationship.PRO, discuss=False)

            change = ChangeNotification()
            change.change_type = ChangeNotification.CREATE
            change.user = users.get_current_user().nickname()
            change.node = node
            change.node_title = node.title
            change.save()

            return HttpResponseRedirect(reverse('node', args=[node.id]))
    else:
        form = CreateNodeForm()

    return render_to_response('add.html', {'form': form}, 
        context_instance=RequestContext(request))