2022-11-15 09:19:08 +00:00
|
|
|
|
|
|
|
from flask import *
|
|
|
|
from sqlalchemy import and_, any_, or_
|
2023-08-05 16:03:14 +00:00
|
|
|
from sqlalchemy.orm import joinedload, Query, load_only
|
2022-11-15 09:19:08 +00:00
|
|
|
|
2023-10-07 17:55:50 +00:00
|
|
|
from files.classes import Comment, CommentVote, Hat, Hole, Post, User, UserBlock, Vote
|
2023-03-12 13:03:58 +00:00
|
|
|
from files.helpers.config.const import *
|
2023-01-25 03:18:17 +00:00
|
|
|
from files.__main__ import cache
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-09-26 22:12:01 +00:00
|
|
|
# Escape SQL pattern-matching special characters
|
|
|
|
def escape_for_search(string):
|
|
|
|
return string.replace('\\', '').replace('_', '\_').replace('%', '\%').strip()
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def sanitize_username(username):
|
2023-09-26 22:12:01 +00:00
|
|
|
username = username.lstrip('@').replace('(', '').replace(')', '')
|
|
|
|
username = escape_for_search(username)
|
|
|
|
return username
|
2022-10-28 02:39:57 +00:00
|
|
|
|
2023-09-07 16:16:13 +00:00
|
|
|
def get_user(username, v=None, graceful=False, include_blocks=False, attributes=None):
|
2022-05-04 23:09:46 +00:00
|
|
|
if not username:
|
2022-10-28 00:55:05 +00:00
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(400, "Empty username.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-10-16 18:09:35 +00:00
|
|
|
search_name = sanitize_username(username)
|
|
|
|
if not search_name:
|
2022-10-28 00:55:05 +00:00
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(400, "Empty username.")
|
2023-09-07 16:16:13 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
user = g.db.query(
|
2022-05-04 23:09:46 +00:00
|
|
|
User
|
|
|
|
).filter(
|
|
|
|
or_(
|
2023-10-16 18:09:35 +00:00
|
|
|
User.username.ilike(search_name),
|
|
|
|
User.original_username.ilike(search_name),
|
2023-11-25 21:57:15 +00:00
|
|
|
User.extra_username.ilike(search_name),
|
2023-10-16 18:09:35 +00:00
|
|
|
User.prelock_username.ilike(search_name),
|
2022-05-04 23:09:46 +00:00
|
|
|
)
|
2022-07-03 11:56:40 +00:00
|
|
|
)
|
|
|
|
|
2023-09-07 16:16:13 +00:00
|
|
|
if attributes:
|
|
|
|
user = user.options(load_only(*attributes))
|
2023-08-05 16:03:14 +00:00
|
|
|
|
2022-07-03 11:56:40 +00:00
|
|
|
user = user.one_or_none()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-02-27 15:38:12 +00:00
|
|
|
if not user:
|
2022-10-28 00:55:05 +00:00
|
|
|
if graceful: return None
|
2023-09-06 18:13:32 +00:00
|
|
|
abort(404, f"A user with the name '{username}' was not found!")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-11-02 20:22:23 +00:00
|
|
|
if v and include_blocks:
|
2022-10-28 01:16:36 +00:00
|
|
|
user = add_block_props(user, v)
|
2022-05-04 23:09:46 +00:00
|
|
|
return user
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_users(usernames, ids_only=False, graceful=False):
|
2022-10-28 02:28:55 +00:00
|
|
|
if not usernames: return []
|
2022-10-28 02:39:57 +00:00
|
|
|
usernames = [sanitize_username(n) for n in usernames]
|
2022-10-28 00:55:05 +00:00
|
|
|
if not any(usernames):
|
|
|
|
if graceful and len(usernames) == 0: return []
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(400, "Empty usernames.")
|
2023-03-01 20:28:34 +00:00
|
|
|
|
|
|
|
if ids_only:
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User.id)
|
2023-03-01 20:28:34 +00:00
|
|
|
else:
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User)
|
2023-03-01 20:28:34 +00:00
|
|
|
|
|
|
|
users = users.filter(
|
2022-06-17 20:37:27 +00:00
|
|
|
or_(
|
2022-06-17 22:03:23 +00:00
|
|
|
User.username.ilike(any_(usernames)),
|
2023-05-13 04:53:14 +00:00
|
|
|
User.original_username.ilike(any_(usernames)),
|
2023-11-25 21:57:15 +00:00
|
|
|
User.extra_username.ilike(any_(usernames)),
|
2023-05-13 04:53:14 +00:00
|
|
|
User.prelock_username.ilike(any_(usernames)),
|
2023-11-25 21:57:15 +00:00
|
|
|
)
|
2022-06-17 20:37:27 +00:00
|
|
|
).all()
|
|
|
|
|
2022-08-21 19:54:55 +00:00
|
|
|
if len(users) != len(usernames) and not graceful:
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(404, "Users not found.")
|
2022-06-17 20:37:27 +00:00
|
|
|
|
2023-03-01 20:28:34 +00:00
|
|
|
if ids_only:
|
|
|
|
users = [x[0] for x in users]
|
|
|
|
|
2022-06-17 20:37:27 +00:00
|
|
|
return users
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_account(id, v=None, graceful=False, include_blocks=False):
|
2023-01-01 11:36:20 +00:00
|
|
|
try:
|
2022-09-30 21:00:58 +00:00
|
|
|
id = int(id)
|
|
|
|
except:
|
2022-10-28 00:55:05 +00:00
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(400, "User ID needs to be an integer.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
user = g.db.get(User, id)
|
2022-09-12 07:17:57 +00:00
|
|
|
|
2023-02-27 15:38:12 +00:00
|
|
|
if not user:
|
2023-08-23 10:08:02 +00:00
|
|
|
if not graceful: abort(404, "User not found.")
|
2022-09-12 07:17:57 +00:00
|
|
|
else: return None
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-10-28 01:16:36 +00:00
|
|
|
if include_blocks:
|
|
|
|
user = add_block_props(user, v)
|
2022-05-04 23:09:46 +00:00
|
|
|
return user
|
|
|
|
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_accounts_dict(ids, v=None, graceful=False):
|
2022-11-27 16:59:36 +00:00
|
|
|
if not ids: return {}
|
2023-01-01 11:36:20 +00:00
|
|
|
try:
|
2024-02-15 23:12:53 +00:00
|
|
|
ids = set(int(id) for id in ids)
|
2022-11-27 16:59:36 +00:00
|
|
|
except:
|
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(400, "User IDs need to be an integer.")
|
2022-11-27 16:59:36 +00:00
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
users = g.db.query(User).filter(User.id.in_(ids))
|
2022-11-27 16:59:36 +00:00
|
|
|
users = users.all()
|
2023-08-23 10:08:02 +00:00
|
|
|
if len(users) != len(ids) and not graceful:
|
|
|
|
abort(404, "Users not found.")
|
|
|
|
|
2022-11-27 16:59:36 +00:00
|
|
|
return {u.id:u for u in users}
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_post(i, v=None, graceful=False):
|
2022-07-01 23:11:48 +00:00
|
|
|
try: i = int(i)
|
2022-10-28 00:55:05 +00:00
|
|
|
except:
|
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
else: abort(400, "Post ID needs to be an integer.")
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2022-06-24 13:19:53 +00:00
|
|
|
if not i:
|
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
else: abort(400, "Empty post ID.")
|
2022-06-24 13:19:53 +00:00
|
|
|
|
2022-05-04 23:09:46 +00:00
|
|
|
if v:
|
2023-06-07 23:26:32 +00:00
|
|
|
vt = g.db.query(Vote).filter_by(user_id=v.id, post_id=i).subquery()
|
2022-05-04 23:09:46 +00:00
|
|
|
blocking = v.blocking.subquery()
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
post = g.db.query(
|
2023-06-07 23:26:32 +00:00
|
|
|
Post,
|
2022-05-04 23:09:46 +00:00
|
|
|
vt.c.vote_type,
|
|
|
|
blocking.c.target_id,
|
|
|
|
)
|
|
|
|
|
2023-10-29 14:30:30 +00:00
|
|
|
post = post.filter(Post.id == i
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2023-01-01 11:36:20 +00:00
|
|
|
vt,
|
2023-06-07 23:26:32 +00:00
|
|
|
vt.c.post_id == Post.id,
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2023-01-01 11:36:20 +00:00
|
|
|
blocking,
|
2023-06-07 23:26:32 +00:00
|
|
|
blocking.c.target_id == Post.author_id,
|
2022-05-04 23:09:46 +00:00
|
|
|
)
|
|
|
|
|
2023-10-29 14:30:30 +00:00
|
|
|
post = post.one_or_none()
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-06-24 13:19:53 +00:00
|
|
|
if not post:
|
2022-05-04 23:09:46 +00:00
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
else: abort(404, "Post not found.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-06-24 13:19:53 +00:00
|
|
|
x = post[0]
|
|
|
|
x.voted = post[1] or 0
|
|
|
|
x.is_blocking = post[2] or 0
|
2022-05-04 23:09:46 +00:00
|
|
|
else:
|
2023-06-07 23:26:32 +00:00
|
|
|
post = g.db.get(Post, i)
|
2022-06-24 13:19:53 +00:00
|
|
|
if not post:
|
2022-05-04 23:09:46 +00:00
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
else: abort(404, "Post not found.")
|
2022-06-24 13:19:53 +00:00
|
|
|
x=post
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_posts(pids, v=None, extra=None):
|
2022-10-28 02:28:55 +00:00
|
|
|
if not pids: return []
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
if v:
|
2023-06-07 23:26:32 +00:00
|
|
|
vt = g.db.query(Vote.vote_type, Vote.post_id).filter(
|
|
|
|
Vote.post_id.in_(pids),
|
2022-05-04 23:09:46 +00:00
|
|
|
Vote.user_id==v.id
|
|
|
|
).subquery()
|
|
|
|
|
|
|
|
blocking = v.blocking.subquery()
|
|
|
|
blocked = v.blocked.subquery()
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
query = g.db.query(
|
2023-06-07 23:26:32 +00:00
|
|
|
Post,
|
2022-05-04 23:09:46 +00:00
|
|
|
vt.c.vote_type,
|
|
|
|
blocking.c.target_id,
|
|
|
|
blocked.c.target_id,
|
|
|
|
).filter(
|
2023-06-07 23:26:32 +00:00
|
|
|
Post.id.in_(pids)
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2023-06-07 23:26:32 +00:00
|
|
|
vt, vt.c.post_id==Post.id
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2023-01-01 11:36:20 +00:00
|
|
|
blocking,
|
2023-06-07 23:26:32 +00:00
|
|
|
blocking.c.target_id == Post.author_id,
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2023-01-01 11:36:20 +00:00
|
|
|
blocked,
|
2023-06-07 23:26:32 +00:00
|
|
|
blocked.c.user_id == Post.author_id,
|
2022-11-09 14:16:22 +00:00
|
|
|
)
|
|
|
|
else:
|
2023-06-07 23:26:32 +00:00
|
|
|
query = g.db.query(Post).filter(Post.id.in_(pids))
|
2022-11-09 14:16:22 +00:00
|
|
|
|
2022-11-25 21:43:35 +00:00
|
|
|
if extra: query = extra(query)
|
|
|
|
|
2022-11-09 14:16:22 +00:00
|
|
|
results = query.all()
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-11-09 14:16:22 +00:00
|
|
|
if v:
|
|
|
|
output = [p[0] for p in results]
|
2022-05-04 23:09:46 +00:00
|
|
|
for i in range(len(output)):
|
2022-11-09 14:16:22 +00:00
|
|
|
output[i].voted = results[i][1] or 0
|
|
|
|
output[i].is_blocking = results[i][2] or 0
|
|
|
|
output[i].is_blocked = results[i][3] or 0
|
2022-05-04 23:09:46 +00:00
|
|
|
else:
|
2022-11-09 14:16:22 +00:00
|
|
|
output = results
|
2022-05-04 23:09:46 +00:00
|
|
|
|
|
|
|
return sorted(output, key=lambda x: pids.index(x.id))
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_comment(i, v=None, graceful=False):
|
2022-07-01 23:11:48 +00:00
|
|
|
try: i = int(i)
|
2022-10-28 00:55:05 +00:00
|
|
|
except:
|
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
abort(404, "Comment ID needs to be an integer.")
|
2022-07-01 23:11:48 +00:00
|
|
|
|
2022-06-24 13:19:53 +00:00
|
|
|
if not i:
|
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
else: abort(404, "Empty comment ID.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-08-23 21:57:39 +00:00
|
|
|
comment = g.db.get(Comment, i)
|
2022-06-24 13:19:53 +00:00
|
|
|
if not comment:
|
|
|
|
if graceful: return None
|
2023-08-23 10:08:02 +00:00
|
|
|
else: abort(404, "Comment not found.")
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2022-10-28 01:16:36 +00:00
|
|
|
return add_vote_and_block_props(comment, v, CommentVote)
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def add_block_props(target, v):
|
2022-10-28 23:39:31 +00:00
|
|
|
if not v: return target
|
|
|
|
id = None
|
|
|
|
|
2023-06-07 23:26:32 +00:00
|
|
|
if any(isinstance(target, cls) for cls in {Post, Comment}):
|
2022-10-28 23:39:31 +00:00
|
|
|
id = target.author_id
|
|
|
|
elif isinstance(target, User):
|
|
|
|
id = target.id
|
|
|
|
else:
|
2023-06-07 23:26:32 +00:00
|
|
|
raise TypeError("add_block_props only supports non-None posts, comments, and users")
|
2023-01-01 11:36:20 +00:00
|
|
|
|
2022-10-28 23:39:31 +00:00
|
|
|
if hasattr(target, 'is_blocking') and hasattr(target, 'is_blocked'):
|
|
|
|
return target
|
|
|
|
|
|
|
|
if v.id == id or id == AUTOJANNY_ID: # users can't block or be blocked by themselves or AutoJanny
|
|
|
|
target.is_blocking = False
|
|
|
|
target.is_blocked = False
|
|
|
|
return target
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
block = g.db.query(UserBlock).filter(
|
2022-10-28 23:39:31 +00:00
|
|
|
or_(
|
|
|
|
and_(
|
|
|
|
UserBlock.user_id == v.id,
|
|
|
|
UserBlock.target_id == id
|
|
|
|
),
|
|
|
|
and_(
|
|
|
|
UserBlock.user_id == id,
|
|
|
|
UserBlock.target_id == v.id
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).first()
|
|
|
|
target.is_blocking = block and block.user_id == v.id
|
|
|
|
target.is_blocked = block and block.target_id == v.id
|
|
|
|
return target
|
2022-10-28 01:16:36 +00:00
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def add_vote_props(target, v, vote_cls):
|
2022-10-28 23:39:31 +00:00
|
|
|
if hasattr(target, 'voted'): return target
|
|
|
|
|
2023-03-16 06:27:58 +00:00
|
|
|
vt = g.db.query(vote_cls.vote_type).filter_by(user_id=v.id)
|
2022-10-28 23:39:31 +00:00
|
|
|
if vote_cls == Vote:
|
2023-06-07 23:26:32 +00:00
|
|
|
vt = vt.filter_by(post_id=target.id)
|
2022-10-28 23:39:31 +00:00
|
|
|
elif vote_cls == CommentVote:
|
|
|
|
vt = vt.filter_by(comment_id=target.id)
|
|
|
|
else:
|
|
|
|
vt = None
|
|
|
|
if vt: vt = vt.one_or_none()
|
|
|
|
target.voted = vt.vote_type if vt else 0
|
|
|
|
return target
|
2022-10-28 01:16:36 +00:00
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def add_vote_and_block_props(target, v, vote_cls):
|
2022-10-28 23:39:31 +00:00
|
|
|
if not v: return target
|
|
|
|
target = add_block_props(target, v)
|
|
|
|
return add_vote_props(target, v, vote_cls)
|
2022-05-04 23:09:46 +00:00
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_comments(cids, v=None, extra=None):
|
2022-05-04 23:09:46 +00:00
|
|
|
if not cids: return []
|
|
|
|
if v:
|
2023-02-27 16:16:12 +00:00
|
|
|
output = get_comments_v_properties(v, None, Comment.id.in_(cids))[1]
|
2022-05-04 23:09:46 +00:00
|
|
|
else:
|
2023-03-16 06:27:58 +00:00
|
|
|
output = g.db.query(Comment).join(Comment.author)
|
2022-11-25 21:43:35 +00:00
|
|
|
if extra: output = extra(output)
|
2023-02-27 15:38:12 +00:00
|
|
|
output = output.filter(Comment.id.in_(cids)).all()
|
2022-05-04 23:09:46 +00:00
|
|
|
return sorted(output, key=lambda x: cids.index(x.id))
|
|
|
|
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_comments_v_properties(v, should_keep_func=None, *criterion):
|
2022-10-29 00:13:37 +00:00
|
|
|
if not v:
|
|
|
|
raise TypeError("A user is required")
|
2023-03-16 06:27:58 +00:00
|
|
|
votes = g.db.query(CommentVote.vote_type, CommentVote.comment_id).filter_by(user_id=v.id).subquery()
|
2022-10-29 00:13:37 +00:00
|
|
|
blocking = v.blocking.subquery()
|
|
|
|
blocked = v.blocked.subquery()
|
2023-03-16 06:27:58 +00:00
|
|
|
comments = g.db.query(
|
2022-10-29 00:13:37 +00:00
|
|
|
Comment,
|
|
|
|
votes.c.vote_type,
|
|
|
|
blocking.c.target_id,
|
|
|
|
blocked.c.target_id,
|
|
|
|
)
|
|
|
|
|
|
|
|
comments = comments.filter(*criterion)
|
2022-12-07 16:51:51 +00:00
|
|
|
comments = comments.outerjoin(
|
2022-10-29 00:13:37 +00:00
|
|
|
votes,
|
|
|
|
votes.c.comment_id == Comment.id,
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2022-10-29 00:13:37 +00:00
|
|
|
blocking,
|
|
|
|
blocking.c.target_id == Comment.author_id,
|
2022-12-07 16:51:51 +00:00
|
|
|
).outerjoin(
|
2022-10-29 00:13:37 +00:00
|
|
|
blocked,
|
|
|
|
blocked.c.user_id == Comment.author_id,
|
|
|
|
)
|
|
|
|
queried = comments.all()
|
|
|
|
output = []
|
|
|
|
dump = []
|
|
|
|
for c in queried:
|
|
|
|
comment = c[0]
|
|
|
|
comment.voted = c[1] or 0
|
|
|
|
comment.is_blocking = c[2] or 0
|
|
|
|
comment.is_blocked = c[3] or 0
|
|
|
|
if not should_keep_func or should_keep_func(c[0]): output.append(comment)
|
|
|
|
else: dump.append(comment)
|
|
|
|
return (comments, output)
|
|
|
|
|
2024-03-06 03:12:36 +00:00
|
|
|
def get_hole(hole_name, v=None, graceful=False):
|
|
|
|
if not hole_name:
|
2022-10-05 10:30:44 +00:00
|
|
|
if graceful: return None
|
2024-03-06 03:12:36 +00:00
|
|
|
else: abort(404, f"/h/{hole_name} was not found.")
|
|
|
|
hole_name = hole_name.replace('/h/', '').replace('h/', '').strip().lower()
|
|
|
|
if not hole_name:
|
2022-10-05 10:30:44 +00:00
|
|
|
if graceful: return None
|
2024-03-06 03:12:36 +00:00
|
|
|
else: abort(404, f"/h/{hole_name} was not found.")
|
|
|
|
hole = g.db.get(Hole, hole_name)
|
2023-10-07 17:55:50 +00:00
|
|
|
if not hole:
|
2022-10-05 10:30:44 +00:00
|
|
|
if graceful: return None
|
2024-03-06 03:12:36 +00:00
|
|
|
else: abort(404, f"/h/{hole_name} was not found.")
|
2023-10-07 18:05:52 +00:00
|
|
|
return hole
|
2023-01-25 03:18:17 +00:00
|
|
|
|
2023-02-27 01:25:43 +00:00
|
|
|
@cache.memoize(timeout=3600)
|
2023-07-30 00:42:06 +00:00
|
|
|
def get_profile_picture(identifier):
|
2023-01-25 03:18:17 +00:00
|
|
|
if isinstance(identifier, int):
|
|
|
|
x = get_account(identifier, graceful=True)
|
|
|
|
else:
|
|
|
|
x = get_user(identifier, graceful=True)
|
|
|
|
|
|
|
|
return x.profile_url if x else 'not_found'
|
2023-01-27 09:41:32 +00:00
|
|
|
|
2023-09-17 20:14:41 +00:00
|
|
|
def get_msg():
|
|
|
|
if request.referrer and request.referrer.split('?')[0] == request.base_url:
|
|
|
|
return request.values.get("msg")
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2023-01-27 11:19:56 +00:00
|
|
|
def get_error():
|
2023-07-14 12:07:21 +00:00
|
|
|
if request.referrer and request.referrer.split('?')[0] == request.base_url:
|
|
|
|
return request.values.get("error")
|
|
|
|
else:
|
|
|
|
return None
|
2023-01-27 09:41:32 +00:00
|
|
|
|
2023-05-05 05:23:59 +00:00
|
|
|
def get_page():
|
|
|
|
try: return max(int(request.values.get("page", 1)), 1)
|
|
|
|
except: return 1
|
2023-11-04 21:28:44 +00:00
|
|
|
|
|
|
|
def get_obj_hole(obj):
|
|
|
|
if isinstance(obj, Comment):
|
|
|
|
if obj.parent_post:
|
|
|
|
obj.hole = g.db.query(Post.hole).filter_by(id=obj.parent_post).one()[0]
|
|
|
|
else:
|
|
|
|
obj.hole = None
|
|
|
|
return obj.hole
|