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

Commit 19f3c3f

Browse files
committed
Pagination
1 parent 3a46e07 commit 19f3c3f

File tree

4 files changed

+16
-97
lines changed

4 files changed

+16
-97
lines changed

quotefault/__init__.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def get_quote_query(speaker: str = "", submitter: str = "", include_hidden: bool
192192
quote_query = db.session.query(Quote,
193193
func.sum(Vote.direction).label('votes')).outerjoin(Vote).group_by(Quote)
194194
# Put the most recent first
195-
quote_query = quote_query.order_by(Quote.quote_time.desc())
195+
quote_query = quote_query.order_by(Quote.id.desc())
196196
# Filter hidden quotes
197197
if not include_hidden:
198198
quote_query = quote_query.filter(Quote.hidden == False)
@@ -206,48 +206,32 @@ def get_quote_query(speaker: str = "", submitter: str = "", include_hidden: bool
206206
# display first 20 stored quotes
207207
@app.route('/storage', methods=['GET'])
208208
@auth.oidc_auth
209-
def get():
209+
def default_get():
210+
return redirect("/storage/1")
211+
212+
# display first 20 stored quotes
213+
@app.route('/storage/<page>', methods=['GET'])
214+
@auth.oidc_auth
215+
def get(page):
210216
"""
211217
Show submitted quotes, only showing first 20 initially
212218
"""
213219
metadata = get_metadata()
214220

221+
page = int(page)
222+
215223
# Get the most recent 20 quotes
216224
quotes = get_quote_query(speaker = request.args.get('speaker'),
217-
submitter = request.args.get('submitter')).limit(20).all()
225+
submitter = request.args.get('submitter')).offset((page-1)*20).limit(20).all()
218226

219227
#tie any votes the user has made to their uid
220228
user_votes = Vote.query.filter(Vote.voter == metadata['uid']).all()
221229
return render_template(
222230
'bootstrap/storage.html',
223231
quotes=quotes,
224232
metadata=metadata,
225-
user_votes=user_votes
226-
)
227-
228-
229-
# display ALL stored quotes
230-
@app.route('/additional', methods=['GET'])
231-
@auth.oidc_auth
232-
def additional_quotes():
233-
"""
234-
Show beyond the first 20 quotes
235-
"""
236-
237-
metadata = get_metadata()
238-
239-
# Get all the quotes
240-
quotes = get_quote_query(speaker = request.args.get('speaker'),
241-
submitter = request.args.get('submitter')).all()
242-
243-
#tie any votes the user has made to their uid
244-
user_votes = db.session.query(Vote).filter(Vote.voter == metadata['uid']).all()
245-
246-
return render_template(
247-
'bootstrap/additional_quotes.html',
248-
quotes=quotes[20:],
249-
metadata=metadata,
250-
user_votes=user_votes
233+
user_votes=user_votes,
234+
page=page
251235
)
252236

253237
@app.route('/report/<quote_id>', methods=['POST'])

quotefault/static/js/load_more.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

quotefault/templates/bootstrap/additional_quotes.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

quotefault/templates/bootstrap/storage.html

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
{% endif %}
1919
{% endwith %}
2020
{{ display( quotes ) }}
21-
<button href="#moreQuotes" id="get_more" data-toggle="collapse" class="btn btn-default center-block">But wait, there's more!</button>
22-
<br>
23-
<div id="moreQuotes" class="collapse" aria-expanded="false">
24-
</div>
21+
<a href="/storage/{{ page + 1 }}">
22+
<button id="get_more" class="btn btn-default center-block">But wait, there's more!</button>
23+
</a>
2524
</div>
2625
{% endblock %}
2726

0 commit comments

Comments
 (0)