Esempio n. 1
0
def edit_post (post_id):
    """ 
    edits post contents
    """

    post = Post.query.get(post_id)
    if not post:
        return "postnotfound", 404

    if not current_user.may_edit (post):
        return "forbidden", 403

    editedContent = request.json["editedContent"]
    post.content = editedContent

    db.session.commit()

    #TODO: save which user edited the post and
    #pass the editing user in the event

    event_dispatcher = EventDispatcher()
    event = Event("post_edited", post)
    event_dispatcher.dispatch(event)
    event = Event("post_id_edited", post.id)
    event_dispatcher.dispatch(event)

    return ""
Esempio n. 2
0
def change_topic_title (topic_str):
    """ 
    changes a topic title. this function is called via ajax
    by the click event handler for #submit-edited-post in topic.js
    """
    topic_id = int(topic_str.split("-")[0])

    topic = Topic.query.get(topic_id)
    if not topic:
        return "nosuchtopic", 400
    
    if not current_user.may_edit(topic.first_post):
        return "forbidden", 403

    topic.title = request.json["newTitle"]
    db.session.commit()

    event_dispatcher = EventDispatcher()
    event = Event("topic_title_changed", topic)
    event_dispatcher.dispatch(event)
    event = Event("topic_id_title_changed", topic.id)
    event_dispatcher.dispatch(event)

    return ""