Exemplo n.º 1
0
def board_send_comment(request, post_id):
        chat = Chat.objects.all()
        user_name = request.session['userss']
        user_id = request.session['user_id']
        print("Comment 들어왔다")
        post = get_object_or_404(Post, pk=post_id)
        comment = Comment(comment=post)
        # comment = Comment(pk=post_id)

        comment_list = Comment.objects.filter(comment=post_id).order_by('-created_date')
        # print(comment_list)
        post_form = PostForm(request.POST, instance=post)


        if request.method == "POST":
            print("post 들어왔다 ")
            form = CommentForm(request.POST, instance=comment)

            if form.is_valid():
                comment = form.save(commit=False)
                comment.post = post
                comment.author = user_name
                comment.save()
                page = request.GET.get('page', '1')
                paginator = Paginator(comment_list, 5)
                print("page")
                commentpage = paginator.get_page(page)
                context = {'comment_list': comment_list,'post_form': post_form, 'post': post, 'comment_form': form, 'page': page, 'commentpage': commentpage, 'userss': user_name, 'user_id': user_id}

                return render(request, 'bbs_detail.html',context)


        else:
            form = CommentForm(request.GET)
            page = request.GET.get('page','1')
            paginator = Paginator(comment_list, 5)
            commentpage = paginator.get_page(page)

            context = {'comment_list': comment_list,'post_form': post_form, 'post': post, 'comment_form': form, 'page': page, 'commentpage': commentpage, 'userss': user_name, 'user_id': user_id, 'chat': chat}


            if form.is_valid():
                comment = form.save(commit=False)
                comment.post = post
                comment.author = user_name
                comment.save()
                page = request.GET.get('page', '1')
                paginator = Paginator(comment_list, 5)
                commentpage = paginator.get_page(page)

                context = {'comment_list': comment_list,'post_form': post_form, 'post': post, 'comment_form': form, 'page': page, 'commentpage': commentpage, 'userss': user_name, 'user_id': user_id, 'chat': chat}

                return render(request, 'bbs_detail.html', context)

        print("pComment 그린다 ")
        return render(request, 'bbs_detail.html', context)
Exemplo n.º 2
0
Arquivo: views.py Projeto: c2jungtk/pp
def add_comment_to_post(request, pk):
    post = get_object_or_404(Product, pk=pk)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.post = post
            comment.save()
            return redirect('product:product_detail', pk=post.pk)
    else:
        form = CommentForm()
    return render(request,'board/add_comment_to_post.html',{'form': form})
Exemplo n.º 3
0
def add_comment_to_post(request, pk):
    post = get_object_or_404(Article, pk=pk)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.post = post
            comment.save()
            return redirect('.', pk=post.pk)
    else:
        form = CommentForm()
    return render(request, 'article_comment.html', {'post': post, 'form': form})
Exemplo n.º 4
0
def comment(request, topic_id):
    if request.method == 'POST':
        topic = get_object_or_404(Topic, pk=topic_id)
        comment_form = CommentForm(request.POST, request.FILES)
        if comment_form.is_valid():
            comment = comment_form.save(commit=False)
            comment.commenter = request.user
            comment.topic_id = topic
            comment.save()
            return redirect(forum)
    else:
        comment_form = CommentForm()
    return render(request, 'forum.html', {'comment': comment_form})
Exemplo n.º 5
0
def addComment(request, article_id):
    article = get_object_or_404(Article, pk=article_id)
    comment = Comment(article_id=article,
                      writer=request.session.get('user_id'),
                      write_date=datetime.datetime.now())
    comments_form = CommentForm(request.POST, instance=comment)
    if comments_form.is_valid():
        comments_form.save()
        # comments_form = CommentsForm()

    context = {
        'comment_id': comment.id,
        'comment': comment.comment,
        'writer': comment.writer,
        'write_date': comment.write_date.strftime("%Y-%m-%d %H:%M")
    }
    return HttpResponse(json.dumps(context), content_type="application/json")
Exemplo n.º 6
0
def comment_new(request, board_pk):
    #post = Post.objects.get(pk=post_pk)
    board = get_object_or_404(Board, pk=board_pk)
    if request.method == 'POST':
        form = CommentForm(request.POST, request.FILES)
        if form.is_valid():
            # form.cleaned_data
            comment = form.save(commit=False)
            comment.board = board
            comment.save()
            messages.success(request, '새 댓글을 저장했습니다')
            return redirect('/board/{}/'.format(comment.board.pk))
    else:
        form = CommentForm()
    return render(request, 'board/comment_form.html', {
        'form': form,
    })
Exemplo n.º 7
0
 def dispatch(self, request, *args, **kwargs):
     object = self.get_object()
     if object.author != request.user:
         messages.warning(request, '수정할 권한이 없습니다.')
         return HttpResponseRedirect('/')
         # 삭제 페이지에서 권한이 없다! 라고 띄우거나
         # detail페이지로 들어가서 삭제에 실패했습니다. 라고 띄우거나
     
     if request.method == "POST":
         form = CommentForm(request.POST, instance=self.get_object())
         if form.is_valid():
             form.save()
             messages.success(request, '댓글이 수정 되었습니다.')
             return redirect('/article/' + str(article.id) + '/comment/')
         else:
             form = CommentForm(instance=self.get_object())
     else:
         return super(CommentUpdate, self).dispatch(request, *args, **kwargs)
Exemplo n.º 8
0
def race_detail(request, id):
    race = Race.objects.get(id=id)
    form = CommentForm()
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment(commenter=request.user,
                              race=race,
                              text=form.data["text"],
                              type=form.data["type"])
            comment.save()
    comments = Comment.objects.filter(race=race)
    context = {
        "race": race,
        "comments": comments,
        "form": form,
    }
    return render(request, "board/race_detail.html", context)
Exemplo n.º 9
0
def comment_edit(request, board_pk, pk):
    #comment = Comment.objects.get(pk=pk)
    comment = get_object_or_404(Comment, pk=pk)

    if comment.user != request.user:
        #messages.warning(request, '댓글 작성자만 수정가능합니다.')
        return redirect('board:board_detail', board_pk)

    if request.method == 'POST':
        form = CommentForm(request.POST, request.FILES, instance=comment)
        if form.is_valid():
            comment = form.save()
            return redirect('/board/{}/'.format(comment.board.pk))
            messages.success(request, '댓글을 수정했습니다')
    else:
        form = CommentForm(instance=comment)
    return render(request, 'board/comment_form.html', {
        'form': form,
    })
Exemplo n.º 10
0
def see_comments(request, pk):
    context = {}
    context['racer'] = get_object_or_404(Racer, id=pk)
    context['teams'] = Team.objects.all()
    context['cars'] = Car.objects.all()
    context['races'] = Race.objects.all()
    context['comments'] = Comment.objects.filter(racer_id=pk)
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
            form.user = request.user
            form.racer_id = pk
            form.save()
            context['form'] = form
            return redirect(see_comments, pk)
    else:
        form = CommentForm()
        context['form'] = form
    return render(request, 'racers_comments.html', context)