-
Notifications
You must be signed in to change notification settings - Fork 19
Pagination #68
base: master
Are you sure you want to change the base?
Pagination #68
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
@@ -206,48 +206,43 @@ 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) | ||
|
|
||
| query = get_quote_query(speaker = request.args.get('speaker'), | ||
| submitter = request.args.get('submitter')) | ||
|
|
||
| rows = query.count() | ||
| rows = int(rows//20 + bool(rows%20 > 0)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really rows? Seems more like it's |
||
|
|
||
| if page > rows or page < 1: | ||
| return "Page Out of Bounds", 404 | ||
|
|
||
| # Get the most recent 20 quotes | ||
| quotes = get_quote_query(speaker = request.args.get('speaker'), | ||
| submitter = request.args.get('submitter')).limit(20).all() | ||
| quotes = query.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, | ||
| rows=rows, | ||
| begin=max(1, page-6), | ||
| end=min(page+6, rows) + 1 | ||
|
Comment on lines
+244
to
+245
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this logic not be done in jinja? seems kinda weird to pass these when you're already passing the page.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Min and Max are not jinja functions |
||
| ) | ||
|
|
||
| @app.route('/report/<quote_id>', methods=['POST']) | ||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,34 @@ | |
| {% 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> | ||
| {% for num in range(begin, end) %} | ||
| <li class="page-item"> | ||
| <a class="page-link" href="/storage/{{ num }}">{{ num }}</a> | ||
| </li> | ||
|
jabbate19 marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. planning to mark the current page separately?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should, good point. |
||
| {% endfor %} | ||
| {% 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 %} | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change this?