Пример #1
0
def update_comment(request):
    refer = request.META.get('HTTP_REFERER', reverse('article:home'))
    form = CommentForms(request.POST)
    data = {}

    if form.is_valid():
        aid = request.POST.get('aid')
        print("aid=", aid)
        comment = Comment()
        # comment = Us
        comment.name = form.cleaned_data['name']
        comment.email = form.cleaned_data['email']
        comment.article = Article.objects.get(id=aid)
        comment.context = form.cleaned_data['context']
        parent_id = form.cleaned_data['parent_id']
        if parent_id != -1:
            comment.parent = Comment.objects.get(id=parent_id)
        comment.save()

        # 返回的参数
        data['status'] = 'success'
        data['username'] = request.user.username
        data['comment_time'] = comment.created_time.strftime(
            '%Y-%m-%d %H-%M-%S')
        data['text'] = comment.context
        data['commnet_id'] = comment.id
        print(data)
    else:
        data['status'] = 'Error'
        data['message'] = list(form.errors.values())[0][0]

        # 以Json的形式返回数据
    return JsonResponse(data)
Пример #2
0
def sumbit_comment(request, pk):
    post = request.POST

    comment = Comment()
    comment.name = post.get("first_name")
    comment.email = post.get('email')
    # comment.website = post.get('website')
    comment.text = post.get('message')
    comment.article = Article.objects.get(id=pk)
    comment.save()

    return redirect(reverse('blog:blog_detail', kwargs={"pk": pk}))
Пример #3
0
 def post(self, request, id):
     name = request.POST.get('name')
     email = request.POST.get('email')
     url = request.POST.get('url')
     content = request.POST.get('content')
     c = Comment()
     c.name = name
     c.email = email
     c.url = url
     c.content = content
     c.article = Article.objects.get(pk=id)
     c.save()
     return JsonResponse({"name": name, "content": content, "create_time": c.create_time})
Пример #4
0
def comment_view(request):
    contenttype = request.POST.get('content_type')
    comment = Comment()
    if contenttype == 'essay':
        object_pk = request.POST.get('object_pk')
        content_object = Essay.objects.get(id=object_pk)
        comment.content_object = content_object
        comment.nickname = request.POST.get('name')
        comment.email = request.POST.get('email')
        comment.url = request.POST.get('url')
        comment.content = request.POST.get('content')
        comment.save()
        url = '/home/essay/detail/%s/' % object_pk
        return HttpResponseRedirect(url)
    return HttpResponse('error')