use sets instead of lists in some statements
parent
93058079eb
commit
0aaa210e1c
|
@ -243,7 +243,7 @@ class Comment(Base):
|
||||||
|
|
||||||
@lazy
|
@lazy
|
||||||
def realbody(self, v):
|
def realbody(self, v):
|
||||||
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))):
|
if self.post and self.post.club and not (v and (v.paid_dues or v.id in {self.author_id, self.post.author_id} or (self.parent_comment and v.id == self.parent_comment.author_id))):
|
||||||
return f"<p>{CC} ONLY</p>"
|
return f"<p>{CC} ONLY</p>"
|
||||||
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
|
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
|
||||||
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
|
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
|
||||||
|
@ -298,7 +298,7 @@ class Comment(Base):
|
||||||
|
|
||||||
@lazy
|
@lazy
|
||||||
def plainbody(self, v):
|
def plainbody(self, v):
|
||||||
if self.post and self.post.club and not (v and (v.paid_dues or v.id in [self.author_id, self.post.author_id] or (self.parent_comment and v.id == self.parent_comment.author_id))):
|
if self.post and self.post.club and not (v and (v.paid_dues or v.id in {self.author_id, self.post.author_id} or (self.parent_comment and v.id == self.parent_comment.author_id))):
|
||||||
return f"{CC} ONLY"
|
return f"{CC} ONLY"
|
||||||
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
|
if self.deleted_utc != 0 and not (v and (v.admin_level >= PERMS['POST_COMMENT_MODERATION'] or v.id == self.author.id)): return "[Deleted by user]"
|
||||||
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
|
if self.is_banned and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == self.author.id): return ""
|
||||||
|
|
|
@ -875,7 +875,7 @@ class User(Base):
|
||||||
|
|
||||||
def get_relationship_count(self, relationship_cls):
|
def get_relationship_count(self, relationship_cls):
|
||||||
# TODO: deduplicate (see routes/users.py)
|
# TODO: deduplicate (see routes/users.py)
|
||||||
if relationship_cls in [SaveRelationship, Subscription]:
|
if relationship_cls in {SaveRelationship, Subscription}:
|
||||||
query = relationship_cls.submission_id
|
query = relationship_cls.submission_id
|
||||||
join = relationship_cls.post
|
join = relationship_cls.post
|
||||||
cls = Submission
|
cls = Submission
|
||||||
|
|
|
@ -228,7 +228,7 @@ def add_block_props(target:Union[Submission, Comment, User], v:Optional[User]):
|
||||||
if not v: return target
|
if not v: return target
|
||||||
id = None
|
id = None
|
||||||
|
|
||||||
if any(isinstance(target, cls) for cls in [Submission, Comment]):
|
if any(isinstance(target, cls) for cls in {Submission, Comment}):
|
||||||
id = target.author_id
|
id = target.author_id
|
||||||
elif isinstance(target, User):
|
elif isinstance(target, User):
|
||||||
id = target.id
|
id = target.id
|
||||||
|
|
|
@ -52,7 +52,7 @@ def allowed_attributes(tag, name, value):
|
||||||
if name == 'style': return True
|
if name == 'style': return True
|
||||||
|
|
||||||
if tag == 'marquee':
|
if tag == 'marquee':
|
||||||
if name in ['direction', 'behavior', 'scrollamount']: return True
|
if name in {'direction', 'behavior', 'scrollamount'}: return True
|
||||||
if name in {'height', 'width'}:
|
if name in {'height', 'width'}:
|
||||||
try: value = int(value.replace('px', ''))
|
try: value = int(value.replace('px', ''))
|
||||||
except: return False
|
except: return False
|
||||||
|
@ -67,11 +67,11 @@ def allowed_attributes(tag, name, value):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if tag == 'img':
|
if tag == 'img':
|
||||||
if name in ['src','data-src']: return is_safe_url(value)
|
if name in {'src','data-src'}: return is_safe_url(value)
|
||||||
if name == 'loading' and value == 'lazy': return True
|
if name == 'loading' and value == 'lazy': return True
|
||||||
if name == 'data-bs-toggle' and value == 'tooltip': return True
|
if name == 'data-bs-toggle' and value == 'tooltip': return True
|
||||||
if name in ['g','b','glow'] and not value: return True
|
if name in {'g','b','glow'} and not value: return True
|
||||||
if name in ['alt','title']: return True
|
if name in {'alt','title'}: return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if tag == 'lite-youtube':
|
if tag == 'lite-youtube':
|
||||||
|
@ -426,8 +426,8 @@ def allowed_attributes_emojis(tag, name, value):
|
||||||
if name == 'src' and value.startswith('/') and '\\' not in value: return True
|
if name == 'src' and value.startswith('/') and '\\' not in value: return True
|
||||||
if name == 'loading' and value == 'lazy': return True
|
if name == 'loading' and value == 'lazy': return True
|
||||||
if name == 'data-bs-toggle' and value == 'tooltip': return True
|
if name == 'data-bs-toggle' and value == 'tooltip': return True
|
||||||
if name in ['g','glow'] and not value: return True
|
if name in {'g','glow'} and not value: return True
|
||||||
if name in ['alt','title']: return True
|
if name in {'alt','title'}: return True
|
||||||
|
|
||||||
if tag == 'span':
|
if tag == 'span':
|
||||||
if name == 'data-bs-toggle' and value == 'tooltip': return True
|
if name == 'data-bs-toggle' and value == 'tooltip': return True
|
||||||
|
|
|
@ -392,7 +392,7 @@ def edit_post(pid, v):
|
||||||
|
|
||||||
p.body = body
|
p.body = body
|
||||||
|
|
||||||
for text in [p.body, p.title, p.url]:
|
for text in {p.body, p.title, p.url}:
|
||||||
if not execute_blackjack(v, p, text, 'submission'): break
|
if not execute_blackjack(v, p, text, 'submission'): break
|
||||||
|
|
||||||
if len(body_html) > POST_BODY_HTML_LENGTH_LIMIT:
|
if len(body_html) > POST_BODY_HTML_LENGTH_LIMIT:
|
||||||
|
@ -810,7 +810,7 @@ def submit_post(v, sub=None):
|
||||||
g.db.add(post)
|
g.db.add(post)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
for text in [post.body, post.title, post.url]:
|
for text in {post.body, post.title, post.url}:
|
||||||
if not execute_blackjack(v, post, text, 'submission'): break
|
if not execute_blackjack(v, post, text, 'submission'): break
|
||||||
|
|
||||||
if v and v.admin_level >= PERMS['POST_BETS']:
|
if v and v.admin_level >= PERMS['POST_BETS']:
|
||||||
|
|
|
@ -933,7 +933,7 @@ def user_profile_name(username):
|
||||||
return redirect(x.profile_url)
|
return redirect(x.profile_url)
|
||||||
|
|
||||||
def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone=False):
|
def get_saves_and_subscribes(v, template, relationship_cls, page:int, standalone=False):
|
||||||
if relationship_cls in [SaveRelationship, Subscription]:
|
if relationship_cls in {SaveRelationship, Subscription}:
|
||||||
query = relationship_cls.submission_id
|
query = relationship_cls.submission_id
|
||||||
join = relationship_cls.post
|
join = relationship_cls.post
|
||||||
cls = Submission
|
cls = Submission
|
||||||
|
|
|
@ -42,7 +42,7 @@ def vote_info_get(v, link):
|
||||||
|
|
||||||
def vote_post_comment(target_id, new, v, cls, vote_cls):
|
def vote_post_comment(target_id, new, v, cls, vote_cls):
|
||||||
if new == "-1" and DISABLE_DOWNVOTES: abort(403)
|
if new == "-1" and DISABLE_DOWNVOTES: abort(403)
|
||||||
if new not in ["-1", "0", "1"]: abort(400)
|
if new not in {"-1", "0", "1"}: abort(400)
|
||||||
if v.client and v.id not in PRIVILEGED_USER_BOTS: abort(403)
|
if v.client and v.id not in PRIVILEGED_USER_BOTS: abort(403)
|
||||||
new = int(new)
|
new = int(new)
|
||||||
target = None
|
target = None
|
||||||
|
|
Loading…
Reference in New Issue