示例#1
0
def post_detail(req, year, month, day, post):
    post = get_object_or_404(Post,
                             slug=post,
                             status='published',
                             publish__day=day,
                             publish__year=year,
                             publish__month=month)
    comments = post.comments.filter(active=True)  # comments is related name
    csubmit = False
    if req.method == 'POST':
        form = CommentForm(req.POST)
        if form.is_valid():
            new_comment = form.save(commit=False)
            new_comment.post = post
            new_comment.save()
            csubmit = True
    else:
        form = CommentForm()
    return render(req, 'post_detail.html', {
        'post': post,
        'form': form,
        'csubmit': csubmit,
        'comments': comments
    })
示例#2
0
文件: routes.py 项目: kmulpuri/wp
def comment():
    form = CommentForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        print(user)
        if user is None:
            flash('Invalid username or password')
            return redirect(url_for('login'))
        comment = Comment(username=form.username.data,
                          comment_text=form.commentInfo.data)
        db.session.add(comment)
        db.session.commit()
        flash('Will reply you soon via mail..')
        return redirect('index')
    return render_template('comment.html', form=form)
示例#3
0
def post_details(request, post_id):
    post = get_object_or_404(Post, pk=post_id)
    # comments = post.comment.filter(active=True)
    comments = post.comment.all()
    comment_form = CommentForm()

    if request.method == 'POST':
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            new_comment = comment_form.save(commit=False)
            new_comment.post = post
            new_comment.save()
            comment_form = CommentForm()

    else:
        comment_form = CommentForm()

    context = {
        'title': 'تفاصيل التدوينة',
        'post': post,
        'comments': comments,
        'comment_form': comment_form,
    }
    return render(request, 'app/post_details.html', context)
示例#4
0
def zendaya(post_id):

    post = Post.query.get(post_id)
    comments = Comment.query.filter_by(post_id = post.id)
    form = CommentForm()
    if form.validate_on_submit():
        name= form.name.data
        comment = Comment(name = name,post_id = post.id,rep = current_user)
        db.session.add(comment)
        db.session.commit()
        
        return redirect(url_for('zendaya',post_id = post.id))


    return render_template('zendaya.html',post = post,comments = comments,form =form,rep = current_user)
示例#5
0
def add_comment(post_id, comment_id=-1):
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data,
                          commentator=current_user,
                          post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment has been created!', 'success')
        return redirect(url_for('post', post_id=post_id))
    return render_template('add_comment.html',
                           form=form,
                           legend='Nowy Komentarz',
                           post_id=post_id,
                           comment_id=comment_id)
示例#6
0
文件: views.py 项目: ahDDD/BlogDemo
def comment_post(request, art_id, tag=None, error_form=None):
    if datetime.datetime.utcnow().strftime(
            '%Y-%m-%d %H:%M:%S') > request.session['ttl']:
        if UserProfile.objects.get(
                belong_to=request.user).full_information is False:
            return redirect(to='complete')
    form = CommentForm(request.POST)
    if form.is_valid():
        name = form.cleaned_data['name']
        comment = form.cleaned_data['comment']
        c = Comment(name=name, comment=comment, article_id=art_id)
        c.save()
    else:
        return detail(request, art_id, tag, error_form=form)
    return redirect(to='detail', art_id=art_id, tag=tag)
示例#7
0
文件: routes.py 项目: SLDem/MySNSite
def comment(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()
    form = CommentForm()
    if form.validate_on_submit():
        user_comment = Comment(body=form.comment.data,
                               commenter=current_user,
                               post_id=post.id)
        db.session.add(user_comment)
        db.session.commit()
        flash('Comment added!')
        return redirect(url_for('home'))
    return render_template('post_comment.html',
                           form=form,
                           title='Post Comment',
                           post_id=post.id)
示例#8
0
def comment():

    form = CommentForm()
    if form.validate_on_submit():

        # save the data
        m = Message(email=form.email.data,
                    message=form.message.data,
                    date=datetime.datetime.now())
        db.session.add(m)
        db.session.commit()

        return redirect('/messages')

    return render_template('forms/comment.html', action='/comment', form=form)
示例#9
0
def comment(post_id):
    form = CommentForm()
    post = Post.query.filter_by(id=post_id).first()
    comments = Comments.query.filter_by(post_id=post_id)
    if form.validate_on_submit():
        comment = Comments(body=form.body.data, post_id=post_id)
        db.session.add(comment)
        db.session.commit()
        flash("Comment Posted")
        return redirect(url_for('comment', post_id=post_id))
    return render_template("comments.html",
                           form=form,
                           post=post,
                           comments=comments,
                           title="Comments")
示例#10
0
def lois_view_detail(request, id):
    """
        Vue detail de la lois
    """
    lois = Lois.objects.get(id=id)
    comments = Comment.objects.filter(lois=id)
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            form = form.save(commit=False)
            form.comment_title = request.user
            form.lois = lois
            form.comment = request.POST['comment']
            form.save()
            return redirect('app:lois-view', id)
    else:
        form = CommentForm()
    context = {
        'lois': lois,
        'comments': comments,
        'form': form,
    }
    template_name = 'pages/lois-view.html'
    return render(request, template_name, context)
示例#11
0
def comment_on_comment(note_id, comment_id):
    local_note = Note.query.get_or_404(note_id)
    parent_comment = Comment.query.get_or_404(comment_id)
    form = CommentForm()

    if form.validate_on_submit():
        new_comment = Comment(note_id=note_id,
                              user_id=current_user.id,
                              content=form.content.data)
        parent_comment.replies.append(new_comment)
        db.session.commit()
        flash('success$Comment posted !')

        return redirect(url_for('note', note_id=note_id))
    return render_template('note.html', note=local_note, form=form)
示例#12
0
文件: routes.py 项目: mwiha/new-blog
def post(post_id):
    post = Post.query.get_or_404(post_id)
    comments = Comment.query.all()
    form = CommentForm()
    if form.validate_on_submit():
        comments = Comment(content=form.content.data, author=current_user)
        db.session.add(comments)
        db.session.commit()
        flash('Your comment has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('post.html',
                           title=post.title,
                           post=post,
                           form=form,
                           comments=comments)
示例#13
0
def post(id):
    post = Post.query.get_or_404(id)
    form = CommentForm()

    if form.validate_on_submit():
        comment = Comment(body=form.body.data,
                          post=post,
                          author=current_user._get_current_object())
        db.session.add(comment)
        flash('Your comment has been published.')
        return redirect(url_for('.post', id=post.id, page=-1))
    comments = post.comments.order_by(Comment.timestamp.asc())
    return render_template('post.html',
                           posts=[post],
                           form=form,
                           comments=comments)
def video(id):
    video = Video.query.get_or_404(id)

    if request.method == 'GET':
        video.views_count += 1
        db.session.commit()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comments(body=form.body.data, video=video,
                           author=current_user._get_current_object())
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('video', id=video.id))

    comments = video.comments.order_by(Comments.comment_time.desc())
    return render_template('video.html', title=video.video_title, form=form, video=video, comments=comments)
示例#15
0
def view_order(order_id):
    order = Order.query.filter_by(id=int(order_id)).first()
    form = CommentForm()
    if (order.dish.deliveryTime - datetime.now()).seconds > 86400:
        can_cancel = True
    else:
        can_cancel = False
    if form.validate_on_submit():
        order.comment = form.content.data
        db.session.commit()
        flash('Your comment has been saved.')
    return render_template('order_info.html',
                           user=user,
                           order=order,
                           form=form,
                           can_cancel=can_cancel)
示例#16
0
def view_post(id_post):
    post = Post.query.get(id_post)
    users = User.query.filter(User.id == Comments.author_id).all()
    form = CommentForm()
    if post.view_counter is None:
        post.view_counter = 0
    post.view_counter += 1
    db.session.commit()
    comments = Comments.query.filter(Comments.post_id == post.id).order_by(
        Comments.id.desc())  # post.comment
    return render_template('view_post.html',
                           post=post,
                           comments=comments,
                           form=form,
                           users=users,
                           title='Просмотр')
示例#17
0
def edit_comment(post_id, comment_id):
    user = User.query.filter_by(username=current_user.username).first_or_404()
    comment = Comment.query.filter_by(id=comment_id).first_or_404()
    if user.id != comment.user_id:  # Check user is allowed to edit comment
        return redirect(url_for('perm_error'))

    form = CommentForm()
    if form.validate_on_submit():
        comment.body = form.body.data
        comment.timestamp = datetime.utcnow()
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('post', post_id=post_id))
    elif request.method == 'GET':  # on arrival fill the page values
        form.fill_form(comment_id)
    return render_template('edit_comment.html', title="Edit Comment", form=form)
示例#18
0
def create_post(option, id):
    if option == 'commit_comment':
        form = CommentForm()
        if form.is_submitted():
            if len(form.comment_post.data) >= 140 or len(form.comment_post.data) <= 5:
                flash('Your post must be between 5 and 140 characters!')
                return redirect(request.referrer)
            else:
                addition = CommitComment(commit_id=id, user_id=current_user.id, comment=form.comment_post.data)
    else:
        if option == 'commit':
            form = CommitForm()
        else:
            form = PostForm()
        assignment_id = form.assignment.data
        schoology_id = Assignment.query.filter_by(id=assignment_id).first().schoology_id
        if form.is_submitted() and option == 'commit':
            if len(form.post.data) <= 5:
                flash('Your post must be longer than 5 characters!')
                return redirect(request.referrer)
            elif len(form.post.data) >= 140:
                flash('Your post must be shorter than 140 characters!')
                return redirect(request.referrer)
            elif type(form.time_spent.data) != int:
                flash('Your time spent must be a number')
                return redirect(request.referrer)
            elif schoology_id is None:
                flash('You cannot post about a sample assignment')
                return redirect(request.referrer)
            else:
                addition = Commit(user_id=int(current_user.id), assignment_id=int(assignment_id), schoology_id=int(schoology_id),
                        body=str(form.post.data), time_spent=int(form.time_spent.data))
        if form.is_submitted() and option == 'post':
            if len(form.post.data) <= 12:
                flash('Your post must be longer than 12 characters!')
                return redirect(request.referrer)
            elif schoology_id is None:
                flash('You cannot post about a sample assignment')
                return redirect(request.referrer)
            else:
                addition = Post(user_id=int(current_user.id), assignment_id=int(assignment_id), schoology_id=int(schoology_id),
                                body=form.post.data)

    db.session.add(addition)
    db.session.commit()
    flash('Congratulations for posting!')
    return redirect(request.referrer)
示例#19
0
def show_post(post_id):
    post = Post.query.get_or_404(post_id)
    authorlist = []
    for identity in post.authors.split("*"):
        authorlist.append(User.query.get(int(identity)))

    page = request.args.get('page', 1, type=int)
    if get_locale() == 'en':
        title, html, menu, category = grab_markdown(post.text_en)
    else:
        title, html, menu, category = grab_markdown(post.text_cn)
    pagination = Comment.query.with_parent(post).filter_by(reviewed=True).order_by(
        Comment.timestamp.asc()).paginate(page, app.config['COMMENT_PER_PAGE'], False)
    comments = pagination.items
    authors = post.authors
    next_url = url_for('.show_post', post_id=post_id, page=pagination.next_num) \
        if pagination.has_next else None
    prev_url = url_for('.show_post', post_id=post_id, page=pagination.prev_num) \
        if pagination.has_prev else None
  
    if current_user.is_authenticated:
        form = UserCommentForm()
        form.author.data = current_user.username
        form.email.data = '*****@*****.**'
        reviewed = True
        if current_user.username == post.author.username:
            from_author = True
        else:
            from_author = False
    else:
        form = CommentForm()
        reviewed = True
        from_author = False

    if form.validate_on_submit():
        comment = Comment(author=form.author.data, email=form.email.data, 
            body=form.body.data, from_author=from_author, post=post, reviewed=reviewed)
        replied_id = request.args.get('reply')
        if replied_id:
            replied_comment = Comment.query.get_or_404(replied_id)
            comment.replied = replied_comment
        db.session.add(comment)
        db.session.commit()
        flash('Published!', 'success')
        return redirect(url_for('.show_post', post_id=post_id)+ '#commentop')
    return render_template('blog/post.html', post=post, html=html, menu=menu, title=title, form=form, comments=comments, 
        pagination=pagination, next_url=next_url, prev_url=prev_url, authorlist=authorlist)
示例#20
0
def post(id):
    post = Post.query.filter_by(id=id).first_or_404()
    form = CommentForm()
    if form.validate_on_submit():
        if not current_user.is_authenticated:
            return redirect(url_for("login"))
        post.add_comment(form.body.data, current_user)
        flash("Your comment is now live!")
        return redirect(url_for("post", id=id))
    return render_template(
        "post.html",
        greeting_name=greeting_name(),
        title=post.title,
        post=post,
        comments=post.comments,
        form=form,
    )
示例#21
0
def post_page(topic_id, subtopic_id, post_id, page=1):
    session = create_session()
    post = session.query(Post).filter(Post.id == post_id,
                                      Post.subtopic_id == subtopic_id).first()
    subtopic = session.query(SubTopic).filter(
        SubTopic.id == subtopic_id, SubTopic.topic_id == topic_id).first()
    topic = session.query(Topic).filter(Topic.id == topic_id).first()
    if not (post and subtopic and topic):
        abort(404)
    if post.lvl_access > 1 and (
        (current_user.is_authenticated and current_user.role < post.lvl_access
         and current_user.id != post.author_id)
            or not current_user.is_authenticated):
        abort(403)
    if ((not current_user.is_authenticated
         or post.author_id != current_user.id) and not post.published):
        abort(404)

    current_page = paginate(
        session.query(Comment).filter(Comment.post_id == post_id), page, 20)
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(author_id=current_user.id,
                          text=form.text.data,
                          post_id=post_id)
        session.add(comment)
        session.commit()
        return redirect('#')
    liked = list(map(
        lambda x: x.id,
        current_user.liked.all())) if current_user.is_authenticated else []
    disliked = list(map(
        lambda x: x.id,
        current_user.disliked.all())) if current_user.is_authenticated else []
    return render_template('post.html',
                           title=topic.title + ' - ' + subtopic.title + ' - ' +
                           post.title,
                           topic=topic,
                           subtopic=subtopic,
                           post=post,
                           User=User,
                           session=session,
                           form=form,
                           current_page=current_page,
                           liked=liked,
                           disliked=disliked)
示例#22
0
def create_comment(id_post):
    form = CommentForm()
    if form.validate_on_submit():
        user = User.query.filter(User.email == current_user.email).one()
        post = Post.query.get(id_post)
        new_comment = Comments(text=form.text.data,
                               date_created=datetime.now() -
                               timedelta(hours=3),
                               author_id=user.id,
                               post_id=post.id)
        db.session.add(new_comment)
        if post.comment_counter is None:
            post.comment_counter = 0
        post.comment_counter += 1
        db.session.commit()
        return redirect(url_for('view_post', id_post=post.id))
    return form
示例#23
0
def view_post(id):
    posts = Post.query.filter_by(id=id).first_or_404()
    comments = Comment.query.filter_by(post_id=posts.id).all()
    form = CommentForm()
    if form.validate_on_submit():
        comment = Comment(content=form.content.data,
                          post=posts,
                          author=current_user.username)
        db.session.add(comment)
        db.session.commit()
        flash('Your comment is now live!')
        return redirect(url_for('view_post', id=id))

    return render_template('view_post.html',
                           posts=posts,
                           comments=comments,
                           form=form)
示例#24
0
def news_comment(id):
    form = CommentForm()
    cur = mysql.connect().cursor()
    sql = "select newsid, Picture, Content, Name from news WHERE newsid=%s" % (
        id)
    cur.execute(sql)
    news = cur.fetchone()
    p = re.compile(r'<.*?>')
    new = p.sub('', news[2])
    if form.validate():
        comment = Comments_news(newsid=id,
                                created_at=datetime.datetime.now(),
                                body=form.body.data,
                                author=form.author.data)
        db.session.add(comment)
        db.session.commit()
    return render_template('news_comment.html', news=news, new=new, form=form)
示例#25
0
def contact():
    form = CommentForm()
    if form.validate_on_submit():

        c = Carpenter()

        name = form.name.data
        email = form.email.data
        comment = form.comment.data
        firstname = c.get_first_name(name)

        thank_you = "Thanks for visiting, {:}. We've sent your comment on to headquarters.".format(firstname)
        c.log_comment(name, email, comment)

        return render_template("contact_confirmation.html", title="Thanks!", thank_you=thank_you)

    return render_template('contact_form.html', title='Get in Touch', form=form)
示例#26
0
文件: post.py 项目: yxm0513/7topdig
def view(post_id, slug=None):
    post = Post.query.get_or_404(post_id)
    if not post.permissions.view:
        if not current_user:
            flash(u"你需要先登录", "error")
            return redirect(url_for("account.login", next=request.path))
        else:
            flash(u"你需要有权限", "error")
            abort(403)

    def edit_comment_form(comment):
        return CommentForm(obj=comment)

    return render_template("post/post.html",
                           comment_form=CommentForm(),
                           edit_comment_form=edit_comment_form,
                           post=post)
示例#27
0
def add_comment():

    form = CommentForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    new_comment = Comment(
        user_id=request.form['userId'],
        song_id=request.form['songId'],
        comment=request.form['comment'],
    )

    db.session.add(new_comment)
    db.session.commit()
    data = new_comment.to_dict()
    user = User.query.get(data['user_id']).to_dict()
    data['userProfileURL'] = user['profile_URL']
    data['username'] = user['artist_name']
    return data
示例#28
0
def blog_single(id):
    form = CommentForm()
    context = {
        'post': Post.query.get(id),
        'form': form,
        'comments': Post.query.get(id).comments.all()
    }
    if form.validate_on_submit():
        db.session.add(
            Comment(name=form.name.data,
                    email=form.email.data,
                    body=form.body.data,
                    post_id=id))
        db.session.commit()
        return redirect(
            url_for('blog_single', id=id, _anchor='section-comments'))
    return render_template('blog-single.html', **context)
示例#29
0
def single(_id_):
    form = CommentForm()
    if form.validate_on_submit():
        comm = Comment(content=form.text.data,
                       user_id=current_user.id,
                       blog_id=_id_)
        blog = Blog.query.filter(Blog.id == _id_).first()
        blog.commentnum += 1
        db.session.add(blog)
        db.session.add(comm)
        return redirect(url_for('posts.single', _id_=_id_))
    post = Blog.query.filter(Blog.id == _id_).first()
    comments = Comment.query.filter(Comment.blog_id == _id_).all()
    return render_template('posts/single.html',
                           post=post,
                           form=form,
                           comments=comments)
示例#30
0
def post(post_id):
    form = CommentForm()
    mdform = MdForm()
    post = Post.query.filter_by(id=post_id).first_or_404()
    mdform.body.data = post.body
    comments = Comment.query.filter_by(post_id=post_id).order_by(
        Comment.timestamp.desc()).all()
    tags = Tagged.query.filter_by(post_id=post_id).all()
    liked_cnt = Liked.query.filter_by(post_id=post_id).count()
    collected_cnt = Collected.query.filter_by(post_id=post_id).count()
    if form.validate_on_submit():
        if current_user.is_authenticated:
            new_comment = Comment(body=form.body.data,
                                  user_id=current_user.id,
                                  post_id=post_id)
            db.session.add(new_comment)
            db.session.commit()
            return redirect(url_for('post', post_id=post.id))
        else:
            return redirect(url_for('login'))
    if not current_user.is_authenticated:
        isLiked = False
        isCollected = False
    else:
        if Liked.query.filter(
                and_(Liked.post_id == post_id,
                     Liked.user_id == current_user.id)).count() == 0:
            isLiked = False
        else:
            isLiked = True
        if Collected.query.filter(
                and_(Collected.post_id == post_id,
                     Collected.user_id == current_user.id)).count() == 0:
            isCollected = False
        else:
            isCollected = True
    return render_template('post.html',
                           mdform=mdform,
                           form=form,
                           post=post,
                           liked_cnt=liked_cnt,
                           isLiked=isLiked,
                           comments=comments,
                           collected_cnt=collected_cnt,
                           isCollected=isCollected,
                           tags=tags)