Example #1
0
def update_topic(tid):
    topic = Topic.query.get(tid)
    if not topic:
        raise NotFound('Topic')

    if not topic.editable:
        raise Denied('updating this topic')

    form = TopicForm.create_api_form(obj=topic)
    topic = form.update_topic(current_user.id)
    data = make_topic_response(topic)
    data['user'] = dict(current_user)
    data['content'] = topic.html
    return jsonify(data)
Example #2
0
def update_topic(tid):
    topic = Topic.query.get(tid)
    if not topic:
        raise NotFound('Topic')

    if not topic.editable:
        raise Denied('updating this topic')

    form = TopicForm.create_api_form(obj=topic)
    topic = form.update_topic(current_user.id)
    data = make_topic_response(topic)
    data['user'] = dict(current_user)
    data['content'] = topic.html
    return jsonify(data)
Example #3
0
def create_cafe_topic(slug):
    cafe = Cafe.cache.first_or_404(slug=slug)

    if not current_user.is_active:
        raise InvalidAccount(description='Your account is not active')

    if cafe.permission == Cafe.PERMISSION_PUBLIC:
        CafeMember.get_or_create(cafe.id, current_user.id)

    form = TopicForm.create_api_form()
    topic = form.create_topic(current_user.id)

    with db.auto_commit():
        cafe.create_cafe_topic(topic.id, current_user.id)

    data = dict(topic)
    data['user'] = dict(current_user)
    data['content'] = topic.html
    return jsonify(data), 201
Example #4
0
def create_topic():
    form = TopicForm.create_api_form()
    topic = form.create_topic(current_user.id)
    data = make_topic_response(topic)
    return jsonify(data)