Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 4bde5dc

Browse files
Vivian Nowka-Keanedevinmatte
authored andcommitted
Fixed page jump bug and added functionality after the top 20 quotes (#46)
* Fixed page jump bug and added functionality after the top 20 quotes * Fixed page jump bug and added functionality after the top 20 quotes
1 parent c0019ed commit 4bde5dc

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

quotefault/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def get():
217217
elif metadata['speaker'] is not None:
218218
quotes = Quote.query.order_by(Quote.quote_time.desc()).filter(Quote.speaker == metadata['speaker']).all()
219219
else:
220+
# collect all quote rows in the Quote db
220221
# quotes = Quote.query.order_by(Quote.quote_time.desc()).limit(20).all()
221222

222223
# returns tuples with a quote and its net vote value
@@ -245,17 +246,26 @@ def get():
245246
@app.route('/additional', methods=['GET'])
246247
@auth.oidc_auth
247248
def additional_quotes():
248-
quotes = Quote.query.order_by(Quote.quote_time.desc()).all() # collect all quote rows in the Quote db
249+
249250
metadata = get_metadata()
251+
252+
# returns tuples with a quote and its net vote value
253+
quotes = db.session.query(Quote, func.sum(Vote.direction).label('votes')).outerjoin(Vote).group_by(Quote).order_by(
254+
Quote.quote_time.desc()).all()
255+
256+
user_votes = db.session.query(Vote).filter(Vote.voter == metadata['uid']).all()
257+
250258
if request.cookies.get('flag'):
251259
return render_template(
252260
'flag/additional_quotes.html',
253261
quotes=quotes[20:],
254-
metadata=metadata
262+
metadata=metadata,
263+
user_votes=user_votes
255264
)
256265
else:
257266
return render_template(
258267
'bootstrap/additional_quotes.html',
259268
quotes=quotes[20:],
260-
metadata=metadata
269+
metadata=metadata,
270+
user_votes=user_votes
261271
)

quotefault/templates/bootstrap/additional_quotes.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
{% for quote in quotes %}
1+
{% for quote, votes in quotes %}
22
<div class="card m-3">
33
<div class="card-body">
44
"{{ quote.quote }}" <b>- {{ get_display_name(quote.speaker) }}</b>
5+
<div id="votes-{{ quote.id }}" class="upvote upvote-meta-stackoverflow">
6+
<a class="upvote" id="upVote-{{ quote.id }}" onClick="makeVote({{ quote.id }}, 1)">
7+
</a>
8+
<span class="count">
9+
{% if votes %}
10+
{{ votes }}
11+
{% else %}
12+
0
13+
{% endif %}
14+
</span>
15+
<a class="downvote" id="downVote-{{ quote.id }}"
16+
onClick="makeVote({{ quote.id }}, -1)">
17+
</a>
18+
</div>
519
</div>
620
<div class="card-footer">
721
Submitted by <a

quotefault/templates/bootstrap/storage.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<div class="card-body">
2626
"{{ quote.quote }}" <b>- {{ get_display_name(quote.speaker) }}</b>
2727
<div id="votes-{{ quote.id }}" class="upvote upvote-meta-stackoverflow">
28-
<a href="#" class="upvote" id="upVote-{{ quote.id }}" onClick="makeVote({{ quote.id }}, 1)">
28+
<a class="upvote" id="upVote-{{ quote.id }}" onClick="makeVote({{ quote.id }}, 1)">
2929
</a>
3030
<span class="count">
3131
{% if votes %}
@@ -34,7 +34,7 @@
3434
0
3535
{% endif %}
3636
</span>
37-
<a href="#" class="downvote" id="downVote-{{ quote.id }}"
37+
<a class="downvote" id="downVote-{{ quote.id }}"
3838
onClick="makeVote({{ quote.id }}, -1)">
3939
</a>
4040
</div>

0 commit comments

Comments
 (0)