コード例 #1
0
ファイル: app.py プロジェクト: champagne-dev/champics
def postView(topic_name, post_slug):
    r = request.args.get('r')
    topic = sql.selectTopicByName(topic_name)
    post = sql.selectPostBySlug(post_slug)
    comments = sql.selectCommentsByPost(post.id)

    try:
        mapped_comments = list(map(lambda x: {
            "text": x.text, 
            "author": x.author, 
            "replied_id": str(x.replied_id), 
            "score": str(int(x.score)), 
            "relative_url": x.relative_url,
            "id": str(x.id),
            "created_timestamp": str(x.created_timestamp)
        }, comments))
        try:
            if r == "new":
                mapped_comments = ranking.orderNewComments(mapped_comments)
            else:
                mapped_comments = ranking.orderTopComments(mapped_comments)
                
        except Exception as e:
            print e
    except:
        mapped_comments = list()

    return render_template("post.html", topics=json.dumps(g.topics), current_topic=json.dumps({"name": topic.name, "id": str(topic.id)}), current_post=json.dumps({"id": post.id, "name": post.name, "slug": post.slug, "relative_url": post.relative_url, "score": post.score, "created_timestamp": post.created_timestamp, "comments":mapped_comments}, default=defaultDatetimeJSONDump))
コード例 #2
0
ファイル: app.py プロジェクト: champagne-dev/champics
def createPostDownvote(topic_name, post_slug):
    post = sql.selectPostBySlug(post_slug)
    sql.decrementPostScore(post.id)
    return jsonify(results=success)