Test for & display invalid search errors on profile page, too

I was there indeed
This commit is contained in:
наб 2020-09-10 20:45:18 +02:00 committed by Drew DeVault
parent 134c1f27d6
commit df5ddcc3cb
2 changed files with 9 additions and 5 deletions

View File

@ -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:
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)

View File

@ -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 %}
<div class="invalid-feedback">{{ search_error }}</div>
{% endif %}