示例#1
0
def detail(request, pk):
    d = Post.objects.get(pk=pk)
    comments = Comment.objects.filter(post=d)
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = CommentForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            comment = form.cleaned_data['comment']
            # print(comment,pk)
            #save comment in Comment model that is in data base
            c = Comment(post=d, comment=comment, user=request.user)
            c.save()
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            context = {'post': d, 'form': form, 'comments': comments}
            return render(request, 'detail.html', context)

    # if a GET (or any other method) we'll create a blank form
    else:
        form = CommentForm()
    context = {'post': d, 'form': form, 'comments': comments}
    return render(request, 'detail.html', context)
示例#2
0
def comment_view(
        request
):  # this function used for posting comment on the post of the user
    user = check_validation(request)
    if user and request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post_id = form.cleaned_data.get('post').id
            comment_text = form.cleaned_data.get('comment_text')
            comment = CommentModel.objects.create(user=user,
                                                  post_id=post_id,
                                                  comment_text=comment_text)
            comment.save()
            sg = sendgrid.SendGridAPIClient(apikey=(SENDGRID_API_KEY))
            from_email = Email("*****@*****.**")
            to_email = Email(comment.post.user.email)
            subject = "Welcome to Review book"
            content = Content("text/plain",
                              "someone just commented on your post. Go check")
            mail = Mail(from_email, subject, to_email, content)
            response = sg.client.mail.send.post(request_body=mail.get())
            print(response.status_code)
            print(response.body)
            print(response.headers)
            ctypes.windll.user32.MessageBoxW(0, u"comment posted successfully",
                                             u"SUCCESS", 0)
            return redirect('/feed/    ')
        else:
            return redirect('/feed/')
    else:
        return redirect('/login')
示例#3
0
def comment_view(request):
    user = check_validation(request)
    if user and request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post=form.cleaned_data.get('post')
            post_id = form.cleaned_data.get('post').id
            comment_text = form.cleaned_data.get('comment_text')
            comment = CommentModel.objects.create(user=user, post_id=post_id, comment_text=comment_text)
            comment.save()
            print "Comment is make on post"
            sg = sendgrid.SendGridAPIClient(apikey=API_KEY)
            from_email = Email("*****@*****.**")
            to_email = Email(post.user.email)
            subject = "InstaClone"
            content = Content("text/plain", "Comment is make on  your post")
            mail = Mail(from_email, subject, to_email, content)
            response = sg.client.mail.send.post(request_body=mail.get())
            print response
            print post.user.email
            return redirect('/feed/')
        else:
            return redirect('/feed/')
    else:
        return redirect('/login/')
示例#4
0
def detail(request, pk):
    p = Post.objects.get(pk=pk)
    comments = Comment.objects.filter(post_id=pk)
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = CommentForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            comment = form.cleaned_data['comment']
            c = Comment(post_id=pk, comment=comment, user=request.user)
            c.save()
            # redirect to a new URL:
            return HttpResponseRedirect(
                reverse('myapp:detail', kwargs={'pk': pk}))

    # if a GET (or any other method) we'll create a blank form
    else:
        form = CommentForm()

    return render(request, 'detail.html', {
        'form': form,
        'p': p,
        'comments': comments
    })
示例#5
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)
示例#6
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})
示例#7
0
def reply(index,user_name):
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data)
        comment.user_id = g.user.id
        comment.article_id = index  #
        # comment.reply_type = 2
        comment.to_user = user_name
        db.session.add(comment)
        db.session.commit()
        flash('Submit reply successfully.')
        return redirect(url_for('detail', index=index))
    return render_template('reply.html', title='Reply', form=form)
示例#8
0
文件: views.py 项目: dhacks/team-h
def post_comment(post_id):
    """
    本文表示、個別ページ post_idから対応するPOSTのデータをDBからとって表示
    本文したにコメント表示
    """
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(author=current_user, post_on=datetime.now(), body=form.body.data, post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        print("comment post success")
        return redirect("/{:d}".format(post_id))
    return render_template("editor.html", form=form)
示例#9
0
def comment_view(request):
    user = check_validation(request)
    if user and request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post_id = form.cleaned_data.get('post').id
            comment_text = form.cleaned_data.get('comment_text')
            comment = Comment.objects.create(user=user, post_id=post_id, comment_text=comment_text)
            comment.save()
            return redirect('/feed/')
        else:
            return redirect('/feed/')
    else:
        return redirect('/login')
示例#10
0
文件: views.py 项目: Nik118/Blog
def add_comment(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.author = request.user
            comment.save()
            return redirect('post_detail', pk=post.pk)
    else:
        form = CommentForm
        return render(request, 'myapp/comment_form.html', {'form': form})
示例#11
0
def post_comment(post_id):
    """
    本文表示、個別ページ post_idから対応するPOSTのデータをDBからとって表示
    本文したにコメント表示
    """
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(author=current_user,
                          post_on=datetime.now(),
                          body=form.body.data,
                          post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        print("comment post success")
        return redirect('/{:d}'.format(post_id))
    return render_template('editor.html', form=form)
示例#12
0
def comment_view(request):
    # ----------------------------------------------here is the function logic-------------------------------------------------------
    user = check_validation(request)
    if user and request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post_id = form.cleaned_data.get('post').id
            comment_text = form.cleaned_data.get('comment_text')
            comment = CommentModel.objects.create(user=user, post_id=post_id, comment_text=comment_text)
            comment.save()
            # TODO: ADD MESSAGE TO INDICATE SUCCESS
            return redirect('/feed/')
        else:
            # TODO: ADD MESSAGE FOR FAILING TO POST COMMENT
            return redirect('/feed/')
    else:
        return redirect('/login')
示例#13
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)
示例#14
0
def article(request, articles_id=1):
    args = {}
    args.update(csrf(request))
    args = {
        'form': CommentForm(),
        'article': Articles.objects.get(id=articles_id),
        'comments': Comments.objects.filter(article_id=articles_id),
        'subcomments': CommentToComment.objects.all(),
    }
    return render(request, "myapp/articl.html", args)
示例#15
0
def article(request, category_name, article_id):
    category = get_object_or_404(Category, name=category_name)
    article = get_object_or_404(Article, id=article_id, category=category)
    comment_list = ArticleComment.objects.filter(
        article=article).order_by('-pub_date')
    posted = False
    context = RequestContext(request)
    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        user = request.user
        if comment_form.is_valid():
            comment_text = comment_form.cleaned_data['comment_text']
            comment = ArticleComment(user=user,
                                     article=article,
                                     comment_text=comment_text,
                                     pub_date=timezone.now())
            comment.save()
            article.comments = article.comments + 1
            article.save()
            posted = True
        else:
            print comment_form.errors
    else:
        comment_form = CommentForm()
        #Search bar methods
        if request.method == 'GET' and 'search_category_button' in request.GET:
            search_category = request.GET.get('search_category')
            category_name = request.GET.get('search_name_c')
            if (category_name is not None) and (search_category is not None):
                return search_bar(request, search_category, category_name)
        if request.method == 'GET' and 'search_user_button' in request.GET:
            user_name = request.GET.get('search_name')
            if user_name is not None:
                return user_search(request, user_name)
    return render_to_response('myapp/base_article.html', {
        'posted': posted,
        'article': article,
        'comment_list': comment_list
    }, context)
示例#16
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)
示例#17
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)
示例#18
0
def comment_view(request):
    user = check_validation(request)
    if user and request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post_id = form.cleaned_data.get('post').id
            comment_text = form.cleaned_data.get('comment_text')
            comment = CommentModel.objects.create(user=user,
                                                  post_id=post_id,
                                                  comment_text=comment_text)
            comment.save()
            poster = PostModel.objects.filter(id=post_id).first()
            subject = "Comment on your photo"
            message = str(
                user.username
            ) + " " + "commented on your photo" + " " + comment_text
            from_email = EMAIL_HOST_USER
            to_email = [poster.user.email]
            send_mail(subject, message, from_email, to_email)
            return redirect('/feed/')
        else:
            return redirect('/feed/')
    else:
        return redirect('/login/')
示例#19
0
def comment_view(request):
    user = check_validation(request)
    if user and request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            post = form.cleaned_data.get('post')
            email = post.user.email
            comment_text = form.cleaned_data.get('comment_text')
            comment = CommentModel.objects.create(user=user, post=post, comment_text=comment_text)
            comment.save()

            sg = sendgrid.SendGridAPIClient(apikey=sendgrid_api)
            from_email = Email("*****@*****.**")
            to_email = Email(email)
            subject = "Upload to win"
            content = Content("text/plain", user.name + " has commented on your post")
            mail = Mail(from_email, subject, to_email, content)
            sg.client.mail.send.post(request_body=mail.get())
            return redirect('/feed/')

        else:
            return redirect('/feed/')
    else:
        return redirect('/login')
示例#20
0
def add_comment_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})
示例#22
0
def PostList(request):
    blog_list = Blog.objects.filter(status=1).order_by('-created_on')
    blog_list1 = Blog.objects.filter(status=1)[:2]
    blog_lists = Blog.objects.all()
    page = request.GET.get('page', 1)
    paginator = Paginator(blog_list, 6)
    alltages = Tag.objects.all()
    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()
    try:
        posts = paginator.page(page)
    except PageNotAnInteger:
        posts = paginator.page(1)
    except EmptyPage:
        posts = paginator.page(paginator.num_pages)
    print(blog_list1)
    comment_form = CommentForm()
    context = {
        'blog_list': blog_list,
        'blog_list1': blog_list1,
        'comment_form': comment_form,
        'posts': posts,
        'tags': alltages,
        '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.html', context)
示例#23
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)
示例#24
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))
示例#25
0
def article_vote(request, category_name, article_id, article_value):
    article = Article.objects.get(id=article_id)
    user = request.user
    voted = True
    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        user = request.user
        if comment_form.is_valid():
            comment_text = comment_form.cleaned_data['comment_text']
            comment = ArticleComment(user=user,
                                     article=article,
                                     comment_text=comment_text,
                                     pub_date=timezone.now())
            comment.save()
            article.comments = article.comments + 1
            article.save()
            posted = True
        else:
            print comment_form.errors
    else:
        comment_form = CommentForm()
        if request.method == 'GET' and 'search_category_button' in request.GET:
            search_category = request.GET.get('search_category')
            category_name = request.GET.get('search_name_c')
            if (category_name is not None) and (search_category is not None):
                return search_bar(request, search_category, category_name)
        if request.method == 'GET' and 'search_user_button' in request.GET:
            user_name = request.GET.get('search_name')
            if user_name is not None:
                return user_search(request, user_name)
    try:
        article_vote = ArticleVote.objects.get(user=user, article=article)
        already_voted = True
        comment_list = ArticleComment.objects.filter(
            article=article).order_by('-pub_date')
        posted = False
        context = {
            'already_voted': already_voted,
            'posted': posted,
            'comment_list': comment_list,
            'article': article,
            'voted': voted
        }
        return render(request, 'myapp/base_article.html', context)
    except:
        article_vote = ArticleVote(user=user,
                                   article=article,
                                   pub_date=timezone.now(),
                                   value=int(article_value))
        article_vote.save()
        article.votes = article.votes + int(article_value)
        article.save()
        already_voted = False
        comment_list = ArticleComment.objects.filter(
            article=article).order_by('-pub_date')
        posted = False
        context = {
            'already_voted': already_voted,
            'posted': posted,
            'comment_list': comment_list,
            'article': article,
            'voted': voted
        }
        return render(request, 'myapp/base_article.html', context)

    return article(request, category_name, article_id)