Test for & display invalid search errors

Hi nab-was-here
This commit is contained in:
Drew DeVault 2020-09-10 10:09:03 -04:00
parent c212995eef
commit 134c1f27d6
2 changed files with 8 additions and 4 deletions

View File

@ -45,9 +45,13 @@ def project_index():
.filter(Project.checklist_complete))
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)
sort = request.args.get("sort")
if sort and sort == "recently-updated":
@ -68,7 +72,7 @@ def project_index():
return render_template("project-index.html", projects=projects,
search=search, features=features, sort=sort, **pagination,
search_keys=["sort"])
search_keys=["sort"], search_error=search_error)
@public.route("/projects/featured")
def featured_projects():

View File

@ -12,7 +12,7 @@
name="search"
type="text"
placeholder="Search all public projects"
class="form-control"
class="form-control {% if search_error %} is-invalid{% endif %}"
value="{{search if search else ""}}" />
{% if search_error %}
<div class="invalid-feedback">{{ search_error }}</div>