示例#1
0
def edit(request, author=None):
    if 'id' in request.POST:
        post = Post.objects.get(pk=request.POST['id'])
    else:
        post = Post(author=author)

    form = PostForm(request.POST, instance=post)
    if form.is_valid():
        post = form.save(commit=False)
        # TODO: build this tag from the author's site domain
        post.atom_id = 'tag:butt:%d:%s' % (post.author.pk, post.slug)
        post.save()

        return HttpResponse(json.dumps({'id': post.pk, 'permalink': post.permalink}))

    return HttpResponseBadRequest(json.dumps(form.errors), content_type='application/json')
示例#2
0
文件: views.py 项目: markpasc/bee
def edit(request, author=None):
    if "id" in request.POST:
        post = Post.objects.get(pk=request.POST["id"])
    else:
        post = Post(author=author)

    form = PostForm(request.POST, instance=post)
    if form.is_valid():
        post = form.save(commit=False)
        # TODO: build this tag from the author's site domain
        if not post.atom_id:
            post.atom_id = "tag:bestendtimesever.com,2009:%s,%s" % (post.author.username, post.slug)
        post.save()

        return HttpResponse(json.dumps({"id": post.pk, "permalink": post.permalink}))

    return HttpResponseBadRequest(json.dumps(form.errors), content_type="application/json")