Ejemplo n.º 1
0
 def get_node(self, request, title, user):
     if request.POST.get("node_id", "") == "":
         return Node.objects.create(title=title, slug=make_slug(title),
                                    type="post", comments_allowed=True,
                                    user=user, status="Draft")
     else:
         return get_object_or_404(Node, id=request.POST["node_id"])
Ejemplo n.º 2
0
    def post(self, request):
        title = request.POST.get("title", "no title")
        body = request.POST.get("body", "")
        tags = request.POST.get("tags", "")
        user = get_object_or_404(Users, username=request.user.username)
        node = self.get_node(request, title, user)

        if request.POST.get("preview", "") == "Preview":
            return render(request, self.template_name,
                          dict(preview=True, node_id=node.id,
                               title=title, body=body, tags=tags))
        else:
            node.set_tags(tags)
            node.title = title
            node.slug = make_slug(title)
            Post.objects.create(node=node, body=body,
                                version=node.post_count() + 1, user=user,
                                format="markdown")
            node.status = "Publish"
            node.save()
            cache.clear()
            return HttpResponseRedirect(node.get_absolute_url())