예제 #1
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)
    title = post.text[:15] + "[...]"
    comments = UserPostComment.objects. \
            filter(post=post).order_by('-date_added')
    context = {
        'post': post, 
        'title': title,
        'comments': comments,
    }
    if request.method == 'GET':
        form = UserPostCommentForm()
        context['form'] = form
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            author = form.cleaned_data['author']
            user_comment = UserPostComment(text=text, author=author, post=post)
            user_comment.save()
            return redirect('post_details', pk=pk)
        else:
            context['form'] = form
            return render(request, 'post_details.html', context)
예제 #2
0
def post_details(request, pk):

    post = UserPost.objects.get(pk=pk)
    if request.method == 'GET':
        form = CommentPostForm()
        comments = UserPostComment.objects.filter(
            post=post).order_by('-date_added')

        context = {
            'post': post,
            'form': form,
            'comments': comments,
        }

        #return HttpResponse(UserPostComment.objects.get(post=post)) #
        return render(request, 'post_details.html', context)

    elif request.method == 'POST':
        form = CommentPostForm(request.POST)

        if form.is_valid():
            text = form.cleaned_data['text']
            user_comment = UserPostComment(text=text, post=post)
            user_comment.save()
        return redirect('/post/' + str(post.pk))
예제 #3
0
def post_details(request, pk):
    
    post = UserPost.objects.get(pk=pk)
    if request.method == 'GET':
        form = CommentPostForm()
        comments=UserPostComment.objects.filter(post=post).order_by('-date_added')

        context = {
            'post': post,
            'form':form,
            'comments':comments,
        }
        
        #return HttpResponse(UserPostComment.objects.get(post=post)) #
        return render(request, 'post_details.html', context)

    elif request.method == 'POST':
        form = CommentPostForm(request.POST)

        
        if form.is_valid():
            text = form.cleaned_data['text']
            user_comment = UserPostComment(text=text, post=post)
            user_comment.save()
        return redirect('/post/'+str(post.pk))
예제 #4
0
def post_details(request, pk):
    if request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text)
            comment.post_id = pk
            comment.save()
    post = UserPost.objects.get(pk=pk)
    comments = post.userpostcomment_set.all().order_by('-date_added')
    form = UserPostCommentForm()
    context = {'post': post, 'comments': comments, 'form': form}
    return render(request, 'post_details.html', context)
예제 #5
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)
    if request.method == 'GET':
        form = UserPostCommentForm()
        context = {
            'post': post,
            'form': form,
        }
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text, post=post, author=request.user)
            comment.save()
        return redirect('post_details', pk=pk)
예제 #6
0
def post_details(request, pk):
    if (request.method == 'GET'):
        form = UserPostCommentForm()
        post = UserPost.objects.get(pk=pk)
        comments = UserPostComment.objects.filter(post=post) \
            .order_by('-date_added')
        context = {'post': post, 'comments': comments, 'form': form}
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text)
            comment.post_id = pk
            comment.save()
        return redirect('/post/{}/'.format(pk))
예제 #7
0
def post_details(request, pk):
    if request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text)
            comment.post_id = pk
            comment.save()

    post = UserPost.objects.get(pk=pk)
    comments = post.userpostcomment_set.all().order_by('-date_added')
    form = UserPostCommentForm()

    context = {'post': post, 'comments': comments, 'form': form}

    return render(request, 'post_details.html', context)
예제 #8
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)
    if request.method == 'GET':
        form = UserPostCommentForm()
        context = {
            'post': post,
            'form': form,
        }
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text,
                                      post=post,
                                      author=request.user)
            comment.save()
        return redirect('post_details', pk=pk)
예제 #9
0
def post_details(request, pk):
    if request.method == 'GET':
        post = UserPost.objects.get(pk=pk)
        comments = UserPostComment.objects.filter(post=post).order_by('-date_added')
        form = UserPostCommentForm()
        context = {
            'post' : post,
            'comments' : comments,
            'form' : form,
        }
        return render(request, 'post_details.html',context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            user_post_comment = UserPostComment(text=text,post=UserPost.objects.get(pk=pk))
            user_post_comment.save()
        return redirect('post_details',pk)
예제 #10
0
def post_details(request, pk):
    if request.method == 'GET':
        post = UserPost.objects.get(pk=pk)
        form = CommentForm()
        comments = UserPostComment.objects.filter(post=pk)
        context = {
            'post': post,
            'form': form,
            'comments': comments,
        }
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            user_comment = UserPostComment(text=text,
                                           post=UserPost.objects.get(pk=pk))
            user_comment.save()
        return redirect('post_details', pk)
예제 #11
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)

    if request.method == 'GET':
        form = UserPostCommentForm()
        comm = UserPostComment.objects.filter(
            post=post).order_by('-date_added')
        context = {
            'post': post,
            'form': form,
            'comments': comm,
        }
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text, post=post)
            comment.save()
        return redirect('post_details', post.pk)

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