remotes/1693045480750635534/spooky-22
Aevann1 2021-11-05 22:10:51 +02:00
parent dbc282b606
commit c4ea7837b7
4 changed files with 24 additions and 5 deletions

View File

@ -65,6 +65,7 @@ class Comment(Base):
return f"<Comment(id={self.id})>"
@lazy
def poll_voted(self, v):
if v:
vote = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=self.id).first()
@ -77,6 +78,12 @@ class Comment(Base):
def options(self):
return [x for x in self.child_comments if x.author_id == AUTOPOLLER_ACCOUNT]
def total_poll_voted(self, v):
if v:
for option in self.options:
if option.poll_voted(v): return True
return False
@property
@lazy
def created_datetime(self):

View File

@ -78,6 +78,12 @@ class Submission(Base):
def options(self):
return self.comments.filter_by(author_id = AUTOPOLLER_ACCOUNT, level=1)
def total_poll_voted(self, v):
if v:
for option in self.options:
if option.poll_voted(v): return True
return False
@property
@lazy
def created_datetime(self):

View File

@ -61,8 +61,11 @@
<script>
function poll_vote(cid) {
function poll_vote(cid, parentid) {
{% if v %}
for(let el of document.getElementsByClassName('presult-'+parentid)) {
el.classList.remove('d-none');
}
var type = document.getElementById(cid).checked;
var scoretext = document.getElementById('poll-' + cid);
var score = Number(scoretext.textContent);
@ -311,10 +314,10 @@
<div id="comment-text-{{c.id}}" class="comment-text mb-0">
{{c.realbody(v) | safe}}
{% if c.options %}
{% for c in c.options %}
{% for o in c.options %}
<div class="custom-control">
<input type="checkbox" class="custom-control-input" id="{{c.id}}" name="option" {% if c.poll_voted(v) %}checked{% endif %} onchange="poll_vote('{{c.id}}')">
<label class="custom-control-label" for="{{c.id}}">{{c.body_html | safe}}{% if c.poll_voted(v) %} - <a href="/votes?link=t3_{{c.id}}"><span id="poll-{{c.id}}">{{c.upvotes}}</span> votes</a>{% endif %}</label>
<input type="checkbox" class="custom-control-input" id="{{o.id}}" name="option" {% if o.poll_voted(v) %}checked{% endif %} onchange="poll_vote('{{o.id}}', '{{c.id}}')">
<label class="custom-control-label" for="{{o.id}}">{{o.body_html | safe}}<span class="presult-{{c.id}} {% if not c.total_poll_voted(v) %}d-none{% endif %}"> - <a href="/votes?link=t3_{{o.id}}"><span id="poll-{{o.id}}">{{o.upvotes}}</span> votes</a></span></label>
</div>
{% endfor %}
<pre></pre>

View File

@ -128,6 +128,9 @@
<script>
function poll_vote(cid) {
{% if v %}
for(let el of document.getElementsByClassName('presult')) {
el.classList.remove('d-none');
}
var type = document.getElementById(cid).checked;
var scoretext = document.getElementById('poll-' + cid);
var score = Number(scoretext.textContent);
@ -510,7 +513,7 @@
{% for c in p.options %}
<div class="custom-control">
<input type="checkbox" class="custom-control-input" id="{{c.id}}" name="option" {% if c.poll_voted(v) %}checked{% endif %} onchange="poll_vote('{{c.id}}')">
<label class="custom-control-label" for="{{c.id}}">{{c.body_html | safe}}{% if c.poll_voted(v) %} - <a href="/votes?link=t3_{{c.id}}"><span id="poll-{{c.id}}">{{c.upvotes}}</span> votes</a>{% endif %}</label>
<label class="custom-control-label" for="{{c.id}}">{{c.body_html | safe}}<span class="presult {% if not p.total_poll_voted(v) %}d-none{% endif %}"> - <a href="/votes?link=t3_{{c.id}}"><span id="poll-{{c.id}}">{{c.upvotes}}</span> votes</a></span></label>
</div>
{% endfor %}