예제 #1
0
파일: views.py 프로젝트: devunt/hydrocarbon
 def get_context_data(self, **kwargs):
     plv = PostListDetailView(post=self.object)
     plv.kwargs = dict()
     plv.request = self.request
     plv.dispatch(self.request, board=self.board.slug)
     ctx = plv.get_context_data()
     kwargs.update(ctx)
     kwargs['board'] = self.board
     voted = {'upvoted': False, 'downvoted': False}
     if self.request.user.is_authenticated():
         vqs = self.object._votes.filter(user=self.request.user)
     else:
         vqs = self.object._votes.filter(user=None, ipaddress=self.request.META['REMOTE_ADDR'])
     if vqs.exists():
         vote = vqs.first()
         if vote.vote == Vote.UPVOTE:
             voted['upvoted'] = True
         elif vote.vote == Vote.DOWNVOTE:
             voted['downvoted'] = True
     kwargs['voted'] = voted
     f = CommentForm(show_ot_form=True)
     if not self.request.user.is_authenticated():
         ot_user = self.request.session.get('onetime_user')
         if ot_user:
             f.initial = {'onetime_nick': ot_user.get('nick'), 'onetime_password': ot_user.get('password')}
     kwargs['comment_form'] = f
     if hasattr(settings, 'GOOGLE_ADS'):
         kwargs['google_ads'] = {
             'client': settings.GOOGLE_ADS['CLIENT'],
             'slot': settings.GOOGLE_ADS['SLOT'],
         }
     return super().get_context_data(**kwargs)
예제 #2
0
파일: views.py 프로젝트: Saminu/hydrocarbon
 def get_context_data(self, **kwargs):
     plv = PostListDetailView(post=self.object)
     plv.kwargs = dict()
     plv.request = self.request
     plv.dispatch(self.request, board=self.board.slug)
     ctx = plv.get_context_data()
     kwargs.update(ctx)
     kwargs['board'] = self.board
     voted = {'upvoted': False, 'downvoted': False}
     if self.request.user.is_authenticated():
         vqs = self.object._votes.filter(user=self.request.user)
     else:
         vqs = self.object._votes.filter(user=None, ipaddress=self.request.META['REMOTE_ADDR'])
     if vqs.exists():
         vote = vqs.first()
         if vote.vote == Vote.UPVOTE:
             voted['upvoted'] = True
         elif vote.vote == Vote.DOWNVOTE:
             voted['downvoted'] = True
     kwargs['voted'] = voted
     f = CommentForm(show_ot_form=True)
     if not self.request.user.is_authenticated():
         ot_user = self.request.session.get('onetime_user')
         if ot_user:
             f.initial = {'onetime_nick': ot_user.get('nick'), 'onetime_password': ot_user.get('password')}
     kwargs['comment_form'] = f
     if hasattr(settings, 'GOOGLE_ADS'):
         kwargs['google_ads'] = {
             'client': settings.GOOGLE_ADS['CLIENT'],
             'slot': settings.GOOGLE_ADS['SLOT'],
         }
     return super().get_context_data(**kwargs)
예제 #3
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)
예제 #4
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")
예제 #5
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)
예제 #6
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)
예제 #7
0
def detail(request, article_id):
    article = get_object_or_404(Article, pk=article_id)
    article.click_num += 1
    article.save()
    comments = article.comment_set.all()
    comments_form = CommentForm()
    context = {
        'article': article,
        'comments_form': comments_form,
        'comments': comments
    }
    return render(request, 'board_detail.html', context)
예제 #8
0
def forum(request):
    comments = Comments.objects.all()
    comment_form = CommentForm()
    current_user = request.user
    topics = Topic.objects.all()
    if request.method == 'POST':
        form = TopicForm(request.POST, request.FILES)
        if form.is_valid():
            topic = form.save(commit=False)
            topic.user = current_user
            topic.save()
            return redirect('/forum')
    else:
        form = TopicForm()
    return render(request, "forum.html",
                  {"form": form, "topics": topics, 'comment': comment_form, "comments": comments})
예제 #9
0
def board_detail(request, post_id):
    user_name = request.session['userss']
    user_id = request.session['user_id']
    post = get_object_or_404(Post, pk=post_id)
    chat = Chat.objects.all()
    if request.method == 'POST':
        post_form = PostForm(request.POST, instance=post)
        print("디테일 포스트로 들어옴 ")

    else:
        post_form = PostForm(instance=post)
        for i in post_form.fields:  # 수정이 되지 않도록 처리
            post_form.fields[i].disabled = True
        comment_form = CommentForm()
        print("디테일 엘스 들어옴 ")

    return render(request, 'bbs_detail.html', {'post_form': post_form, 'post': post, 'comment_form': comment_form, 'userss': user_name, 'user_id': user_id, 'chat': chat})
예제 #10
0
파일: views.py 프로젝트: 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})
예제 #11
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})
예제 #12
0
    def get(self, request, *args, **kwargs):
        article = self.get_object()
        #form = CommentForm() 
        # comments = Comment.objects.filter(Article=article_id)
        form = CommentForm()

        ctx = {
            #'view': self.__class__.__name__,
            #'data': article
            'form' : form,
            'article' : article,
            #'comments' : comments
            #'post' : post,
         #   'form' : form
        }

        try:
            comments = Comment.objects.filter(post=article)
            ctx['comments'] = comments
            # todo 코멘트에 대한 view 생성, ctx에 추가
        except:
            pass
            # 흘리기


        #post = get_object_or_404(Post, 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('article_detail', pk=pk)
        #else:
        #    form = CommentForm()
        
#        pk = self.kwargs.get(self.pk_url_kwargs)
#        comments = Comment.objects.all()
#        comment = comments.get(pk=pk)
        #if not article:
        #    raise Http404('invalid article_id')  # 검색된 데이터가 없다면 에러 발생

        return self.render_to_response(ctx)
예제 #13
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})
예제 #14
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)
예제 #15
0
파일: views.py 프로젝트: tastyr94/django
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,
    })
예제 #16
0
파일: views.py 프로젝트: tastyr94/django
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,
    })