From 9a51c3c4fb6334f729bb69fcfda5703627dc4470 Mon Sep 17 00:00:00 2001 From: dsc Date: Sat, 12 Mar 2022 22:14:27 +0200 Subject: [PATCH] Ignore accounts without address, add user page --- yellow/api.py | 4 +- yellow/routes.py | 13 +++++++ yellow/templates/includes/user_results.html | 2 +- yellow/templates/user.html | 42 +++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 yellow/templates/user.html diff --git a/yellow/api.py b/yellow/api.py index 5db663b..699649c 100644 --- a/yellow/api.py +++ b/yellow/api.py @@ -13,7 +13,9 @@ async def api_root(): @bp_api.get('/user/') async def api_all(): - return jsonify([u.to_json(ignore_key='id') for u in User.select()]) + q = User.select() + q = q.where(User.address.is_null(False)) + return jsonify([u.to_json(ignore_key='id') for u in q]) @bp_api.get('/user/') diff --git a/yellow/routes.py b/yellow/routes.py index 7c1e6ec..ae5723d 100644 --- a/yellow/routes.py +++ b/yellow/routes.py @@ -70,6 +70,19 @@ async def search(): return await render_template('search.html', users=users) +@bp_routes.route("/user/") +async def user_page(name: str): + if not name or len(name) <= 1: + raise Exception("invalid name") + + _user = User.select().where( + User.username == name, + User.address.is_null(False) + ).get() + + return await render_template('user.html', users=[_user]) + + @bp_routes.route("/about") async def about(): return await render_template('about.html') diff --git a/yellow/templates/includes/user_results.html b/yellow/templates/includes/user_results.html index 7c6fca7..0b3bd7e 100644 --- a/yellow/templates/includes/user_results.html +++ b/yellow/templates/includes/user_results.html @@ -2,7 +2,7 @@ {% for user in users %}
- {{user.username}} + {{user.username}} Added: {{ user.created_dt }}
{{user.address}} diff --git a/yellow/templates/user.html b/yellow/templates/user.html new file mode 100644 index 0000000..408f93f --- /dev/null +++ b/yellow/templates/user.html @@ -0,0 +1,42 @@ +{% extends "base.html" %} +{% block content %} +
+{% block title %}YellWOWPages - User{% endblock %} +
+ +
+ {% include 'includes/search.html' %} + + {% if not users %} +
Nothing found... + {% else %} + {% include 'includes/user_results.html' %} + {% endif %} +
+ + + +{% endblock %} \ No newline at end of file