diff --git a/nerochan/models.py b/nerochan/models.py index 3309e82..02efafc 100644 --- a/nerochan/models.py +++ b/nerochan/models.py @@ -71,7 +71,7 @@ class Artwork(pw.Model): Artwork model is any uploaded content from a user. """ id = pw.AutoField() - user = pw.ForeignKeyField(User) + user = pw.ForeignKeyField(User, backref='artworks') image = pw.CharField() upload_date = pw.DateTimeField(default=datetime.utcnow) last_edit_date = pw.DateTimeField(default=datetime.utcnow) diff --git a/nerochan/routes/user.py b/nerochan/routes/user.py index 6f5467c..8c4ba94 100644 --- a/nerochan/routes/user.py +++ b/nerochan/routes/user.py @@ -11,7 +11,25 @@ bp = Blueprint('user', 'user') @bp.route('/users') 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/') def show(handle: str): diff --git a/nerochan/templates/user/list.html b/nerochan/templates/user/list.html new file mode 100644 index 0000000..a6a95c4 --- /dev/null +++ b/nerochan/templates/user/list.html @@ -0,0 +1,49 @@ +{% extends 'includes/base.html' %} + +{% block content %} + +
+
+

artists

+ {% if users %} +
{{ total_users }} artists in the database.
+ + + + + + + + + + + {% for user in users %} + + + + + + + {% endfor %} + +
HandleRegister DateLast Login DateArtworks
{{ user.handle }}{{ user.register_date | humanize }}{{ user.last_login_date | humanize }}{{ user.artworks.count() }}
+ {% endif %} +
+ {% if users %} +
+ + {% for i in range(1, total_pages + 1) %} +
+ {% if i == page %} + {{ page }} + {% else %} + {{ i }} + {% endif %} +
+ {% endfor %} +
+
+ {% endif %} +
+ +{% endblock %}