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

Pagination #68

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change this?

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,38 @@ 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()

rows = get_quote_query(speaker = request.args.get('speaker'),
submitter = request.args.get('submitter')).count()

rows = int(rows//20 + bool(rows%20 > 0))

#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,
rows=rows
)

@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.

51 changes: 47 additions & 4 deletions quotefault/templates/bootstrap/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,53 @@
{% 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>
<nav aria-label="page selector">
<ul class="pagination pagination-lg justify-content-center">
{% if page == 1 %}
<li class="page-item disabled">
<a class="page-link" href="/storage/{{ page - 1 }}" tabindex="-1">Previous</a>
{% else %}
<li class="page-item">
<a class="page-link" href="/storage/{{ page - 1 }}">Previous</a>
{% endif %}
</li>
{% if rows <= 12 %}
{% for num in range(1, rows + 1) %}
<li class="page-item">
<a class="page-link" href="/storage/{{ num }}">{{ num }}</a>
</li>
{% endfor %}
{% elif page < 6 %}
{% for num in range(1, 12) %}
<li class="page-item">
<a class="page-link" href="/storage/{{ num }}">{{ num }}</a>
</li>
{% endfor %}
{% elif rows - page <= 5 %}
{% for num in range(rows - 10, rows + 1) %}
<li class="page-item">
<a class="page-link" href="/storage/{{ num }}">{{ num }}</a>
</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

planning to mark the current page separately?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should, good point.

{% endfor %}
{% else %}
{% for num in range(page - 5, page + 6) %}
<li class="page-item">
<a class="page-link" href="/storage/{{ num }}">{{ num }}</a>
</li>
{% endfor %}
{% endif %}
{% if page == rows %}
<li class="page-item disabled">
<a class="page-link" href="/storage/{{ page + 1 }}" tabindex="-1">Next</a>
{% else %}
<li class="page-item">
<a class="page-link" href="/storage/{{ page + 1 }}">Next</a>
{% endif %}
</li>

</li>
</ul>
</nav>
</div>
{% endblock %}

Expand Down