Пример #1
0
def api_create_post():
    if request.form['sawGender'] not in Post.allowed_genders or request.form['authorGender'] not in Post.allowed_genders:
        abort(400)
    p = Post(request.form['title'], request.form['body'], request.remote_addr, request.form['authorGender'], request.form['sawGender'])
    if 'sign' in request.form and request.form['sign'] == 'true':
        if g.athena is None:
            abort(400)
        p.author = g.athena
        if request.form['replies'] == 'true':
            p.replies_enabled = True
    if 'sticky' in request.form and request.form['sticky'] == 'true' and g.athena in moderators:
        p.sticky = True

    # save the post and return its id
    p.add()
    return standardize_json({'id': p.id})