Expand search to handle results, search submission

This commit is contained in:
Kiril Kovachev 2024-10-14 12:33:37 +01:00
parent 7b0cc42775
commit 45c263602b
3 changed files with 31 additions and 2 deletions

View File

@ -1,7 +1,16 @@
from flask import Blueprint, render_template from flask import Blueprint, render_template, request
blueprint = Blueprint("search", __name__, url_prefix="/search") blueprint = Blueprint("search", __name__, url_prefix="/search")
def search_results(args: dict):
class renderable:
def render(self):
return "ok"
results = [renderable(), renderable()] # Do something with args
return render_template("search/search_results.html", results=results, value=args["keywords"])
@blueprint.route("/") @blueprint.route("/")
def search_page(): def search_page():
if request.args:
return search_results(request.args)
return render_template("search/search.html") return render_template("search/search.html")

View File

@ -5,5 +5,14 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<input type="text" id="search_bar" placeholder="{{ localize("search_placeholder") }}"> <form method="get">
<label for="search_bar">Search</label>
<input type="text" id="search_bar" name="keywords" placeholder="{{ localize("search_placeholder") }}" value="{{value}}">
<label for="include_kanji">Include kanji</label>
<input type="checkbox" id="include_kanji" checked>
<label for="include_kanji">Include kotoba</label>
<input type="checkbox" id="include_kanji" checked>
</form>
{% block results %}
{% endblock %}
{% endblock %} {% endblock %}

View File

@ -0,0 +1,11 @@
{% extends 'search/search.html' %}
{% block results %}
{% for result in results %}
<div class="result">
{{result.render()}}
</div>
{% endfor %}
{% endblock%}