forked from orson/bachemap
leaderboard collation and template, but not working right
This commit is contained in:
parent
aeb7ca9749
commit
599cc12a05
48
app.py
48
app.py
@ -237,8 +237,56 @@ def create_app(config=Config):
|
|||||||
}
|
}
|
||||||
mongo.db.users.insert_one(admin_user)
|
mongo.db.users.insert_one(admin_user)
|
||||||
print(f"Admin {username} added! Referral code is {admin_user['referral_code']}")
|
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
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app=create_app()
|
app=create_app()
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|||||||
6
templates/leaderboard.html
Normal file
6
templates/leaderboard.html
Normal 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>
|
||||||
Loading…
Reference in New Issue
Block a user