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 createDiscussionNode(relationship): "don't forget to save() after calling this!" try: if relationship.discussion_node is not None: # link is OK, don't duplicate. return except TruthNode.DoesNotExist: # link to discussion is broken. fix below pass invert_text = {True: "n inverted", False: ""} node_title = "[[node %i]] should be a%s %s of [[node %i]]" % (relationship.child_node.id, invert_text[relationship.invert_child], node_relationship_choices[relationship.relationship], relationship.parent_node.id) # if the title already exists, declare that our discussion node. nodes = TruthNode.objects.filter(title=node_title) if nodes.count() == 0: node = TruthNode() node.title = node_title node.save() else: node = nodes[0] # unpin node from discussion orphans NodeRelationship.objects.filter(parent_node__pk=settings.DISCUSSION_ORPHANS_ID, child_node__pk=node.pk).delete() relationship.discussion_node = node
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))