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

Commit

Permalink
Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbate19 committed Mar 26, 2022
1 parent 3a46e07 commit 19f3c3f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 97 deletions.
42 changes: 13 additions & 29 deletions quotefault/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def get_quote_query(speaker: str = "", submitter: str = "", include_hidden: bool
quote_query = db.session.query(Quote,
func.sum(Vote.direction).label('votes')).outerjoin(Vote).group_by(Quote)
# Put the most recent first
quote_query = quote_query.order_by(Quote.quote_time.desc())
quote_query = quote_query.order_by(Quote.id.desc())
# Filter hidden quotes
if not include_hidden:
quote_query = quote_query.filter(Quote.hidden == False)
Expand All @@ -206,48 +206,32 @@ def get_quote_query(speaker: str = "", submitter: str = "", include_hidden: bool
# display first 20 stored quotes
@app.route('/storage', methods=['GET'])
@auth.oidc_auth
def get():
def default_get():
return redirect("/storage/1")

# display first 20 stored quotes
@app.route('/storage/<page>', methods=['GET'])
@auth.oidc_auth
def get(page):
"""
Show submitted quotes, only showing first 20 initially
"""
metadata = get_metadata()

page = int(page)

# Get the most recent 20 quotes
quotes = get_quote_query(speaker = request.args.get('speaker'),
submitter = request.args.get('submitter')).limit(20).all()
submitter = request.args.get('submitter')).offset((page-1)*20).limit(20).all()

#tie any votes the user has made to their uid
user_votes = Vote.query.filter(Vote.voter == metadata['uid']).all()
return render_template(
'bootstrap/storage.html',
quotes=quotes,
metadata=metadata,
user_votes=user_votes
)


# display ALL stored quotes
@app.route('/additional', methods=['GET'])
@auth.oidc_auth
def additional_quotes():
"""
Show beyond the first 20 quotes
"""

metadata = get_metadata()

# Get all the quotes
quotes = get_quote_query(speaker = request.args.get('speaker'),
submitter = request.args.get('submitter')).all()

#tie any votes the user has made to their uid
user_votes = db.session.query(Vote).filter(Vote.voter == metadata['uid']).all()

return render_template(
'bootstrap/additional_quotes.html',
quotes=quotes[20:],
metadata=metadata,
user_votes=user_votes
user_votes=user_votes,
page=page
)

@app.route('/report/<quote_id>', methods=['POST'])
Expand Down
62 changes: 0 additions & 62 deletions quotefault/static/js/load_more.js

This file was deleted.

2 changes: 0 additions & 2 deletions quotefault/templates/bootstrap/additional_quotes.html

This file was deleted.

7 changes: 3 additions & 4 deletions quotefault/templates/bootstrap/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
{% endif %}
{% endwith %}
{{ display( quotes ) }}
<button href="#moreQuotes" id="get_more" data-toggle="collapse" class="btn btn-default center-block">But wait, there's more!</button>
<br>
<div id="moreQuotes" class="collapse" aria-expanded="false">
</div>
<a href="/storage/{{ page + 1 }}">
<button id="get_more" class="btn btn-default center-block">But wait, there's more!</button>
</a>
</div>
{% endblock %}

Expand Down

0 comments on commit 19f3c3f

Please sign in to comment.