From df5ddcc3cb4036e4c4224ff44e5cc9f053bfd86f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 10 Sep 2020 20:45:18 +0200 Subject: [PATCH] Test for & display invalid search errors on profile page, too I was there indeed --- hubsrht/blueprints/users.py | 10 +++++++--- hubsrht/templates/projects.html | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/hubsrht/blueprints/users.py b/hubsrht/blueprints/users.py index 8617ecf..0528a20 100644 --- a/hubsrht/blueprints/users.py +++ b/hubsrht/blueprints/users.py @@ -55,11 +55,15 @@ def projects_GET(owner): projects = projects.filter(Project.visibility == Visibility.public) search = request.args.get("search") + search_error = None if search: - projects = search_by(projects, search, - [Project.name, Project.description]) + try: + projects = search_by(projects, search, + [Project.name, Project.description]) + except ValueError as e: + search_error = str(e) projects, pagination = paginate_query(projects) return render_template("projects.html", user=owner, projects=projects, - search=search, **pagination) + search=search, search_error=search_error, **pagination) diff --git a/hubsrht/templates/projects.html b/hubsrht/templates/projects.html index ad43d8d..5c50c87 100644 --- a/hubsrht/templates/projects.html +++ b/hubsrht/templates/projects.html @@ -35,8 +35,8 @@ name="search" type="text" placeholder="Search {{user.canonical_name}}'s projects" - class="form-control" - value="{{search if search else ""}}" /> + class="form-control {% if search_error %}is-invalid{% endif %}" + value="{{search or ""}}" /> {% if search_error %}
{{ search_error }}
{% endif %}