コード例 #1
0
ファイル: topic.py プロジェクト: retooth/morse
def topic (topic_str):
    """ 
    renders topic view
    :param topic_id: indicates topic view to render
    :rtype: html 
    """
    topic_id = int(topic_str.split("-")[0])
    topic = Topic.query.get(topic_id)
    if not topic:
       return "nosuchtopic", 400

    check_ban(topic.board_id)

    if not current_user.may_read(topic.board):
        return render_template('4xx/403-default.html'), 403

    topic.view_count = Topic.view_count + 1
    db.session.commit()

    topic_with_user_context = TopicWrapper(topic)
    post_filter_dispatcher = PostFilterDispatcher()
    format_tool_dispatcher = FormatToolDispatcher()

    return render_template("topic.html", topic = topic_with_user_context, 
                            post_filter_dispatcher = post_filter_dispatcher,
                            format_tool_dispatcher = format_tool_dispatcher)
コード例 #2
0
ファイル: builders.py プロジェクト: retooth/morse
def certain_posts (topic_str):
    """ 
    renders a number of posts defined by GET json parameter
    this function is called via ajax in topic.js
    """
    topic_id = int(topic_str.split("-")[0])
    topic = Topic.query.get(topic_id)
    if not topic:
        return "topicnotfound", 404

    topic = TopicWrapper(topic)
    if not current_user.may_read(topic.board):
        return "forbidden", 403

    posts = []
    for post_id in request.json["IDs"]:
        post = Post.query.get(post_id)
        if not post or post.topic_id != topic_id:
            return "invalidrequest", 400
            break
        post = PostWrapper(post)
        posts.append(post)

    format_tool_dispatcher = FormatToolDispatcher()
    return render_template("partial/posts.html", posts = posts, format_tool_dispatcher = format_tool_dispatcher)
コード例 #3
0
ファイル: topic.py プロジェクト: retooth/morse
def get_posts (topic_str):
    """ 
    returns a JSON object with structure {postIDs: [post_id]}
    this function is called via ajax in topic.js
    """
    topic_id = int(topic_str.split("-")[0])

    topic = Topic.query.get(topic_id)
    if not topic:
        return "topicnotfound", 404

    topic = TopicWrapper(topic)

    if not current_user.may_read(topic.board):
        return "forbidden", 403

    post_ids = []
    for post in PostListGenerator(topic_id):
        post_ids.append(post.id)

    return jsonify(IDs = post_ids)
コード例 #4
0
ファイル: board.py プロジェクト: retooth/morse
def board(board_str):
    """ 
    Renders the board view for board_id
    :rtype: html
    """
    board_id = int(board_str.split("-")[0])
    check_ban(board_id)

    board  = Board.query.filter(Board.id == board_id).first()
    if not board:
        return render_template('4xx/404-default'), 404

    if not current_user.may_read(board):
        return render_template('4xx/403-default.html'), 403

    topic_filter_dispatcher = TopicFilterDispatcher()
    format_tool_dispatcher = FormatToolDispatcher()

    return render_template('board.html', board = board,
                            topic_filter_dispatcher = topic_filter_dispatcher,
                            format_tool_dispatcher = format_tool_dispatcher)
コード例 #5
0
ファイル: board.py プロジェクト: retooth/morse
def get_topics (board_str):
    """ 
    returns a JSON object with structure {topicIDs: [topic_id]}
    this function is called via ajax in board.js
    """
    board_id = int(board_str.split("-")[0])

    board = Board.query.get(board_id)
    if not board:
        return "boardnotfound", 404

    if not current_user.may_read(board):
        return "forbidden", 403

    topic_ids = []
    for topic in TopicListGenerator(board_id):
        topic_ids.append(topic.id)

    cache = TopicCache()
    cache.refresh(board_id) 

    return jsonify(IDs = topic_ids)
コード例 #6
0
ファイル: builders.py プロジェクト: retooth/morse
def certain_topics (board_str):
    """ 
    renders a number of topics defined by GET json parameter
    this function is called via ajax in board.js
    """
    board_id = int(board_str.split("-")[0])
    board = Board.query.get(board_id)
    if not board:
        return "boardnotfound", 404

    if not current_user.may_read(board):
        return "forbidden", 403

    topics = []
    for topic_id in request.json["IDs"]:
        topic = Topic.query.get(topic_id)
        if not topic or topic.board_id != board_id:
            return "invalidrequest", 400
            break
        topic = TopicWrapper(topic)
        topics.append(topic)

    return render_template("partial/topics.html", topics = topics)