dont pass db session as an argument unless necessary

pull/152/head
Aevann 2023-06-08 03:49:37 +03:00
parent ee92098abe
commit d8bfc0a0a9
16 changed files with 94 additions and 100 deletions

View File

@ -259,7 +259,9 @@ class Comment(Base):
if kind == 'tilt' and num > 4: return 4
return num
def json(self, db:scoped_session):
@property
@lazy
def json(self):
if self.is_banned:
data = {'is_banned': True,
'ban_reason': self.ban_reason,
@ -301,7 +303,7 @@ class Comment(Base):
'is_bot': self.is_bot,
'flags': flags,
'author': '👻' if self.ghost else self.author.json,
# 'replies': [x.json(db=db) for x in self.replies(sort="old", v=None)] # WORKER TIMEOUTS ON BUGTHREAD
# 'replies': [x.json for x in self.replies(sort="old", v=None)] # WORKER TIMEOUTS ON BUGTHREAD
}
if self.level >= 2: data['parent_comment_id'] = self.parent_comment_id

View File

@ -29,8 +29,9 @@ class HatDef(Base):
def __repr__(self):
return f"<{self.__class__.__name__}(id={self.id})>"
@property
@lazy
def number_sold(self, db:scoped_session):
def number_sold(self):
return db.query(Hat).filter_by(hat_id=self.id).count()
@lazy

View File

@ -2,6 +2,7 @@ from typing import Any, Callable, Optional, Tuple, Union
from sqlalchemy import Column, func
from sqlalchemy.orm import scoped_session
from flask import g
from files.helpers.config.const import *
@ -27,14 +28,14 @@ class Leaderboard:
def __init__(self, header_name:str, table_header_name:str, html_id:str, table_column_name:str,
user_relative_url:Optional[str], query_function:Callable[..., Tuple[Any, Any, Any]],
criteria, v:User, value_func:Optional[Callable[[User], Union[int, Column]]], db:scoped_session, users, limit=LEADERBOARD_LIMIT):
criteria, v:User, value_func:Optional[Callable[[User], Union[int, Column]]], users, limit=LEADERBOARD_LIMIT):
self.header_name = header_name
self.table_header_name = table_header_name
self.html_id = html_id
self.table_column_name = table_column_name
self.user_relative_url = user_relative_url
self.limit = limit
lb = query_function(criteria, v, db, users, limit)
lb = query_function(criteria, v, users, limit)
self.all_users = lb[0]
self.v_position = lb[1]
self.v_value = lb[2]
@ -48,12 +49,12 @@ class Leaderboard:
self.value_func = lambda u: u[1] or 0
@classmethod
def get_simple_lb(cls, order_by, v:User, db:scoped_session, users, limit:int):
def get_simple_lb(cls, order_by, v:User, users, limit:int):
leaderboard = users.order_by(order_by.desc()).limit(limit).all()
position = None
if v not in leaderboard:
sq = db.query(User.id, func.rank().over(order_by=order_by.desc()).label("rank")).subquery()
position = db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
sq = g.db.query(User.id, func.rank().over(order_by=order_by.desc()).label("rank")).subquery()
position = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
return (leaderboard, position, None)
@classmethod
@ -65,8 +66,8 @@ class Leaderboard:
return func.rank().over(order_by=func.count(criteria).desc()).label("rank")
@classmethod
def get_badge_marsey_lb(cls, lb_criteria, v:User, db:scoped_session, users:Any, limit):
sq = db.query(lb_criteria, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria)).group_by(lb_criteria).subquery()
def get_badge_marsey_lb(cls, lb_criteria, v:User, users:Any, limit):
sq = g.db.query(lb_criteria, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria)).group_by(lb_criteria).subquery()
sq_criteria = None
if lb_criteria == Badge.user_id:
sq_criteria = User.id == sq.c.user_id
@ -75,42 +76,42 @@ class Leaderboard:
else:
raise ValueError("This leaderboard function only supports Badge.user_id and Emoji.author_id")
leaderboard = db.query(User, sq.c.count).join(sq, sq_criteria).order_by(sq.c.count.desc())
position = db.query(User.id, sq.c.rank, sq.c.count).join(sq, sq_criteria).filter(User.id == v.id).one_or_none()
leaderboard = g.db.query(User, sq.c.count).join(sq, sq_criteria).order_by(sq.c.count.desc())
position = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, sq_criteria).filter(User.id == v.id).one_or_none()
if position: position = (position[1], position[2])
else: position = (leaderboard.count() + 1, 0)
leaderboard = leaderboard.limit(limit).all()
return (leaderboard, position[0], position[1])
@classmethod
def get_blockers_lb(cls, lb_criteria, v:User, db:scoped_session, users:Any, limit):
def get_blockers_lb(cls, lb_criteria, v:User, users:Any, limit):
if lb_criteria != UserBlock.target_id:
raise ValueError("This leaderboard function only supports UserBlock.target_id")
sq = db.query(lb_criteria, cls.count_and_label(lb_criteria)).group_by(lb_criteria).subquery()
leaderboard = db.query(User, sq.c.count).join(User, User.id == sq.c.target_id).order_by(sq.c.count.desc())
sq = g.db.query(lb_criteria, cls.count_and_label(lb_criteria)).group_by(lb_criteria).subquery()
leaderboard = g.db.query(User, sq.c.count).join(User, User.id == sq.c.target_id).order_by(sq.c.count.desc())
sq = db.query(lb_criteria, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria)).group_by(lb_criteria).subquery()
position = db.query(sq.c.rank, sq.c.count).join(User, User.id == sq.c.target_id).filter(sq.c.target_id == v.id).limit(1).one_or_none()
sq = g.db.query(lb_criteria, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria)).group_by(lb_criteria).subquery()
position = g.db.query(sq.c.rank, sq.c.count).join(User, User.id == sq.c.target_id).filter(sq.c.target_id == v.id).limit(1).one_or_none()
if not position: position = (leaderboard.count() + 1, 0)
leaderboard = leaderboard.limit(limit).all()
return (leaderboard, position[0], position[1])
@classmethod
def get_hat_lb(cls, lb_criteria, v:User, db:scoped_session, users:Any, limit):
leaderboard = db.query(User, func.count(lb_criteria)).join(lb_criteria).group_by(User).order_by(func.count(lb_criteria).desc())
sq = db.query(User.id, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria)).join(lb_criteria).group_by(User).subquery()
position = db.query(sq.c.rank, sq.c.count).filter(sq.c.id == v.id).limit(1).one_or_none()
def get_hat_lb(cls, lb_criteria, v:User, users:Any, limit):
leaderboard = g.db.query(User, func.count(lb_criteria)).join(lb_criteria).group_by(User).order_by(func.count(lb_criteria).desc())
sq = g.db.query(User.id, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria)).join(lb_criteria).group_by(User).subquery()
position = g.db.query(sq.c.rank, sq.c.count).filter(sq.c.id == v.id).limit(1).one_or_none()
if not position: position = (leaderboard.count() + 1, 0)
leaderboard = leaderboard.limit(limit).all()
return (leaderboard, position[0], position[1])
@classmethod
def get_upvotes_lb(cls, lb_criteria, v:User, db:scoped_session, users:Any, limit):
def get_upvotes_lb(cls, lb_criteria, v, users:Any, limit):
users13 = cache.get("users13") or []
users13_1 = cache.get("users13_1") or []
users13_2 = cache.get("users13_2") or []
users13_accs = db.query(User).filter(User.id.in_(users13_1)).all()
users13_accs = g.db.query(User).filter(User.id.in_(users13_1)).all()
users13_accs = sorted(users13_accs, key=lambda x: users13_1.index(x.id))
users13_accs = tuple(zip(users13_accs, users13_2))
try:
@ -121,12 +122,12 @@ class Leaderboard:
return (users13_accs, pos13[0], pos13[1])
@classmethod
def get_downvotes_lb(cls, lb_criteria, v:User, db:scoped_session, users:Any, limit):
def get_downvotes_lb(cls, lb_criteria, v:User, users:Any, limit):
users9 = cache.get("users9") or []
users9_1 = cache.get("users9_1") or []
users9_2 = cache.get("users9_2") or []
users9_accs = db.query(User).filter(User.id.in_(users9_1)).all()
users9_accs = g.db.query(User).filter(User.id.in_(users9_1)).all()
users9_accs = sorted(users9_accs, key=lambda x: users9_1.index(x.id))
users9_accs = tuple(zip(users9_accs, users9_2))
try:

View File

@ -182,8 +182,9 @@ class Post(Base):
if self.thumburl: return self.thumburl
return None
@property
@lazy
def json(self, db:scoped_session):
def json(self):
if self.is_banned:
return {'is_banned': True,
'deleted_utc': self.deleted_utc,
@ -234,7 +235,7 @@ class Post(Base):
}
if "replies" in self.__dict__:
data["replies"]=[x.json(db) for x in self.replies]
data["replies"]=[x.json for x in self.replies]
return data

View File

@ -785,11 +785,6 @@ class User(Base):
def do_reddit(self):
return self.notifications_count == self.reddit_notifications_count
@property
@lazy
def alt_ids(self):
return [x.id for x in self.get_alt_graph(g.db)]
@property
@lazy
def moderated_subs(self):

View File

@ -1,16 +1,17 @@
import time
from flask import g
from files.classes.casino_game import CasinoGame
from files.helpers.alerts import *
from files.helpers.config.const import *
from files.helpers.useractions import badge_grant
def get_game_feed(game, db):
games = db.query(CasinoGame) \
def get_game_feed(game):
games = g.db.query(CasinoGame) \
.filter(CasinoGame.active == False, CasinoGame.kind == game) \
.order_by(CasinoGame.created_utc.desc()).limit(30).all()
def format_game(game):
user = db.query(User).filter(User.id == game.user_id).one()
user = g.db.query(User).filter(User.id == game.user_id).one()
wonlost = 'lost' if game.winnings < 0 else 'won'
relevant_currency = "coin" if game.currency == "coins" else "marseybux"
@ -23,27 +24,27 @@ def get_game_feed(game, db):
return list(map(format_game, games))
def get_user_stats(u:User, game:str, db:scoped_session, include_ties=False):
games = db.query(CasinoGame.user_id, CasinoGame.winnings).filter(CasinoGame.kind == game, CasinoGame.user_id == u.id)
def get_user_stats(u:User, game:str, include_ties=False):
games = g.db.query(CasinoGame.user_id, CasinoGame.winnings).filter(CasinoGame.kind == game, CasinoGame.user_id == u.id)
wins = games.filter(CasinoGame.winnings > 0).count()
ties = games.filter(CasinoGame.winnings == 0).count() if include_ties else 0
losses = games.filter(CasinoGame.winnings < 0).count()
return (wins, ties, losses)
def get_game_leaderboard(game, db:scoped_session):
def get_game_leaderboard(game):
timestamp_24h_ago = time.time() - 86400
timestamp_all_time = CASINO_RELEASE_DAY # "All Time" starts on release day
biggest_win_all_time = db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
biggest_win_all_time = g.db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
CasinoGame).join(User).order_by(CasinoGame.winnings.desc()).filter(CasinoGame.kind == game, CasinoGame.created_utc > timestamp_all_time).limit(1).one_or_none()
biggest_win_last_24h = db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
biggest_win_last_24h = g.db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
CasinoGame).join(User).order_by(CasinoGame.winnings.desc()).filter(CasinoGame.kind == game, CasinoGame.created_utc > timestamp_24h_ago).limit(1).one_or_none()
biggest_loss_all_time = db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
biggest_loss_all_time = g.db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
CasinoGame).join(User).order_by(CasinoGame.winnings.asc()).filter(CasinoGame.kind == game, CasinoGame.created_utc > timestamp_all_time).limit(1).one_or_none()
biggest_loss_last_24h = db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
biggest_loss_last_24h = g.db.query(CasinoGame.user_id, User.username, CasinoGame.currency, CasinoGame.winnings).select_from(
CasinoGame).join(User).order_by(CasinoGame.winnings.asc()).filter(CasinoGame.kind == game, CasinoGame.created_utc > timestamp_24h_ago).limit(1).one_or_none()
if not biggest_win_all_time:

View File

@ -13,11 +13,8 @@ SNAPPY_MARSEYS = []
SNAPPY_QUOTES = []
def const_initialize(db:scoped_session):
_initialize_marseys(db)
_initialize_snappy_marseys_and_quotes()
global marseys_const, marseys_const2, marsey_mappings, SNAPPY_KONGS, SNAPPY_MARSEYS, SNAPPY_QUOTES
def _initialize_marseys(db:scoped_session):
global marseys_const, marseys_const2, marsey_mappings, SNAPPY_KONGS
marseys_const = [x[0] for x in db.query(Emoji.name).filter(Emoji.kind=="Marsey", Emoji.submitter_id==None, Emoji.name!='chudsey').all()]
marseys_const2 = marseys_const + ['chudsey','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark']
marseys = db.query(Emoji).filter(Emoji.kind=="Marsey", Emoji.submitter_id==None).all()
@ -35,10 +32,6 @@ def _initialize_marseys(db:scoped_session):
db.commit()
db.close()
def _initialize_snappy_marseys_and_quotes():
global SNAPPY_MARSEYS, SNAPPY_QUOTES
SNAPPY_MARSEYS = [f':#{x}:' for x in marseys_const2]
if IS_FISTMAS():

View File

@ -32,9 +32,9 @@ def casino_game_page(v:User, game):
elif game not in CASINO_GAME_KINDS:
abort(404)
feed = json.dumps(get_game_feed(game, g.db))
leaderboard = json.dumps(get_game_leaderboard(game, g.db))
v_stats = get_user_stats(v, game, g.db, game == 'blackjack')
feed = json.dumps(get_game_feed(game))
leaderboard = json.dumps(get_game_leaderboard(game))
v_stats = get_user_stats(v, game, game == 'blackjack')
game_state = ''
if game == 'blackjack':
@ -62,7 +62,7 @@ def casino_game_feed(v:User, game):
elif game not in CASINO_GAME_KINDS:
abort(404)
feed = get_game_feed(game, g.db)
feed = get_game_feed(game)
return {"feed": feed}
@ -128,7 +128,7 @@ def blackjack_deal_to_player(v:User):
currency = request.values.get("currency")
create_new_game(v, wager, currency)
state = dispatch_action(v, BlackjackAction.DEAL)
feed = get_game_feed('blackjack', g.db)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "marseybux": v.marseybux}}
except Exception as e:
@ -147,7 +147,7 @@ def blackjack_player_hit(v:User):
try:
state = dispatch_action(v, BlackjackAction.HIT)
feed = get_game_feed('blackjack', g.db)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "marseybux": v.marseybux}}
except:
abort(400, "Unable to hit!")
@ -165,7 +165,7 @@ def blackjack_player_stay(v:User):
try:
state = dispatch_action(v, BlackjackAction.STAY)
feed = get_game_feed('blackjack', g.db)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "marseybux": v.marseybux}}
except:
abort(400, "Unable to stay!")
@ -183,7 +183,7 @@ def blackjack_player_doubled_down(v:User):
try:
state = dispatch_action(v, BlackjackAction.DOUBLE_DOWN)
feed = get_game_feed('blackjack', g.db)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "marseybux": v.marseybux}}
except:
abort(400, "Unable to double down!")
@ -201,7 +201,7 @@ def blackjack_player_bought_insurance(v:User):
try:
state = dispatch_action(v, BlackjackAction.BUY_INSURANCE)
feed = get_game_feed('blackjack', g.db)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "marseybux": v.marseybux}}
except:
abort(403, "Unable to buy insurance!")

View File

@ -74,7 +74,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
execute_shadowban_viewers_and_voters(v, post)
execute_shadowban_viewers_and_voters(v, comment)
if v and v.client: return top_comment.json(db=g.db)
if v and v.client: return top_comment.json
else:
if post.is_banned and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or post.author_id == v.id)): template = "post_banned.html"
else: template = "post.html"
@ -395,7 +395,7 @@ def comment(v:User):
if c.parent_submission:
cache.delete(f'post_{c.parent_submission}')
if v.client: return c.json(db=g.db)
if v.client: return c.json
return {"comment": render_template("comments.html", v=v, comments=[c])}
@app.post("/delete/comment/<int:cid>")

View File

@ -64,7 +64,7 @@ def front_all(v, sub=None, subdomain=None):
if v and v.hidevotedon:
posts = [x for x in posts if not hasattr(x, 'voted') or not x.voted]
if v and v.client: return {"data": [x.json(g.db) for x in posts], "total": total}
if v and v.client: return {"data": [x.json for x in posts], "total": total}
return render_template("home.html", v=v, listing=posts, total=total, sort=sort, t=t, page=page, sub=sub, home=True, pins=pins, size=size)
@ -237,5 +237,5 @@ def all_comments(v:User):
comments = get_comments(idlist, v=v)
if v.client: return {"data": [x.json(g.db) for x in comments]}
if v.client: return {"data": [x.json for x in comments]}
return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, total=total, size = PAGE_SIZE)

View File

@ -50,7 +50,7 @@ def unread(v):
n.read = True
g.db.add(n)
return {"data":[x[1].json(g.db) for x in listing]}
return {"data":[x[1].json for x in listing]}
@app.get("/notifications/modmail")
@ -70,7 +70,7 @@ def notifications_modmail(v):
g.db.flush()
if v.client: return {"data":[x.json(g.db) for x in listing]}
if v.client: return {"data":[x.json for x in listing]}
return render_template("notifications.html",
v=v,
@ -141,7 +141,7 @@ def notifications_messages(v:User):
listing = message_threads.order_by(thread_order.c.created_utc.desc()) \
.offset(PAGE_SIZE*(page-1)).limit(PAGE_SIZE).all()
if v.client: return {"data":[x.json(g.db) for x in listing]}
if v.client: return {"data":[x.json for x in listing]}
return render_template("notifications.html",
v=v,
@ -188,7 +188,7 @@ def notifications_posts(v:User):
v.last_viewed_post_notifs = int(time.time())
g.db.add(v)
if v.client: return {"data":[x.json(g.db) for x in listing]}
if v.client: return {"data":[x.json for x in listing]}
return render_template("notifications.html",
v=v,
@ -272,7 +272,7 @@ def notifications_reddit(v:User):
v.last_viewed_reddit_notifs = int(time.time())
g.db.add(v)
if v.client: return {"data":[x.json(g.db) for x in listing]}
if v.client: return {"data":[x.json for x in listing]}
return render_template("notifications.html",
v=v,
@ -408,7 +408,7 @@ def notifications(v:User):
g.db.flush()
if v.client: return {"data":[x.json(g.db) for x in listing]}
if v.client: return {"data":[x.json for x in listing]}
return render_template("notifications.html",
v=v,

View File

@ -168,7 +168,7 @@ def post_id(pid, anything=None, v=None, sub=None):
p.replies = list(pinned2.keys()) + comments
if v and v.client:
return p.json(g.db)
return p.json
template = "post.html"
if (p.is_banned or p.author.shadowbanned) \
@ -716,7 +716,7 @@ def submit_post(v:User, sub=None):
cache.delete_memoized(userpagelisting)
g.db.flush()
if v.client: return p.json(g.db)
if v.client: return p.json
else:
p.voted = 1
return {"post_id": p.id, "success": True}

View File

@ -169,7 +169,7 @@ def searchposts(v:User):
posts = get_posts(ids, v=v, eager=True)
if v.client: return {"total":total, "data":[x.json(g.db) for x in posts]}
if v.client: return {"total":total, "data":[x.json for x in posts]}
return render_template("search.html",
v=v,
@ -280,7 +280,7 @@ def searchcomments(v:User):
comments = get_comments(ids, v=v)
if v.client: return {"total":total, "data":[x.json(db=g.db) for x in comments]}
if v.client: return {"total":total, "data":[x.json for x in comments]}
return render_template("search_comments.html", v=v, query=query, page=page, comments=comments, sort=sort, t=t, total=total, standalone=True)
@ -372,7 +372,7 @@ def searchmessages(v:User):
comments = dict.fromkeys([x.top_comment for x in comments])
if v.client: return {"total":total, "data":[x.json(db=g.db) for x in comments]}
if v.client: return {"total":total, "data":[x.json for x in comments]}
return render_template("search_comments.html", v=v, query=query, page=page, comments=comments, sort=sort, t=t, total=total, standalone=True, render_replies=True)
@app.get("/search/users")

View File

@ -42,10 +42,10 @@ def reddit_post(subreddit, v, path):
@cache.cached(key_prefix="marseys")
def get_marseys(db:scoped_session):
def get_marseys():
if not FEATURES['MARSEYS']: return []
marseys = []
for marsey, author in db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id == None).order_by(Emoji.count.desc()):
for marsey, author in g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id == None).order_by(Emoji.count.desc()):
marsey.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None
marseys.append(marsey)
return marseys
@ -58,7 +58,7 @@ def marseys(v:User):
if SITE_NAME != 'rDrama':
abort(404)
marseys = get_marseys(g.db)
marseys = get_marseys()
authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True)
original = os.listdir("/asset_submissions/emojis/original")
for marsey in marseys:
@ -394,7 +394,7 @@ def transfers(v:User):
comments = comments.order_by(Comment.id.desc()).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
if v.client:
return {"data": [x.json(g.db) for x in comments]}
return {"data": [x.json for x in comments]}
else:
return render_template("transfers.html", v=v, page=page, comments=comments, standalone=True, total=total)

View File

@ -412,30 +412,30 @@ def transfer_bux(v:User, username:str):
def leaderboard(v:User):
users = g.db.query(User)
coins = Leaderboard("Coins", "coins", "coins", "Coins", None, Leaderboard.get_simple_lb, User.coins, v, lambda u:u.coins, g.db, users)
marseybux = Leaderboard("Marseybux", "marseybux", "marseybux", "Marseybux", None, Leaderboard.get_simple_lb, User.marseybux, v, lambda u:u.marseybux, g.db, users)
subscribers = Leaderboard("Followers", "followers", "followers", "Followers", "followers", Leaderboard.get_simple_lb, User.stored_subscriber_count, v, lambda u:u.stored_subscriber_count, g.db, users)
posts = Leaderboard("Posts", "post count", "posts", "Posts", "posts", Leaderboard.get_simple_lb, User.post_count, v, lambda u:u.post_count, g.db, users)
comments = Leaderboard("Comments", "comment count", "comments", "Comments", "comments", Leaderboard.get_simple_lb, User.comment_count, v, lambda u:u.comment_count, g.db, users)
received_awards = Leaderboard("Received awards", "received awards", "received-awards", "Received Awards", None, Leaderboard.get_simple_lb, User.received_award_count, v, lambda u:u.received_award_count, g.db, users)
coins_spent = Leaderboard("Coins spent on awards", "coins spent on awards", "spent", "Coins", None, Leaderboard.get_simple_lb, User.coins_spent, v, lambda u:u.coins_spent, g.db, users)
truescore = Leaderboard("Truescore", "truescore", "truescore", "Truescore", None, Leaderboard.get_simple_lb, User.truescore, v, lambda u:u.truescore, g.db, users)
coins = Leaderboard("Coins", "coins", "coins", "Coins", None, Leaderboard.get_simple_lb, User.coins, v, lambda u:u.coins, users)
marseybux = Leaderboard("Marseybux", "marseybux", "marseybux", "Marseybux", None, Leaderboard.get_simple_lb, User.marseybux, v, lambda u:u.marseybux, users)
subscribers = Leaderboard("Followers", "followers", "followers", "Followers", "followers", Leaderboard.get_simple_lb, User.stored_subscriber_count, v, lambda u:u.stored_subscriber_count, users)
posts = Leaderboard("Posts", "post count", "posts", "Posts", "posts", Leaderboard.get_simple_lb, User.post_count, v, lambda u:u.post_count, users)
comments = Leaderboard("Comments", "comment count", "comments", "Comments", "comments", Leaderboard.get_simple_lb, User.comment_count, v, lambda u:u.comment_count, users)
received_awards = Leaderboard("Received awards", "received awards", "received-awards", "Received Awards", None, Leaderboard.get_simple_lb, User.received_award_count, v, lambda u:u.received_award_count, users)
coins_spent = Leaderboard("Coins spent on awards", "coins spent on awards", "spent", "Coins", None, Leaderboard.get_simple_lb, User.coins_spent, v, lambda u:u.coins_spent, users)
truescore = Leaderboard("Truescore", "truescore", "truescore", "Truescore", None, Leaderboard.get_simple_lb, User.truescore, v, lambda u:u.truescore, users)
badges = Leaderboard("Badges", "badges", "badges", "Badges", None, Leaderboard.get_badge_marsey_lb, Badge.user_id, v, None, g.db, None)
badges = Leaderboard("Badges", "badges", "badges", "Badges", None, Leaderboard.get_badge_marsey_lb, Badge.user_id, v, None, None)
blocks = Leaderboard("Most blocked", "most blocked", "most-blocked", "Blocked By", "blockers", Leaderboard.get_blockers_lb, UserBlock.target_id, v, None, g.db, None)
blocks = Leaderboard("Most blocked", "most blocked", "most-blocked", "Blocked By", "blockers", Leaderboard.get_blockers_lb, UserBlock.target_id, v, None, None)
owned_hats = Leaderboard("Owned hats", "owned hats", "owned-hats", "Owned Hats", None, Leaderboard.get_hat_lb, User.owned_hats, v, None, g.db, None)
owned_hats = Leaderboard("Owned hats", "owned hats", "owned-hats", "Owned Hats", None, Leaderboard.get_hat_lb, User.owned_hats, v, None, None)
leaderboards = [coins, marseybux, coins_spent, truescore, subscribers, posts, comments, received_awards, badges, blocks, owned_hats]
if SITE == 'rdrama.net':
leaderboards.append(Leaderboard("Designed hats", "designed hats", "designed-hats", "Designed Hats", None, Leaderboard.get_hat_lb, User.designed_hats, v, None, g.db, None))
leaderboards.append(Leaderboard("Marseys made", "Marseys made", "marseys-made", "Marseys", None, Leaderboard.get_badge_marsey_lb, Emoji.author_id, v, None, g.db, None))
leaderboards.append(Leaderboard("Designed hats", "designed hats", "designed-hats", "Designed Hats", None, Leaderboard.get_hat_lb, User.designed_hats, v, None, None))
leaderboards.append(Leaderboard("Marseys made", "Marseys made", "marseys-made", "Marseys", None, Leaderboard.get_badge_marsey_lb, Emoji.author_id, v, None, None))
leaderboards.append(Leaderboard("Upvotes given", "upvotes given", "upvotes-given", "Upvotes Given", "upvoting", Leaderboard.get_upvotes_lb, None, v, None, g.db, None))
leaderboards.append(Leaderboard("Upvotes given", "upvotes given", "upvotes-given", "Upvotes Given", "upvoting", Leaderboard.get_upvotes_lb, None, v, None, None))
leaderboards.append(Leaderboard("Downvotes received", "downvotes received", "downvotes-received", "Downvotes Received", "downvoters", Leaderboard.get_downvotes_lb, None, v, None, g.db, None))
leaderboards.append(Leaderboard("Downvotes received", "downvotes received", "downvotes-received", "Downvotes Received", "downvoters", Leaderboard.get_downvotes_lb, None, v, None, None))
return render_template("leaderboard.html", v=v, leaderboards=leaderboards)
@ -870,7 +870,7 @@ def u_username_wall(v:Optional[User], username:str):
comments = [c[0] for c in comments]
if v and v.client:
return {"data": [c.json(g.db) for c in comments]}
return {"data": [c.json for c in comments]}
return render_template("userpage/wall.html", u=u, v=v, listing=comments, page=page, total=total, is_following=is_following, standalone=True, render_replies=True, wall=True)
@ -919,7 +919,7 @@ def u_username_wall_comment(v:User, username:str, cid):
# props won't save properly unless you put them in a list
output = get_comments_v_properties(v, None, Comment.top_comment_id == c.top_comment_id)[1]
if v and v.client: return top_comment.json(db=g.db)
if v and v.client: return top_comment.json
return render_template("userpage/wall.html", u=u, v=v, listing=[top_comment], page=1, is_following=is_following, standalone=True, render_replies=True, wall=True, comment_info=comment_info, total=1)
@ -968,7 +968,7 @@ def u_username(v:Optional[User], username:str):
if u.unban_utc:
if v and v.client:
return {"data": [x.json(g.db) for x in listing]}
return {"data": [x.json for x in listing]}
return render_template("userpage/posts.html",
unban=u.unban_string,
@ -982,7 +982,7 @@ def u_username(v:Optional[User], username:str):
is_following=is_following)
if v and v.client:
return {"data": [x.json(g.db) for x in listing]}
return {"data": [x.json for x in listing]}
return render_template("userpage/posts.html",
u=u,
@ -1054,7 +1054,7 @@ def u_username_comments(username, v=None):
listing = get_comments(ids, v=v)
if v and v.client:
return {"data": [c.json(g.db) for c in listing]}
return {"data": [c.json for c in listing]}
return render_template("userpage/comments.html", u=u, v=v, listing=listing, page=page, sort=sort, t=t,total=total, is_following=is_following, standalone=True)
@ -1217,7 +1217,7 @@ def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone
else:
raise TypeError("Only supports Posts and Comments. This is probably the result of a bug with *this* function")
if v.client: return {"data": [x.json(g.db) for x in listing]}
if v.client: return {"data": [x.json for x in listing]}
return render_template(template, u=v, v=v, listing=listing, page=page, total=total, standalone=standalone)
@app.get("/@<username>/saved/posts")

View File

@ -76,7 +76,7 @@
{% if SITE == 'rdrama.net' %}
<td>{% include "user_in_table.html" %}</td>
{% endif %}
<td><a href="/hat_owners/{{hat.id}}">{{hat.number_sold(g.db)}}</a></td>
<td><a href="/hat_owners/{{hat.id}}">{{hat.number_sold}}</a></td>
<td>{{hat.price}}</td>
<td class="shop-table-actions" style="width:unset">
{% if hat.id not in owned_hat_ids and hat.is_purchasable %}