master
Aevann1 2021-07-29 00:38:58 +02:00
parent e67927ce9c
commit dfb7f8df71
3 changed files with 22 additions and 15 deletions

View File

@ -296,10 +296,9 @@ class Submission(Base, Stndrd, Age_times, Scores, Fuzzing):
def has_award(self, kind): def has_award(self, kind):
return bool(len([x for x in self.awards if x.kind == kind])) return bool(len([x for x in self.awards if x.kind == kind]))
def voted(self, v): @property
vote = v.votes.filter_by(submission_id=self.id).first() def voted(self):
if vote: return vote.vote_type return self._voted if "_voted" in self.__dict__ else 0
else: return 0
@property @property
def title(self): def title(self):

View File

@ -69,8 +69,8 @@ def notifications(v):
render_replies=True, render_replies=True,
is_notification_page=True) is_notification_page=True)
@cache.memoize(timeout=1500)
def frontlist(v=None, sort="hot", page=1,t="all", filter_words='', **kwargs): def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words='', **kwargs):
posts = g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0) posts = g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0)
if v and v.admin_level == 0: if v and v.admin_level == 0:
@ -169,7 +169,12 @@ def frontlist(v=None, sort="hot", page=1,t="all", filter_words='', **kwargs):
post.views = post.views + random.randint(7,10) post.views = post.views + random.randint(7,10)
g.db.add(post) g.db.add(post)
return [x for x in posts if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)][:26] posts = [x for x in posts if not (x.author and x.author.shadowbanned) or (v and v.id == x.author_id)][:26]
if ids_only:
posts = [x.id for x in posts]
return posts
return posts
@app.get("/") @app.get("/")
@app.get("/api/v1/listing") @app.get("/api/v1/listing")
@ -193,7 +198,7 @@ def front_all(v):
sort=request.args.get("sort", defaultsorting) sort=request.args.get("sort", defaultsorting)
t=request.args.get('t', defaulttime) t=request.args.get('t', defaulttime)
posts = frontlist(sort=sort, ids = frontlist(sort=sort,
page=page, page=page,
t=t, t=t,
v=v, v=v,
@ -203,8 +208,11 @@ def front_all(v):
) )
# check existence of next page # check existence of next page
next_exists = (len(posts) == 26) next_exists = (len(ids) == 26)
posts = posts[:25] ids = ids[0:25]
# check if ids exist
posts = get_posts(ids, v=v)
if request.path == "/": return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page) if request.path == "/": return render_template("home.html", v=v, listing=posts, next_exists=next_exists, sort=sort, t=t, page=page)
else: return jsonify({"data": [x.json for x in posts], "next_exists": next_exists}) else: return jsonify({"data": [x.json for x in posts], "next_exists": next_exists})
@ -303,7 +311,7 @@ def changelog(v):
# check existence of next page # check existence of next page
next_exists = (len(ids) == 26) next_exists = (len(ids) == 26)
ids = ids[:25] ids = ids[0:25]
# check if ids exist # check if ids exist
posts = get_posts(ids, v=v) posts = get_posts(ids, v=v)
@ -418,7 +426,7 @@ def all_comments(v):
next_exists = len(idlist) == 26 next_exists = len(idlist) == 26
idlist = idlist[:25] idlist = idlist[0:25]
return {"html": lambda: render_template("home_comments.html", return {"html": lambda: render_template("home_comments.html",
v=v, v=v,

View File

@ -14,7 +14,7 @@
{% set score=ups-downs %} {% set score=ups-downs %}
{% if v %} {% if v %}
{% set voted= p.voted(v) %} {% set voted= p.voted %}
{% else %} {% else %}
{% set voted=-2 %} {% set voted=-2 %}
{% endif %} {% endif %}