dont query polls on frontpage

remotes/1693045480750635534/spooky-22
Aevann1 2022-06-26 08:10:02 +02:00
parent 4d7e7b629b
commit 5aad7e09a6
2 changed files with 39 additions and 47 deletions

View File

@ -387,7 +387,7 @@ class Submission(Base):
return url
@lazy
def realbody(self, v):
def realbody(self, v, listing=False):
if self.club and not (v and (v.paid_dues or v.id == self.author_id)): return f"<p>{CC} ONLY</p>"
body = self.body_html or ""
@ -407,43 +407,44 @@ class Submission(Base):
self.upvotes += amount
g.db.add(self)
for c in self.options:
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{c.id}" name="option"'
if c.poll_voted(v): body += " checked"
if v: body += f''' onchange="poll_vote('{c.id}', '{self.id}')"'''
else: body += f''' onchange="poll_vote_no_v('{c.id}', '{self.id}')"'''
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
if not self.total_poll_voted(v): body += ' d-none'
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="poll-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
if not listing:
for c in self.options:
body += f'<div class="custom-control"><input type="checkbox" class="custom-control-input" id="{c.id}" name="option"'
if c.poll_voted(v): body += " checked"
if v: body += f''' onchange="poll_vote('{c.id}', '{self.id}')"'''
else: body += f''' onchange="poll_vote_no_v('{c.id}', '{self.id}')"'''
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
if not self.total_poll_voted(v): body += ' d-none'
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="poll-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
if self.choices:
curr = self.total_choice_voted(v)
if curr: curr = " value=" + str(curr.comment_id)
else: curr = ''
body += f'<input class="d-none" id="current-{self.id}"{curr}>'
if self.choices:
curr = self.total_choice_voted(v)
if curr: curr = " value=" + str(curr.comment_id)
else: curr = ''
body += f'<input class="d-none" id="current-{self.id}"{curr}>'
for c in self.choices:
body += f'''<div class="custom-control"><input name="choice-{self.id}" autocomplete="off" class="custom-control-input" type="radio" id="{c.id}" onchange="choice_vote('{c.id}','{self.id}')"'''
if c.poll_voted(v): body += " checked "
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
if not self.total_choice_voted(v): body += ' d-none'
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="choice-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
for c in self.choices:
body += f'''<div class="custom-control"><input name="choice-{self.id}" autocomplete="off" class="custom-control-input" type="radio" id="{c.id}" onchange="choice_vote('{c.id}','{self.id}')"'''
if c.poll_voted(v): body += " checked "
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html}<span class="presult-{self.id}'''
if not self.total_choice_voted(v): body += ' d-none'
body += f'"> - <a href="/votes?link=t3_{c.id}"><span id="choice-{c.id}">{c.upvotes}</span> votes</a></span></label></div>'
for c in self.bet_options:
body += f'''<div class="custom-control mt-3"><input autocomplete="off" class="custom-control-input bet" type="radio" id="{c.id}" onchange="bet_vote('{c.id}')"'''
if c.poll_voted(v): body += " checked "
if not (v and v.coins > 200) or self.total_bet_voted(v) or not v.can_gamble: body += " disabled "
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html} - <a href="/votes?link=t3_{c.id}"><span id="bet-{c.id}">{c.upvotes}</span> bets</a>'''
if not self.total_bet_voted(v):
body += '''<span class="cost"> (cost of entry: 200 coins)</span>'''
body += "</label>"
if v and v.admin_level > 2:
body += f'''<button class="btn btn-primary px-2 mx-2" style="font-size:10px;padding:2px" onclick="post_toast(this,'/distribute/{c.id}')">Declare winner</button>'''
body += "</div>"
for c in self.bet_options:
body += f'''<div class="custom-control mt-3"><input autocomplete="off" class="custom-control-input bet" type="radio" id="{c.id}" onchange="bet_vote('{c.id}')"'''
if c.poll_voted(v): body += " checked "
if not (v and v.coins > 200) or self.total_bet_voted(v) or not v.can_gamble: body += " disabled "
body += f'''><label class="custom-control-label" for="{c.id}">{c.body_html} - <a href="/votes?link=t3_{c.id}"><span id="bet-{c.id}">{c.upvotes}</span> bets</a>'''
if not self.total_bet_voted(v):
body += '''<span class="cost"> (cost of entry: 200 coins)</span>'''
body += "</label>"
if v and v.admin_level > 2:
body += f'''<button class="btn btn-primary px-2 mx-2" style="font-size:10px;padding:2px" onclick="post_toast(this,'/distribute/{c.id}')">Declare winner</button>'''
body += "</div>"
if self.author.sig_html and (self.author_id == MOOSE_ID or (not self.ghost and not (v and v.sigs_disabled))):
body += f"<hr>{self.author.sig_html}"
if self.author.sig_html and (self.author_id == MOOSE_ID or (not self.ghost and not (v and v.sigs_disabled))):
body += f"<hr>{self.author.sig_html}"
return body
@ -503,13 +504,4 @@ class Submission(Base):
@lazy
def active_flags(self, v):
return len(self.flags(v))
@lazy
def is_saved(self, v):
return g.db.query(SaveRelationship).filter_by(user_id=v.id, submission_id=self.id).one_or_none()
@lazy
def is_subscribed(self, v):
return g.db.query(Subscription).filter_by(user_id=v.id, submission_id=self.id).one_or_none()
return len(self.flags(v))

View File

@ -218,7 +218,7 @@
<div class="post-actions mt-2 d-none d-md-block">
<ul class="list-inline text-right d-flex">
{% if p.realbody(v) %}
{% if p.realbody(v, True) %}
<a class="list-inline-item" role="button" onclick="expandText('{{p.id}}')"><i class="fas fa-expand-alt mr-0 text-expand-icon-{{p.id}}"></i></a>
{% endif %}
<li class="list-inline-item">
@ -250,7 +250,7 @@
</li>
{% if p.realbody(v) and request.path != "/changelog"%}
{% if p.realbody(v, True) and request.path != "/changelog"%}
<a class="list-inline-item" role="button" onclick="expandText('{{p.id}}')"><i class="fas fa-expand-alt mr-0 text-expand-icon-{{p.id}}"></i></a>
{% endif %}
@ -332,9 +332,9 @@
{% if (not p.club or v and (v.paid_dues or v.id == p.author_id)) and not v_forbid_deleted %}
{% if p.realbody(v) %}
{% if p.realbody(v, True) %}
<div class="d-none card rounded border pt-3 pb-2 my-2 {% if p.author.agendaposter %}agendaposter{% endif %}" id="post-text-{{p.id}}">
{{p.realbody(v) | safe}}
{{p.realbody(v, True) | safe}}
</div>
{% endif %}