This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Pagination #68
Open
jabbate19
wants to merge
5
commits into
ComputerScienceHouse:master
Choose a base branch
from
jabbate19:pagination
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pagination #68
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
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
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. 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.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?