remotes/1693045480750635534/spooky-22
Aevann1 2021-10-05 21:15:48 +02:00
parent ee9774042f
commit a5ce637b50
4 changed files with 14 additions and 16 deletions

View File

@ -131,7 +131,4 @@ def after_request(response):
return response return response
from files.routes import * from files.routes import *
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()]

View File

@ -5,13 +5,14 @@ from sqlalchemy import *
from sqlalchemy.orm import relationship, deferred from sqlalchemy.orm import relationship, deferred
from files.helpers.lazy import lazy from files.helpers.lazy import lazy
from files.helpers.const import SLURS from files.helpers.const import SLURS
from files.__main__ import Base, shadowbanned from files.__main__ import Base
from .flags import CommentFlag from .flags import CommentFlag
from os import environ from os import environ
import time import time
site = environ.get("DOMAIN").strip() site = environ.get("DOMAIN").strip()
class Comment(Base): class Comment(Base):
__tablename__ = "comments" __tablename__ = "comments"
@ -356,12 +357,12 @@ class Comment(Base):
@property @property
@lazy @lazy
def active_flags(self): return self.ordered_flags.count() def active_flags(self): return self.flags.count()
@property @property
@lazy @lazy
def ordered_flags(self): def ordered_flags(self): return self.flags.order_by(CommentFlag.id).all()
return self.flags.filter(CommentFlag.user_id.notin_(shadowbanned)).order_by(CommentFlag.id).all()
class Notification(Base): class Notification(Base):

View File

@ -1,18 +1,19 @@
from flask import render_template from flask import render_template, g
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import relationship, deferred from sqlalchemy.orm import relationship, deferred
import re, random import re, random
from urllib.parse import urlparse from urllib.parse import urlparse
from files.helpers.lazy import lazy from files.helpers.lazy import lazy
from files.helpers.const import SLURS from files.helpers.const import SLURS
from files.__main__ import Base, shadowbanned from files.__main__ import Base
from .flags import Flag from .flags import *
from os import environ from os import environ
import time import time
site = environ.get("DOMAIN").strip() site = environ.get("DOMAIN").strip()
site_name = environ.get("SITE_NAME").strip() site_name = environ.get("SITE_NAME").strip()
class Submission(Base): class Submission(Base):
__tablename__ = "submissions" __tablename__ = "submissions"
@ -388,12 +389,11 @@ class Submission(Base):
@property @property
@lazy @lazy
def active_flags(self): return self.ordered_flags.count() def active_flags(self): return self.flags.count()
@property @property
@lazy @lazy
def ordered_flags(self): def ordered_flags(self): return self.flags.order_by(Flag.id).all()
return self.flags.filter(Flag.user_id.notin_(shadowbanned)).order_by(Flag.id).all()
class SaveRelationship(Base): class SaveRelationship(Base):

View File

@ -10,7 +10,7 @@ def api_flag_post(pid, v):
post = get_post(pid) post = get_post(pid)
if v: if v and not v.shadowbanned:
existing = g.db.query(Flag).options(lazyload('*')).filter_by(user_id=v.id, post_id=post.id).first() existing = g.db.query(Flag).options(lazyload('*')).filter_by(user_id=v.id, post_id=post.id).first()
if existing: return "", 409 if existing: return "", 409
@ -41,7 +41,7 @@ def api_flag_comment(cid, v):
comment = get_comment(cid) comment = get_comment(cid)
if v: if v and not v.shadowbanned:
existing = g.db.query(CommentFlag).options(lazyload('*')).filter_by( existing = g.db.query(CommentFlag).options(lazyload('*')).filter_by(
user_id=v.id, comment_id=comment.id).first() user_id=v.id, comment_id=comment.id).first()