You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
import peewee
|
|
from flask import render_template, Blueprint, request
|
|
|
|
from suchwow._models import Post, TipReceived, User
|
|
|
|
|
|
bp = Blueprint("leaderboard", "leaderboard")
|
|
|
|
@bp.route("/leaderboards/top_posters")
|
|
def top_posters():
|
|
top_posters = TipReceived.select(
|
|
TipReceived.post, peewee.fn.SUM(TipReceived.amount)
|
|
).join(Post).order_by(
|
|
peewee.fn.SUM(TipReceived.amount).desc()
|
|
).group_by(TipReceived.post)
|
|
# revenue = fn.SUM(Booking.slots * Case(None, (
|
|
# (Booking.member == 0, Facility.guestcost),
|
|
# ), Facility.membercost))
|
|
#
|
|
# query = (Facility
|
|
# .select(Facility.name, revenue.alias('revenue'))
|
|
# .join(Booking)
|
|
# .group_by(Facility.name)
|
|
# .order_by(SQL('revenue')))
|
|
return render_template("leaderboard.html", posters=top_posters)
|
|
|
|
@bp.route("/leaderboards/top_posts")
|
|
def top_posts():
|
|
days = request.args.get('days', 1)
|
|
try:
|
|
days = int(days)
|
|
except:
|
|
days = 1
|
|
|
|
if days not in [1, 3, 7, 30, 9999]:
|
|
days = 7
|
|
|
|
posts = get_top_posts(days)
|
|
return render_template("post/top.html", posts=posts, days=days)
|