Beispiel #1
0
def addcomment(request, articles_id=1, user_id=1):
    if request.POST:
        newcomm = CommentForm(request.POST)
        if newcomm.is_valid():
            comment = newcomm.save(commit=False)
            comment.article = Articles.objects.get(id=articles_id)
            comment.user = User.objects.get(id=user_id)
            newcomm.save()
    return redirect('/article/%s/' % articles_id)
Beispiel #2
0
def addcomment(request, articles_id=1, user_id=1):
    if request.POST:
        newcomm = CommentForm(request.POST)
        if newcomm.is_valid():
            comment = newcomm.save(commit=False)
            comment.article = Articles.objects.get(id=articles_id)
            comment.user = User.objects.get(id=user_id)
            newcomm.save()
    return redirect('/article/%s/' % articles_id)
Beispiel #3
0
def index(request):
  form = CommentForm()
  if request.method == "POST" and form.validate(request.form):
    form.save()
    return redirect(url_for('myapp/index'))
  query = Comment.all().order('-created')
  comments = query.fetch(ITEMS_PER_PAGE)
  return render_to_response('myapp/index.html',
                            {'form': form.as_widget(),
                             'comments': comments})
Beispiel #4
0
def PostDetail(request, slug):
    posts = Blog.objects.filter(status=1).order_by('?')[:4]
    ads = Ads.objects.all()
    blog_detail = Blog.objects.filter(slug=slug)[0]
    tags = blog_detail.tags.all()
    pythonpost = Blog.objects.filter(status=1, Category='Python').reverse()
    djangopost = Blog.objects.filter(status=1, Category='Django')
    post = get_object_or_404(Blog, slug=slug)
    comments = post.comments.filter(active=True)
    sitelogo = Logo.objects.all().last()
    pages = Pages.objects.all()
    post = Blog.objects.filter(status=1)[:3]
    sliderimage1 = HomepageSlider.objects.first()
    sliderimage2 = HomepageSlider.objects.last()
    title = TitleandTag.objects.all()
    about = SiteDescription.objects.first()
    footer = Footer.objects.first()
    footerlink = Footer.objects.last()
    video = Video.objects.first()
    new_comment = None
    # Comment posted
    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():

            # Create Comment object but don't save to database yet
            new_comment = comment_form.save(commit=False)
            # Assign the current post to the comment
            new_comment.post = post
            # Save the comment to the database
            new_comment.save()
            return HttpResponseRedirect(reverse('PostDetail', args=[slug]))

    else:
        comment_form = CommentForm()
    context = {
        'post': post,
        'comments': comments,
        'new_comment': new_comment,
        'comment_form': comment_form,
        'blog': blog_detail,
        'pythonpost': pythonpost,
        'djangopost': djangopost,
        'tags': tags,
        'posts': posts,
        'ads': ads,
        'send': False,
        'pages': pages,
        'Logo': sitelogo,
        'post': post,
        'first': sliderimage1,
        'second': sliderimage2,
        'title': title,
        'about': about,
        'footer': footer,
        'footerlink': footerlink,
        'video': video
    }
    return render(request, 'blog_detail.html', context)
Beispiel #5
0
def add_comment_to_post(request, pk):
    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.post = post
            comment.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = CommentForm()
    return render(request, 'myapp/comment_form.html', {'form': form})
def addcomment(request, pk):
    a = get_object_or_404(Post, pk=pk)
    u = request.user
    form = CommentForm()
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            com = form.save(commit=False)
            com.post = a
            com.author = u
            com.save()
            return redirect('myapp:detail', pk=a.pk)
    return render(request, 'myapp/comment.html', {'form': form})
Beispiel #7
0
def post_detail_view(request,year,month,day,post):
    post=get_object_or_404(Post,slug=post,publish__year=year,publish__month=month,publish__day=day)
    comments=post.comments.filter(active=True)
    csubmit=False
    form=CommentForm()
    if request.method=='POST':
        form=CommentForm(request.POST)
        if form.is_valid():
            newcomment=form.save(commit=False)
            newcomment.post=post
            newcomment.save()
            csubmit=True
    d={'post':post,'form':form,'csubmit':csubmit,'comments':comments}
    return render(request,'myApp/post_detail.html',d)
Beispiel #8
0
def post_detail_view(request, year, month, day, post):
    #if the record is available get that object else raise 404 error.It is available in django shortcuts
    post = get_object_or_404(Post,
                             slug=post,
                             publish__year=year,
                             publish__month=month,
                             publish__day=day)
    comments = post.comments.filter(active=True)
    csubmit = False
    form = CommentForm()
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid:
            newcomment = form.save(commit=False)
            newcomment.post = post
            newcomment.save()
            csubmit = True
    d = {'post': post, 'form': form, 'csubmit': csubmit, 'comments': comments}
    return render(request, 'myapp/post_detail.html', d)
Beispiel #9
0
def comment_edit(request, song_id, comment_id=None):
    """コメントの編集"""
    song = get_object_or_404(Song, pk=song_id)  # 親の曲を読む
    # comment_idが指定されている(修正時)
    if comment_id:
        comment = get_object_or_404(Comment, pk=comment_id)
    # comment_idが指定されていない(追加時)
    else:
        comment = Comment()

    if request.method == 'POST':
        # POSTされたrequestデータからフォームを作成
        form = CommentForm(request.POST, instance=comment)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.song = song
            comment.save()
            return redirect('myapp:comment_list', song_id=song_id)
    else:  # GETの時
        form = CommentForm(instance=comment)

    return render(request, 'myapp/comment_edit.html',
                  dict(form=form, song_id=song_id, comment_id=comment_id))