Ejemplo n.º 1
0
def index():
    form = PostForm()
    if form.validate_on_submit():
        language = guess_language(form.post.data)
        if language == 'UNKNOWN' or len(language) > 5:
            language = ''
        post = Post(body=form.post.data,
                    author=current_user,
                    language=language)
        db.session.add(post)
        db.session.commit()
        flash(_('Your post is now live!'))
        return redirect(url_for('index'))
    page = request.args.get('page', 1, type=int)
    posts = current_user.followed_posts().paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('index', page=posts.next_num) \
        if posts.has_next else None
    prev_url = url_for('index', page=posts.prev_num) \
        if posts.has_prev else None
    return render_template('index.html',
                           title=_('Home'),
                           form=form,
                           posts=posts.items,
                           next_url=next_url,
                           prev_url=prev_url)
Ejemplo n.º 2
0
def write():
	form = PostForm()
	if form.validate_on_submit():
		post = Post(title=form.title.data,content = form.content.data,user_id = current_user.id)
		db.session.add(post)
		db.session.commit()
		flash('Your post is now live!')
		return redirect(url_for('index'))
	return render_template('write.html',title='Write',form=form)
Ejemplo n.º 3
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        p = Post(title = form.title.data, body = form.body.data,\
            subject = form.subject.data, user_id = current_user.id)
        db.session.add(p)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('new_post.html', form=form)
Ejemplo n.º 4
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New post',
                           form=form,
                           legend='Update Post')
Ejemplo n.º 5
0
def post():
    """
    記事をポストするページ
    """
    form = PostForm()
    if form.validate_on_submit():
        article = Post(title=form.title.data,
                       author=current_user,
                       tag=form.tag.data,
                       body=form.body.data,
                       published_on=datetime.now())
        db.session.add(article)
        db.session.commit()
        print("post success")
        flash('Successfully posted')
        return redirect(url_for('index'))
    return render_template('post.html', form=form)
Ejemplo n.º 6
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    if post.author != current_user:
        abort(403)
    form = PostForm()
    if form.validate_on_submit():
        post.title = form.title.data
        post.content = form.content.data
        db.session.commit()
        flash('Your post has been updated!', 'success')
        return redirect(url_for('post', post_id=post.id))
    elif request.method == 'GET':
        form.title.data = post.title
        form.content.data = post.content
    return render_template('create_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')
Ejemplo n.º 7
0
def post():
    """
    記事をポストするページ
    """
    form = PostForm()
    if form.validate_on_submit():
        article = Post(
            title=form.title.data,
            author=current_user,
            tag=form.tag.data,
            body=form.body.data,
            published_on=datetime.now(),
        )
        db.session.add(article)
        db.session.commit()
        print("post success")
        flash("Successfully posted")
        return redirect(url_for("index"))
    return render_template("post.html", form=form)