示例#1
0
def get_post(post_id, title=""):
    # Locate post
    matched_post = post.get_post(post_id=post_id)
    if matched_post is None:
        return abort(404)

    # Render main post's markdown
    body = markdown.render_markdown.delay(matched_post.body).wait()

    if body is None:
        return abort(500)

    # Get answers
    try:
        page = int(request.args.get('p', 1))
    except ValueError:
        return abort(400)

    answers = answer_controller.get_answers(post_id=post_id, page=page)
    leaderboard = Leaderboard(post_id=post_id)

    # Get respective comments
    answer_comments = []
    for answer in answers.items:
        answer_comments.append(get_rendered_comments(AnswerComment, max_depth=2, answer_id=answer.id))

    post_comments = get_rendered_comments(PostComment, max_depth=2, post_id=post_id)

    return \
        render_template('post/view.html', post_id=post_id, post=matched_post,
                        post_body=body, answers=answers, leaderboard=leaderboard,
                        vote=vote, answer_comments=answer_comments, post_comments=post_comments)
示例#2
0
    def get(self):
        try:
            post_id = int(request.args.get("id"))
        except:
            print("Gecersiz Post_id")
            abort(400)

        data = get_post(post_id)
        if not data:
            print("Bu post_id:{}'ye sahip post bulunamadi".format(post_id))
            abort(404)

        return {'status': 'OK', 'data': data}
示例#3
0
文件: post.py 项目: vishvega/Axtell
def get_post(post_id, title=None):
    # Locate post
    matched_post = post.get_post(post_id=post_id)
    if matched_post is None:
        return abort(404)

    if matched_post.deleted:
        return render_template('deleted.html'), 410

    # Always redirect to canonical url
    slug = slugify(matched_post.title)

    # Redirect if slug is incorrect. add 'noredirect=1' flag to avoid infinite redirection in
    # exceptional circumstances
    if title != slug and request.args.get('noredirect', '0') != '1':
        canonical_url = url_for('get_post', p=request.args.get('p'), post_id=post_id, title=slug, noredirect=1)
        return redirect(canonical_url, code=301)

    # Render main post's markdown
    body = markdown.render_markdown.delay(matched_post.body).wait()

    if body is None:
        return abort(500)

    # Get answers
    try:
        page = int(request.args.get('p', 1))
    except ValueError:
        return abort(400)

    answers = answer_controller.get_answers(post_id=post_id, page=page)
    leaderboard = Leaderboard(post_id=post_id)

    # Get respective comments
    answer_comments = [get_rendered_comments(AnswerComment, max_depth=2, answer_id=answer.id)
                       for answer in answers.items]

    post_comments = get_rendered_comments(PostComment, max_depth=2, post_id=post_id)

    return \
        render_template('post/view.html', post_id=post_id, post=matched_post,
                        post_body=body, answers=answers, leaderboard=leaderboard,
                        vote=vote, answer_comments=answer_comments, post_comments=post_comments)
示例#4
0
def get_post(post_id):
    # Locate post
    matched_post = post.get_post(post_id=post_id)
    if matched_post is None:
        return abort(404)

    # Render main post's markdown
    body = markdown.render_markdown.delay(matched_post.body).wait()

    if body is None:
        return abort(500)

    # Get answers
    try:
        page = int(request.args.get('p', 1))
    except ValueError:
        return abort(400)

    answers = answer.get_answers(post_id=post_id, page=page)

    return render_template('post/view.html',
                           post=matched_post,
                           post_body=body,
                           answers=answers)
示例#5
0
文件: post.py 项目: vishvega/Axtell
def get_canonical_post_url(post_id):
    matched_post = post.get_post(post_id=post_id)
    if matched_post is None:
        return abort(404)
    url = canonical_host + url_for('get_post', post_id=post_id, title=slugify(matched_post.title))
    return render_json({"url": url})