Ejemplo n.º 1
0
def new_post():
    """allows user to create a new post"""
    form = PostForm()
    the_post = Post()
    if form.validate_on_submit():
        the_author = Author.get_by_display_name(form.author_display_name.data)
        the_post.author_id = the_author.id
        the_post.title = form.title.data
        the_post.date_written = form.date_written.data
        the_post.body = form.body.data
        the_post.language_id = Language.query.filter(
            Language.name == form.language.data).first().id
        the_post.country_id = Country.query.filter(
            Country.name == form.nasod.data).first().id
        the_post.created_by = current_user.id
        the_post.modified_by = current_user.id
        db.session.add(the_post)
        db.session.commit()
        return redirect(url_for('post', post_id=the_post.id))
    elif request.method == 'GET':
        the_post.title = form.title.data
        the_post.date_written = form.date_written.data
        the_post.body = form.body.data
        the_post.language = form.language.data
    return render_template('post.html',
                           form=form,
                           post=the_post,
                           poster=current_user)
Ejemplo n.º 2
0
def post(user):
    post = Post()
    post.title = "Fast API + GraphQL"
    post.body = "this is the post body and can be as long as possible"

    user.posts().save(post)
    return post