def save(self, ip_address):
     cleaned_data = super(CommentForm, self).clean()
     comment = Comment()
     comment.text = cleaned_data['comment']
     comment.ip_address = ip_address
     comment.save()
     return comment
Beispiel #2
0
def comment_add(request, proid):
    # if this is a POST request we need to process the form data

    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':

        # create a form instance and populate it with data from the request:
        form = CommentForm(request.POST)
        # check whether it's valid:

        if form.is_valid():
            current_user = request.user
            data = Comment()
            data.product_id = proid
            data.user_id = current_user.id
            data.subject = form.cleaned_data['subject']
            data.rating = form.cleaned_data['rating']
            data.message = form.cleaned_data['message']
            data.save()

            messages.success(
                request,
                "Your review has been sent. Thank You for your interest ")
            return HttpResponseRedirect(url)
    else:
        return HttpResponseRedirect(url)
Beispiel #3
0
def reply_insert(request):
    id = request.POST["idx"]
    dto = Comment(board_idx=id,
                  writer=request.POST["writer"],
                  content=request.POST["content"])
    dto.save()
    return HttpResponseRedirect("detail?idx=" + id)
Beispiel #4
0
def addcmt(request, slug):
    cmt = request.POST.get('cmt')
    item = Items.objects.get(slug=slug)
    com = Comment(user=request.user, item=item, comments=cmt, parent=None)
    com.save()
    messages.success(request, "Review Submitted succesfully")
    return redirect(request.META['HTTP_REFERER'])
Beispiel #5
0
def comment_add(request, proid):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user
            data = Comment()
            data.product_id = proid
            data.user_id = current_user.id
            data.subject = form.cleaned_data['subject']
            data.rating = form.cleaned_data['rating']
            data.message = form.cleaned_data['message']
            data.save()
            messages.success(request, "Your review has been sent")
            return HttpResponseRedirect(url)
    else:
        return HttpResponseRedirect(url)
Beispiel #6
0
def comment_add(request, proid):
    url = request.META.get('HTTP_REFERER')
    if request.method == 'POST':

        current_user = request.user
        data = Comment()
        data.product_id = proid
        data.user_id = current_user.id
        data.name = current_user.username
        data.email = current_user.email
        data.subject = request.POST['subject']
        data.message = request.POST['message']
        data.save()
        messages.success(request, "ur review has been sent.")
        return HttpResponseRedirect(url)

    else:
        return HttpResponseRedirect(url)
Beispiel #7
0
    def post(self, request):
        comment_form = CommentForm(request.POST, user=request.user)

        data = {}
        if comment_form.is_valid():
            # 检查通过,保存数据

            comment = Comment()
            comment.content = comment_form.cleaned_data['content']
            comment.article = comment_form.cleaned_data['content_object']
            comment.user = comment_form.cleaned_data['user']

            # 判断是否是回复
            parent = comment_form.cleaned_data['parent']
            if parent:
                comment.root = parent.root if parent.root else parent
                comment.parent = parent
                comment.reply_to = parent.user
            comment.save()

            # 发送邮件
            comment.sen_email(request)
            # 返回评论数据.get_nickname()是users:model里面的如果有昵称返回昵称,没有就返回手机号,是评论不刷新页面出现
            data['status'] = 'SUCCESS'
            data['user'] = comment.user.get_nickname()
            data['created'] = comment.created.strftime('%Y-%m-%d %H:%M:%S')
            data['content'] = comment.content
            data['content_type'] = comment.article._meta.model_name

            # return JsonResponse(data)

            # 返回回复数据
            if parent:
                data['reply_to'] = comment.reply_to.get_nickname()
            else:
                data['reply_to'] = ''
            data['id'] = comment.id
            data['root_id'] = comment.root.id if comment.root else ''
            # print("#root_%s" % data['root_id'])

        else:
            data['status'] = 'ERROR'
            data['message'] = list(comment_form.errors.values())[0][0]
        return JsonResponse(data)
Beispiel #8
0
def addcomment(request, id):
    url = request.META.get('HTTP_REFERER')

    if request.method == 'POST':  # check post
        form = CommentForm(request.POST)
        if form.is_valid():
            data = Comment()
            data.comment = form.cleaned_data['comment']
            data.ip = request.META.get('REMOTE_ADDR')
            data.item_id = id
            current_user = request.user
            data.user_id = current_user.id
            data.save()
            messages.success(
                request,
                "Your comment has been sent. Thank you for your interest.")
            return HttpResponseRedirect(url)

    return HttpResponseRedirect(url)
Beispiel #9
0
def request_individual(request, request_id):

    req = Request.objects.get(id=request_id)

    if request.method == 'POST':
        comment = Comment()
        comment.request_id = request_id
        comment.content = request.POST.get('content')
        comment.author = request.user
        comment.save()
        return redirect(req)

    
    discussion = []
    try:
        discussion = Comment.objects.filter(request_id=request_id)
    except Comment.DoesNotExist:
        discussion = []
    return render(request, 'home/request.html', {'req': req, 'comments': discussion})
Beispiel #10
0
def detail(request, pk):
    post = Post.objects.get(pk=pk)
    form = CommentForm()
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment(author=form.cleaned_data["author"],
                              body=form.cleaned_data["body"],
                              post=post)
            comment.save()

    comments = Comment.objects.filter(post=post)
    context = {
        "post": post,
        "comments": comments,
        "form": form,
    }

    return render(request, "detail.html", context)
Beispiel #11
0
def home_detail(request, pk):
    home = Home.objects.get(pk=pk)
    form = CommentForm()
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment(
                author=form.cleaned_data["author"],
                body=form.cleaned_data["body"],
                game=home
            )
            comment.save()
    comments = Comment.objects.filter(game=home)
    context = {
        'home': home,
        'comments': comments,
        'form': form,
    }
    return render(request, 'home_detail.html', context)
Beispiel #12
0
def addComment(request, id):
    url = request.META.get('HTTP_REFERER')  # get last url
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            current_user = request.user
            data = Comment()
            data.user_id = current_user.id
            data.product_id = id
            data.subject = form.cleaned_data['subject']
            data.comment = form.cleaned_data['comment']
            data.rate = form.cleaned_data['rate']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()
            messages.success(request, "Yorumunuz başarı ile gönderildi")

            return HttpResponseRedirect(url)

    messages.warning(request, "Yorumunuz kaydedilmedi, kontrol edin")
    return HttpResponseRedirect(url)
Beispiel #13
0
def ArticleDetailView(request, article_id):
    '''
    文章内容
    '''
    if request.method == "GET":
        post = get_object_or_404(Article, id=article_id)

        # +
        comments = Comment.objects.filter(
            article=post).order_by('-created_time')

        md = markdown.Markdown(extensions=[
            'markdown.extensions.extra',
            'markdown.extensions.codehilite',
            'markdown.extensions.toc',
        ])
        post.body = md.convert(post.body)
        post.toc = md.toc
        return render(request,
                      'blog/detail.html',
                      context={
                          'post': post,
                          'comments': comments
                      })

    if request.method == "POST":
        article_id = request.POST.get('id')
        post = get_object_or_404(Article, id=article_id)
        comment = Comment()
        text = request.POST.get("text", "")
        comment.article = post
        comment.content = text
        comment.save()
        #path=reverse('home:detail',args=(article_id))+'#comment_dot'
        return redirect(
            request.META['HTTP_REFERER'])  #HttpResponseRedirect(path)