1
0
forked from orson/bachemap

leaderboard collation and template, but not working right

This commit is contained in:
Orson 2024-09-09 20:37:18 -06:00
parent aeb7ca9749
commit 599cc12a05
2 changed files with 54 additions and 0 deletions

48
app.py
View File

@ -237,8 +237,56 @@ def create_app(config=Config):
}
mongo.db.users.insert_one(admin_user)
print(f"Admin {username} added! Referral code is {admin_user['referral_code']}")
@app.route('/leaderboard')
def leaderboard():
leaders = mongo.db.pins.aggregate([
{
"$group": {
"_id":"$added_by",
"count": {"$sum":1}
}
},
{
"$sort": {"count":-1}
},
{
"$limit":10
},
{
"$lookup": {
"from": "users",
"localField": "_id",
"foreignField": "_id",
"as": "user_info"
}
},
{
"$unwind": "$user_info"
},
{
"$project": {
"_id":0,
"added_by": "$_id",
"count":1,
"username": "$user_info.username"
}
}
])
print(leaders)
for leader in leaders:
leader["username"] = leader["username"][0]+"***"+leader["username"][-1]
if current_user.is_authenticated:
username = user.username
else:
username = None
return render_template('leaderboard.html', leaders=leaders, username=username)
return app
app=create_app()
if __name__ == '__main__':
app.run(debug=True)

View File

@ -0,0 +1,6 @@
{% extends 'secondbase.html' %}
<ul>
{% for leader in leaders %}
{% if username != None and leader.username == username %}<li><span style="padding-left: -100%;">¡Felicidades, estás aquí!</span><b>{{ leader.username }} -> {{leader.count}}</b></li>{% else %}{{leader.username}} -> {{leader.count}}{% endif %}
{% endfor %}
</ul>