mirror of
https://github.com/godotengine/godot-showreel-voting.git
synced 2026-09-03 18:15:13 +03:00
added show all option to pagination
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from typing import Optional
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import IntegerField, StringField, ValidationError
|
||||
from wtforms.validators import InputRequired
|
||||
@@ -24,4 +23,4 @@ class CastVoteForm(FlaskForm):
|
||||
|
||||
|
||||
class SelectVideoForm(FlaskForm):
|
||||
video_id = IntegerField('Video ID', validators=[InputRequired()])
|
||||
video_id = IntegerField('Video ID', validators=[InputRequired()])
|
||||
|
||||
@@ -89,6 +89,7 @@ def delete_vote(video_id: int):
|
||||
@bp.route('/history')
|
||||
@auth.vote_role_required
|
||||
def history():
|
||||
limit = request.args.get('limit')
|
||||
page = int(request.args.get('page', 1))
|
||||
total_video_count = DB.session.query(Video).count()
|
||||
total_user_votes = DB.session.query(Vote).filter(Vote.user_id == g.user.id).count()
|
||||
@@ -98,15 +99,22 @@ def history():
|
||||
}
|
||||
query = DB.session.query(Vote).filter(Vote.user_id == g.user.id).order_by(Vote.created_at.desc())
|
||||
|
||||
if limit == 'all':
|
||||
total_results = query.count()
|
||||
per_page = total_results if total_results > 0 else 1
|
||||
else:
|
||||
per_page = 30
|
||||
|
||||
try:
|
||||
submitted_votes = DB.paginate(query, page=page, per_page=30)
|
||||
submitted_votes = DB.paginate(query, page=page, per_page=per_page)
|
||||
except NotFound:
|
||||
submitted_votes = DB.paginate(query, page=1, per_page=30)
|
||||
submitted_votes = DB.paginate(query, page=1, per_page=per_page)
|
||||
|
||||
|
||||
# We probably want to add pagination here
|
||||
content = render_template('history.html', progress=progress, submitted_votes=submitted_votes)
|
||||
if request.args.get('page'):
|
||||
|
||||
if request.args.get('page') or request.args.get('limit'):
|
||||
return content
|
||||
return render_template('default.html', content = content, user=g.user)
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
<h1 style="margin-bottom: 20px;">Vote history</h1>
|
||||
<div>
|
||||
<p>You have voted {{ progress.current }} out of {{ progress.total }} entries. {% if progress.current != progress.total %}<a href="/vote">Continue voting</a>.{% endif %}</p>
|
||||
|
||||
<div class="entries">
|
||||
<div class="entries">
|
||||
<!-- Items should be sorted by what you Voted last in chronological order -->
|
||||
<!-- This should be a loop -->
|
||||
{% for entry in submitted_votes.items %}
|
||||
@@ -43,7 +42,6 @@
|
||||
{% elif entry.rating == -1 %}
|
||||
<p>Your vote: <strong class="vote no">No 👎</strong></p>
|
||||
{% else %}
|
||||
<!-- This should not happen -->
|
||||
<p>Your vote: <strong>Skip ⏭️</strong></p>
|
||||
{% endif %}
|
||||
<div style="margin-top: 10px;">
|
||||
|
||||
@@ -41,5 +41,14 @@
|
||||
<span class="ellipsis">…</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<button
|
||||
class="button small secondary"
|
||||
type="button"
|
||||
hx-get="{{ url_for(request_url, limit='all') }}"
|
||||
hx-target="{{ hx_target }}"
|
||||
hx-swap="{{ strategy }} show:window:top"
|
||||
>
|
||||
Show all
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user