add improved user filtering and pagination

graphs-n-shit
lza_menace 4 years ago
parent a16176cfd6
commit 998fdb730c

@ -28,13 +28,17 @@ app.register_blueprint(leaderboard.bp)
def index():
itp = 20
page = request.args.get("page", 1)
submitter = request.args.get("submitter", None)
try:
page = int(page)
except:
flash("Wow, wtf hackerman. Cool it.")
page = 1
posts = Post.select().order_by(Post.timestamp.desc()).paginate(page, itp)
posts = Post.select().order_by(Post.timestamp.desc())
if submitter:
posts = posts.where(Post.submitter == submitter)
posts = posts.paginate(page, itp)
total_pages = Post.select().count() / itp
return render_template("index.html", posts=posts, page=page, total_pages=total_pages)

@ -21,7 +21,7 @@
<td>{{ post.timestamp.strftime('%Y-%m-%d %H:%M') }}</td>
<td>{{ post.id }}</td>
<td><a href="{{ url_for('post.read', id=post.id) }}">{{ post.title }}</a></td>
<td>{{ post.submitter }}</td>
<td><a href="/?submitter={{ post.submitter }}">{{ post.submitter }}</a></td>
</tr>
{% endfor %}
</table>
@ -32,11 +32,11 @@
{% if page > 1 %}
<a href="/?page={{ page - 1 }}" style="padding:1em;">Back</a>
<a href="{% if request.args.submitter %}/?submitter={{ request.args.submitter }}&{% else %}/?{% endif %}page={{ page - 1 }}" style="padding:1em;">Back</a>
{% endif %}
{% if page < total_pages and total_pages > 0 %}
<a href="/?page={{ page + 1 }}" style="padding:1em;">Next</a>
<a href="{% if request.args.submitter %}/?submitter={{ request.args.submitter }}&{% else %}/?{% endif %}page={{ page + 1 }}" style="padding:1em;">Next</a>
{% endif %}
<hr>

@ -12,13 +12,13 @@
<table class="table table-striped">
<tr>
<th>Submitter</th>
<th>Posts</th>
<th>Post Count</th>
<th>Amount</th>
</tr>
{% for poster, data in posters.items() | sort(attribute='1.amount', reverse=True) %}
<tr>
<td>{{ poster }}</td>
<td>{% for post in data["posts"] %}<a href="{{ url_for('post.read', id=post.id) }}">{{ post }}</a>{{ "," if not loop.last }}{% endfor %}</td>
<td><a href="/?submitter={{ poster }}">{{ poster }}</a></td>
<td>{{ data["posts"] | length }}</td>
<td>{{ data["amount"] }} WOW</td>
</tr>
{% endfor %}

@ -12,7 +12,7 @@
<!-- Post Info -->
<h1>{{ post.title }}</h1>
<p class="subtitle">{{ post.text }}</p>
<p class="subtext">Submitted by <i><u>{{ post.submitter }}</u></i> at <i>{{ post.timestamp }}</i></p>
<p class="subtext">Submitted by <i><u><a href="/?submitter={{ post.submitter }}">{{ post.submitter }}</a></u></i> at <i>{{ post.timestamp }}</i></p>
<br>
<img src="{{ url_for('post.uploaded_file', filename=post.image_name) }}" width=600/ style="margin-bottom:1em;border-radius:4px;">
<hr>

@ -22,7 +22,7 @@
<td>{{ post[1].timestamp.strftime('%Y-%m-%d %H:%M') }}</td>
<td>{{ post[1].id }}</td>
<td><a href="{{ url_for('post.read', id=post[1].id) }}">{{ post[1].title }}</a></td>
<td>{{ post[1].submitter }}</td>
<td><a href="/?submitter={{ post[1].submitter }}">{{ post[1].submitter }}</a></td>
<td>{{ post[0] }} WOW</td>
</tr>
{% endfor %}

Loading…
Cancel
Save