Exemple #1
0
def topicView(topic_name):
    r = request.args.get('r')
    topic = sql.selectTopicByName(topic_name)
    posts = sql.selectPostsByTopic(topic.id)

    try:
        mapped_posts = list(map(lambda x: {
            "name": x.name, 
            "slug": x.slug, 
            "relative_url": x.relative_url, 
            "score": str(int(x.score)),
            "id": str(x.id),
            "created_timestamp": str(x.created_timestamp)
        }, posts))
        try:
            if r == "new":
                mapped_posts = ranking.orderNewPosts(mapped_posts)
            else:
                mapped_posts = ranking.orderTopPosts(mapped_posts)

        except Exception as e:
            print e

    except Exception as e:
        mapped_posts = list()

    return render_template("topic.html", topics=json.dumps(g.topics), current_topic=json.dumps({"name": topic.name, "id": str(topic.id)}), posts=json.dumps(mapped_posts))
Exemple #2
0
def frontpageView():
    r = request.args.get('r')
    posts = sql.selectPosts(20, True)

    try:
        mapped_posts = list(map(lambda x: {
            "name": x.name, 
            "slug": x.slug, 
            "relative_url": x.relative_url, 
            "score": str(int(x.score)),
            "id": str(x.id),
            "created_timestamp": str(x.created_timestamp)
        }, posts))
        try:
            if r == "new":
                mapped_posts = ranking.orderNewPosts(mapped_posts)
            else:
                mapped_posts = ranking.orderTopPosts(mapped_posts)

        except Exception as e:
            print e

    except Exception as e:
        mapped_posts = list()
    
    if r == "new":
        r = "New"
    else:
        r = "Top"

    return render_template("frontpage.html", topics=json.dumps(g.topics), posts=json.dumps(mapped_posts), r=r)