fdsdfs
This commit is contained in:
parent
cc8a75e086
commit
2a557154b0
4 changed files with 24 additions and 5 deletions
|
@ -65,6 +65,7 @@ class Comment(Base):
|
||||||
|
|
||||||
return f"<Comment(id={self.id})>"
|
return f"<Comment(id={self.id})>"
|
||||||
|
|
||||||
|
@lazy
|
||||||
def poll_voted(self, v):
|
def poll_voted(self, v):
|
||||||
if v:
|
if v:
|
||||||
vote = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=self.id).first()
|
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):
|
def options(self):
|
||||||
return [x for x in self.child_comments if x.author_id == AUTOPOLLER_ACCOUNT]
|
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
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def created_datetime(self):
|
def created_datetime(self):
|
||||||
|
|
|
@ -78,6 +78,12 @@ class Submission(Base):
|
||||||
def options(self):
|
def options(self):
|
||||||
return self.comments.filter_by(author_id = AUTOPOLLER_ACCOUNT, level=1)
|
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
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
def created_datetime(self):
|
def created_datetime(self):
|
||||||
|
|
|
@ -61,8 +61,11 @@
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function poll_vote(cid) {
|
function poll_vote(cid, parentid) {
|
||||||
{% if v %}
|
{% if v %}
|
||||||
|
for(let el of document.getElementsByClassName('presult-'+parentid)) {
|
||||||
|
el.classList.remove('d-none');
|
||||||
|
}
|
||||||
var type = document.getElementById(cid).checked;
|
var type = document.getElementById(cid).checked;
|
||||||
var scoretext = document.getElementById('poll-' + cid);
|
var scoretext = document.getElementById('poll-' + cid);
|
||||||
var score = Number(scoretext.textContent);
|
var score = Number(scoretext.textContent);
|
||||||
|
@ -311,10 +314,10 @@
|
||||||
<div id="comment-text-{{c.id}}" class="comment-text mb-0">
|
<div id="comment-text-{{c.id}}" class="comment-text mb-0">
|
||||||
{{c.realbody(v) | safe}}
|
{{c.realbody(v) | safe}}
|
||||||
{% if c.options %}
|
{% if c.options %}
|
||||||
{% for c in c.options %}
|
{% for o in c.options %}
|
||||||
<div class="custom-control">
|
<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}}')">
|
<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="{{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="{{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>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
|
|
|
@ -128,6 +128,9 @@
|
||||||
<script>
|
<script>
|
||||||
function poll_vote(cid) {
|
function poll_vote(cid) {
|
||||||
{% if v %}
|
{% if v %}
|
||||||
|
for(let el of document.getElementsByClassName('presult')) {
|
||||||
|
el.classList.remove('d-none');
|
||||||
|
}
|
||||||
var type = document.getElementById(cid).checked;
|
var type = document.getElementById(cid).checked;
|
||||||
var scoretext = document.getElementById('poll-' + cid);
|
var scoretext = document.getElementById('poll-' + cid);
|
||||||
var score = Number(scoretext.textContent);
|
var score = Number(scoretext.textContent);
|
||||||
|
@ -510,7 +513,7 @@
|
||||||
{% for c in p.options %}
|
{% for c in p.options %}
|
||||||
<div class="custom-control">
|
<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}}')">
|
<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>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue