Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form = CommentForm(object=self.object, data=request.POST)

        if form.is_valid():
            form.save()
            return HttpResponseRedirect(self.object.get_absolute_url())

        context = self.get_context_data(object=self.object, form=form)
        return self.render_to_response(context)
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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.º 6
0
def CommentCreate(request, id):
	if not request.user.is_authenticated():
		return HttpResponseRedirect('/login/')
	if request.method == 'POST':
		form = CommentForm(request.POST)
		if form.is_valid():
			news = get_object_or_404(News,id=id)
			user = request.user.pk
			person = Person.objects.get(user_id=user)
			comment = Comment(description=form.cleaned_data['description'], date=form.cleaned_data['date'], user=person, news_item=news)
   			comment.save()
   			return HttpResponseRedirect('/listnews/')
   		else:
   			return render_to_response('comment.html', {'form': form}, context_instance=RequestContext(request))
	else:
		'''No esta ingresando el comentario'''
		form = CommentForm()
		return render_to_response('comment.html', {'form': form}, context_instance=RequestContext(request))
Ejemplo n.º 7
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
                  })
def comment_edit(request, report_id, comment_id=None):
    """感想の編集"""
    report = get_object_or_404(Report, pk=report_id)  # 親の書籍を読む
    if comment_id:   # comment_id が指定されている (修正時)
        comment = get_object_or_404(Comment, pk=comment_id)
    else:               # comment_id が指定されていない (追加時)
        comment = Comment()

    if request.method == 'POST':
        form = CommentForm(request.POST, instance=comment)  # POST された request データからフォームを作成
        if form.is_valid():    # フォームのバリデーション
            comment = form.save(commit=False)
            comment.report = report  # この感想の、親の書籍をセット
            comment.save()
            return redirect('polls:comment_list', report_id=report_id)
    else:    # GET の時
        form = CommentForm(instance=comment)  # comment インスタンスからフォームを作成

    return render(request,
                  'polls/comment_edit.html',
                  dict(form=form, report_id=report_id, comment_id=comment_id))
Ejemplo n.º 9
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.º 10
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))
Ejemplo n.º 11
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.º 12
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.º 13
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들을 리턴