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))
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))
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))