Add search

This commit is contained in:
sqozz 2017-12-28 04:19:04 +01:00
parent 9eddb24fc2
commit 17c833a616
3 changed files with 32 additions and 2 deletions

View file

@ -31,7 +31,15 @@ def create():
def search():
global strings
print(strings)
return render_template("result.html", results=request.args.get("q", ""), strings=strings, language="english", categories=settings["categories"])
connection = sqlite3.connect("torrentdb.sqlite")
c = connection.cursor()
term = request.args.get("q", "")
terms = term.split(" ")
terms = list(map(lambda x: "%" + x + "%", terms))
search = " AND ".join(["name LIKE (?)"] * len(terms))
c.execute("SELECT fileid, name FROM torrents WHERE " + search, terms)
results = c.fetchall()
return render_template("result.html", results=results, strings=strings, language="english", categories=settings["categories"])
def init():
global strings

4
static/css/result.css Normal file
View file

@ -0,0 +1,4 @@
table, th, td {
width: 100%;
border: 1px solid white;
}

View file

@ -5,5 +5,23 @@ vim: ts=2 noexpandtab
{% block title %}{{ super() }} - Results{% endblock%}
{% set active_page = "search" %}
{% block content %}
<p>{{results}}</p>
<link href="{{ url_for("static", filename="css/result.css") }}" rel="stylesheet">
<table>
<tr>
<th>Name</th>
<th>Size</th>
<th>Snatches</th>
<th>UL</th>
<th>DL</th>
</tr>
<tr>
{% for result in results %}
<td>{{ result[1] }}</td>
<td>test</td>
<td>N/A</td>
<td>N/A</td>
<td>N/A</td>
{% endfor %}
</tr>
</table>
{% endblock content%}