Ejemplo n.º 1
0
def detail(request, question_id):
    if request.method == "GET":
        question_data = get_object_or_404(Question, pk=question_id)
        #댓글 폼 생성
        form = CommentForm()
        #question_data = Question.objects.get(id=question_id)
        # choice_data = Choice.objects.filter(question=question_id)
        context = {
            'form': form,
            'question_data': question_data,
            # 'choice_data':choice_data
        }
        return render(request, 'polls/detail.html', context)
        # return HttpResponse('question_id : {}'.format(question_id))
    elif request.method == "POST":
        form = CommentForm(request.POST, request.FILES)
        if form.is_valid():
            #Question 객체 찾기
            question = get_object_or_404(Question, pk=question_id)
            #CustomUser 객체 찾기
            customuser = get_object_or_404(CustomUser,
                                           pk=request.session['username'])
            obj = form.save(commit=False)
            obj.question = question
            obj.customuser = customuser
            obj.save()
            return HttpResponseRedirect(
                reverse('polls:detail', args=(question_id, )))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: glmcz/Dairy
def blog_detail(request, pk):
        post = Post.objects.get(pk=pk)
        comments = Comment.objects.filter(post=post)

        form = CommentForm()
        if request.method == "POSTS":
                form = CommentForm(request.POST)
                if form.is_valid():
                        comment = comments(
                                author = form.cleaned_data["author"],
                                body = form.cleaned_data["body"],
                                post = post,
                        )
                        comment.save()
        context = {"post": post, "comments": comments, "form": form}
        return render(request, "blog_detail.html", context)
Ejemplo n.º 3
0
def create_comment(request, poll_id):
    if request.method == 'POST':
        form = CommentForm(request.POST)

        if form.is_valid():
            comment = Comment.objects.create(
                title=form.cleaned_data.get('title'),
                body=form.cleaned_data.get('body'),
                tel=form.cleaned_data.get('tel'),
                email=form.cleaned_data.get('email'))

    else:
        form = CommentForm()

    context = {'form': form, 'poll_id': poll_id}

    return render(request, 'polls/create-comment.html', context=context)
Ejemplo n.º 4
0
def maps(request, maps_id):
    template_name = 'polls/maps.html'
    information = get_object_or_404(Info, pk=maps_id)

    return render(request,
                  template_name,
                  context={
                      'comment_form': CommentForm(),
                      'information': information
                  })
Ejemplo n.º 5
0
def comment(request):
    comment = Comment.objects.all().order_by('-id')
    paginator = Paginator(comment, 5)
    page = request.GET.get('page')
    comment = paginator.get_page(page)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            c = form.save(commit=False)
            c.comment_date = timezone.now()
            c.save()
            return render(request, 'polls/comment.html', {
                'form': form,
                'comment': comment
            })
    else:
        form = CommentForm()
    return render(request, 'polls/comment.html', {
        'form': form,
        'comment': comment
    })
Ejemplo n.º 6
0
def comment(request):
    user_comment = CommentForm(data=request.POST)
    if request.method == 'POST':
        if user_comment.is_valid():
            comment = user_comment.save(commit=False)
            comment.user = request.user
            poll = Poll.objects.get(pk=request.POST['pollid'])
            comment.poll = poll
            comment.save()
            return DetailsView(request, request.POST['pollid'])
        else:
            return DetailsView(request, request.POST['pollid'])
    return redirect(request.path)
Ejemplo n.º 7
0
def detail(request, pk):
    form = CommentForm()  # CommentForm을 form 안에 넣는다.
    c = Comment.objects.all(
    )  # Comment 의 모든 object를 c에 넣는다, 나중에 context로 리턴해준다.
    q = Question.objects.prefetch_related('choice_set').get(id=pk)  # 최적화방법
    if request.method == "POST":  # CommentForm을 작성해서 POST로 들어오면
        Pform = CommentForm(
            request.POST)  # CommentForm에 POST로 들어온 것들을 Pform 안에 넣고
        if Pform.is_valid():  # 유효성 검사를 한다
            Pform.save(commit=False)  # DB에 바로 저장하지 않고
            Pform.comment_user = request.user.username  # [작동안함]
            Pform.comment_date = timezone.now()  # 현재 시간을 comment_date에 넣는다.
            Pform.question = q.question_text
            Pform.save()  # DB에 적용시킨다.
            return redirect('polls:detail', pk)  # 현재 페이지로 redirect 시킨다.
        else:
            return HttpResponse('유효하지 않은 데이터입니다.')  # Form 데이터가 유효하지 않으면 출력
    else:
        return render(request, 'polls/detail.html', {
            'question': q,
            'form': form,
            'c': c
        })  # 함수의 끝으로 context들을 리턴
Ejemplo n.º 8
0
def comment_new(request, map_pk):
    info = Info.objects.get(pk=map_pk)
    rate_count = 0
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author_id = request.user.id
            comment.info_id = info.pk
            comment.rate = request.POST['rate']
            for rate in comment.rate:
                if rate == '★':
                    rate_count += 1
            info.rate_sum += rate_count
            info.count += 1
            info.rate_ave = round(info.rate_sum / info.count, 1)
            info.save()
            comment.save()
            messages.success(request, '메시지를 작성하였습니다.')
            return redirect('polls:maps',
                            map_pk)  # post.get_absolute_url() => post detail
    else:
        form = CommentForm()
    return render(request, 'poll/maps.html', {'form': form})
Ejemplo n.º 9
0
def DetailsView(request, poll_id):
    poll = get_object_or_404(Poll, pk=poll_id)
    top_polls = Poll.objects.annotate(
        num_votes=Sum('choice__votes')).order_by('-num_votes')
    top_tags = Poll.tags.most_common()[:10]
    similar_polls = poll.tags.similar_objects()[:5]
    comment_form = CommentForm()
    if request.user.is_authenticated():
        auth_form = False
        logged_in = True

    else:
        logged_in = False
        auth_form = AuthenticateForm()
    return render_to_response('polls/detail.html', {
        "poll": poll,
        "top_polls": top_polls,
        "top_tags": top_tags,
        "auth_form": auth_form,
        "logged_in": logged_in,
        "comment_form": comment_form,
        "similar_polls": similar_polls
    },
                              context_instance=RequestContext(request))