fix user list

master
lza_menace 2 years ago
parent e502c1eb5d
commit 6c1ad45762

@ -71,7 +71,7 @@ class Artwork(pw.Model):
Artwork model is any uploaded content from a user. Artwork model is any uploaded content from a user.
""" """
id = pw.AutoField() id = pw.AutoField()
user = pw.ForeignKeyField(User) user = pw.ForeignKeyField(User, backref='artworks')
image = pw.CharField() image = pw.CharField()
upload_date = pw.DateTimeField(default=datetime.utcnow) upload_date = pw.DateTimeField(default=datetime.utcnow)
last_edit_date = pw.DateTimeField(default=datetime.utcnow) last_edit_date = pw.DateTimeField(default=datetime.utcnow)

@ -11,7 +11,25 @@ bp = Blueprint('user', 'user')
@bp.route('/users') @bp.route('/users')
def list(): def list():
return 'users list' ipp = 20
page = request.args.get("page", 1)
try:
page = int(page)
except:
flash('Invalid page number provided.', 'warning')
page = 1
users = User.select().where(
User.is_verified == True
).order_by(User.register_date.desc())
paginated_users = users.paginate(page, ipp)
total_pages = ceil(users.count() / ipp)
return render_template(
'user/list.html',
users=paginated_users,
total_users=users.count(),
page=page,
total_pages=total_pages
)
@bp.route('/user/<handle>') @bp.route('/user/<handle>')
def show(handle: str): def show(handle: str):

@ -0,0 +1,49 @@
{% extends 'includes/base.html' %}
{% block content %}
<div class="container">
<div class="row">
<h1>artists</h1>
{% if users %}
<h6>{{ total_users }} artists in the database.</h6>
<table class="u-full-width">
<thead>
<tr>
<th>Handle</th>
<th>Register Date</th>
<th>Last Login Date</th>
<th>Artworks</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
<td><a href="{{ url_for('user.show', handle=user.handle) }}">{{ user.handle }}</a></td>
<td>{{ user.register_date | humanize }}</td>
<td>{{ user.last_login_date | humanize }}</td>
<td>{{ user.artworks.count() }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% if users %}
<div class="row mt-4">
<span class="inline">
{% for i in range(1, total_pages + 1) %}
<h6 class="inline">
{% if i == page %}
{{ page }}
{% else %}
<a href="?page={{ i }}">{{ i }}</a>
{% endif %}
</h6>
{% endfor %}
</span>
</div>
{% endif %}
</div>
{% endblock %}
Loading…
Cancel
Save