forked from MarseyWorld/MarseyWorld
master
parent
d6bbdd7c8b
commit
0c9816c185
|
@ -13,27 +13,12 @@ import time
|
|||
site = environ.get("DOMAIN").strip()
|
||||
site_name = environ.get("SITE_NAME").strip()
|
||||
|
||||
class SubmissionAux(Base):
|
||||
|
||||
__tablename__ = "submissions_aux"
|
||||
|
||||
key_id = Column(BigInteger, primary_key=True)
|
||||
id = Column(BigInteger, ForeignKey("submissions.id"))
|
||||
title = Column(String(500))
|
||||
title_html = Column(String(500))
|
||||
url = Column(String(500))
|
||||
body = deferred(Column(String(10000)))
|
||||
body_html = deferred(Column(String(20000)))
|
||||
ban_reason = Column(String(128))
|
||||
embed_url = Column(String(256))
|
||||
|
||||
|
||||
class Submission(Base):
|
||||
|
||||
__tablename__ = "submissions"
|
||||
|
||||
id = Column(BigInteger, primary_key=True)
|
||||
submission_aux = relationship("SubmissionAux", uselist=False, primaryjoin="Submission.id==SubmissionAux.id")
|
||||
author_id = Column(BigInteger, ForeignKey("users.id"))
|
||||
edited_utc = Column(BigInteger, default=0)
|
||||
created_utc = Column(BigInteger, default=0)
|
||||
|
@ -57,15 +42,19 @@ class Submission(Base):
|
|||
over_18 = Column(Boolean, default=False)
|
||||
author = relationship("User", primaryjoin="Submission.author_id==User.id")
|
||||
is_bot = Column(Boolean, default=False)
|
||||
|
||||
upvotes = Column(Integer, default=1)
|
||||
downvotes = Column(Integer, default=0)
|
||||
|
||||
app_id=Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
title = Column(String(500))
|
||||
title_html = Column(String(500))
|
||||
url = Column(String(500))
|
||||
body = deferred(Column(String(10000)))
|
||||
body_html = deferred(Column(String(20000)))
|
||||
ban_reason = Column(String(128))
|
||||
embed_url = Column(String(256))
|
||||
|
||||
oauth_app = relationship("OauthApp", viewonly=True)
|
||||
|
||||
approved_by = relationship("User", uselist=False, primaryjoin="Submission.is_approved==User.id", viewonly=True)
|
||||
|
||||
awards = relationship("AwardRelationship", viewonly=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -339,24 +328,6 @@ class Submission(Base):
|
|||
def award_count(self, kind) -> int:
|
||||
return len([x for x in self.awards if x.kind == kind])
|
||||
|
||||
@property
|
||||
def title(self):
|
||||
return self.submission_aux.title
|
||||
|
||||
@title.setter
|
||||
def title(self, x):
|
||||
self.submission_aux.title = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.submission_aux.url
|
||||
|
||||
@url.setter
|
||||
def url(self, x):
|
||||
self.submission_aux.url = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
@lazy
|
||||
def realurl(self, v):
|
||||
if v and v.agendaposter and random.randint(1, 10) < 4:
|
||||
|
@ -373,27 +344,9 @@ class Submission(Base):
|
|||
return self.url
|
||||
else: return ""
|
||||
|
||||
@property
|
||||
def body(self):
|
||||
return self.submission_aux.body
|
||||
|
||||
@body.setter
|
||||
def body(self, x):
|
||||
self.submission_aux.body = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
@property
|
||||
def body_html(self):
|
||||
return self.submission_aux.body_html
|
||||
|
||||
@body_html.setter
|
||||
def body_html(self, x):
|
||||
self.submission_aux.body_html = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
def realbody(self, v):
|
||||
if self.club and not (v and v.paid_dues): return "COUNTRY CLUB ONLY"
|
||||
body = self.submission_aux.body_html
|
||||
body = self.body_html
|
||||
|
||||
if not v or v.slurreplacer:
|
||||
for s,r in SLURS.items():
|
||||
|
@ -403,15 +356,6 @@ class Submission(Base):
|
|||
if v and v.nitter: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
|
||||
return body
|
||||
|
||||
@property
|
||||
def title_html(self):
|
||||
return self.submission_aux.title_html
|
||||
|
||||
@title_html.setter
|
||||
def title_html(self, x):
|
||||
self.submission_aux.title_html = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
@lazy
|
||||
def realtitle(self, v):
|
||||
if self.club and not (v and v.paid_dues) and not (v and v.admin_level == 6): return 'COUNTRY CLUB MEMBERS ONLY'
|
||||
|
@ -423,24 +367,6 @@ class Submission(Base):
|
|||
|
||||
return title
|
||||
|
||||
@property
|
||||
def ban_reason(self):
|
||||
return self.submission_aux.ban_reason
|
||||
|
||||
@ban_reason.setter
|
||||
def ban_reason(self, x):
|
||||
self.submission_aux.ban_reason = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
@property
|
||||
def embed_url(self):
|
||||
return self.submission_aux.embed_url
|
||||
|
||||
@embed_url.setter
|
||||
def embed_url(self, x):
|
||||
self.submission_aux.embed_url = x
|
||||
g.db.add(self.submission_aux)
|
||||
|
||||
@property
|
||||
@lazy
|
||||
def is_image(self):
|
||||
|
|
|
@ -152,11 +152,11 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
|
|||
|
||||
if not (v and v.changelogsub):
|
||||
posts=posts.join(Submission.submission_aux)
|
||||
posts=posts.filter(not_(SubmissionAux.title.ilike(f'[changelog]%')))
|
||||
posts=posts.filter(not_(Submission.title.ilike(f'[changelog]%')))
|
||||
|
||||
if v and filter_words:
|
||||
for word in filter_words:
|
||||
posts=posts.filter(not_(SubmissionAux.title.ilike(f'%{word}%')))
|
||||
posts=posts.filter(not_(Submission.title.ilike(f'%{word}%')))
|
||||
|
||||
gt = kwargs.get("gt")
|
||||
lt = kwargs.get("lt")
|
||||
|
@ -258,7 +258,7 @@ def changeloglist(v=None, sort="new", page=1 ,t="all", **kwargs):
|
|||
)
|
||||
|
||||
posts=posts.join(Submission.submission_aux).join(Submission.author)
|
||||
posts=posts.filter(SubmissionAux.title.ilike(f'_changelog%', User.admin_level == 6))
|
||||
posts=posts.filter(Submission.title.ilike(f'_changelog%', User.admin_level == 6))
|
||||
|
||||
if t != 'all':
|
||||
cutoff = 0
|
||||
|
|
|
@ -617,7 +617,7 @@ def submit_post(v):
|
|||
url = url.replace("https://streamable.com/", "https://streamable.com/e/")
|
||||
|
||||
repost = g.db.query(Submission).join(Submission.submission_aux).options(lazyload('*')).filter(
|
||||
SubmissionAux.url.ilike(url),
|
||||
Submission.url.ilike(url),
|
||||
Submission.deleted_utc == 0,
|
||||
Submission.is_banned == False
|
||||
).first()
|
||||
|
@ -663,9 +663,9 @@ def submit_post(v):
|
|||
|
||||
Submission.author_id == v.id,
|
||||
Submission.deleted_utc == 0,
|
||||
SubmissionAux.title == title,
|
||||
SubmissionAux.url == url,
|
||||
SubmissionAux.body == body
|
||||
Submission.title == title,
|
||||
Submission.url == url,
|
||||
Submission.body == body
|
||||
).first()
|
||||
|
||||
if dup:
|
||||
|
@ -722,11 +722,11 @@ def submit_post(v):
|
|||
#or_(
|
||||
# and_(
|
||||
Submission.author_id == v.id,
|
||||
SubmissionAux.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"],
|
||||
Submission.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"],
|
||||
Submission.created_utc > cutoff
|
||||
# ),
|
||||
# and_(
|
||||
# SubmissionAux.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"]/2,
|
||||
# Submission.title.op('<->')(title) < app.config["SPAM_SIMILARITY_THRESHOLD"]/2,
|
||||
# Submission.created_utc > cutoff
|
||||
# )
|
||||
#)
|
||||
|
@ -741,11 +741,11 @@ def submit_post(v):
|
|||
#or_(
|
||||
# and_(
|
||||
Submission.author_id == v.id,
|
||||
SubmissionAux.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"],
|
||||
Submission.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"],
|
||||
Submission.created_utc > cutoff
|
||||
# ),
|
||||
# and_(
|
||||
# SubmissionAux.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"]/2,
|
||||
# Submission.url.op('<->')(url) < app.config["SPAM_URL_SIMILARITY_THRESHOLD"]/2,
|
||||
# Submission.created_utc > cutoff
|
||||
# )
|
||||
#)
|
||||
|
@ -863,23 +863,17 @@ def submit_post(v):
|
|||
over_18=bool(request.values.get("over_18","")),
|
||||
app_id=v.client.application.id if v.client else None,
|
||||
is_bot = request.headers.get("X-User-Type","").lower()=="bot"
|
||||
url=url,
|
||||
body=body,
|
||||
body_html=body_html,
|
||||
embed_url=embed,
|
||||
title=title,
|
||||
title_html=filter_title(title)
|
||||
)
|
||||
|
||||
g.db.add(new_post)
|
||||
g.db.flush()
|
||||
|
||||
|
||||
new_post_aux = SubmissionAux(id=new_post.id,
|
||||
url=url,
|
||||
body=body,
|
||||
body_html=body_html,
|
||||
embed_url=embed,
|
||||
title=title,
|
||||
title_html=filter_title(title)
|
||||
)
|
||||
g.db.add(new_post_aux)
|
||||
g.db.flush()
|
||||
|
||||
vote = Vote(user_id=v.id,
|
||||
vote_type=1,
|
||||
submission_id=new_post.id
|
||||
|
|
|
@ -70,7 +70,7 @@ def searchposts(v):
|
|||
|
||||
if 'q' in criteria:
|
||||
words=criteria['q'].split()
|
||||
words=[SubmissionAux.title.ilike('%'+x+'%') for x in words]
|
||||
words=[Submission.title.ilike('%'+x+'%') for x in words]
|
||||
words=tuple(words)
|
||||
posts=posts.filter(*words)
|
||||
|
||||
|
@ -90,18 +90,18 @@ def searchposts(v):
|
|||
domain=criteria['domain']
|
||||
posts=posts.filter(
|
||||
or_(
|
||||
SubmissionAux.url.ilike("https://"+domain+'/%'),
|
||||
SubmissionAux.url.ilike("https://"+domain+'/%'),
|
||||
SubmissionAux.url.ilike("https://"+domain),
|
||||
SubmissionAux.url.ilike("https://"+domain),
|
||||
SubmissionAux.url.ilike("https://www."+domain+'/%'),
|
||||
SubmissionAux.url.ilike("https://www."+domain+'/%'),
|
||||
SubmissionAux.url.ilike("https://www."+domain),
|
||||
SubmissionAux.url.ilike("https://www."+domain),
|
||||
SubmissionAux.url.ilike("https://old." + domain + '/%'),
|
||||
SubmissionAux.url.ilike("https://old." + domain + '/%'),
|
||||
SubmissionAux.url.ilike("https://old." + domain),
|
||||
SubmissionAux.url.ilike("https://old." + domain)
|
||||
Submission.url.ilike("https://"+domain+'/%'),
|
||||
Submission.url.ilike("https://"+domain+'/%'),
|
||||
Submission.url.ilike("https://"+domain),
|
||||
Submission.url.ilike("https://"+domain),
|
||||
Submission.url.ilike("https://www."+domain+'/%'),
|
||||
Submission.url.ilike("https://www."+domain+'/%'),
|
||||
Submission.url.ilike("https://www."+domain),
|
||||
Submission.url.ilike("https://www."+domain),
|
||||
Submission.url.ilike("https://old." + domain + '/%'),
|
||||
Submission.url.ilike("https://old." + domain + '/%'),
|
||||
Submission.url.ilike("https://old." + domain),
|
||||
Submission.url.ilike("https://old." + domain)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue