Option redirect=true pour une recherche en ligne

Modification du schéma sqlite:
`ALTER TABLE search_results ADD url TEXT;;`
This commit is contained in:
augustin64 2022-10-28 23:01:02 +02:00
parent cd2789e4fc
commit 234e0f784f
3 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,7 @@
Partition module
"""
import os
from flask import Blueprint, abort, send_file, render_template
from flask import Blueprint, abort, send_file, render_template, request, redirect
from .db import get_db
from .auth import login_required, admin_required
@ -38,7 +38,7 @@ def partition_search(uuid):
db = get_db()
partition = db.execute(
"""
SELECT * FROM search_results
SELECT uuid, url FROM search_results
WHERE uuid = ?
""",
(uuid,)
@ -46,6 +46,8 @@ def partition_search(uuid):
if partition is None:
abort(404)
if request.args.get("redirect") == "true" and partition["url"] is not None:
return redirect(partition["url"])
return send_file(os.path.join("search-partitions", f"{uuid}.pdf"))

View File

@ -59,10 +59,10 @@ def online_search(query, num_queries):
uuid = str(uuid4())
db.execute(
"""
INSERT INTO search_results (uuid)
VALUES (?)
INSERT INTO search_results (uuid, url)
VALUES (?, ?)
""",
(uuid,)
(uuid, element,)
)
db.commit()
urllib.request.urlretrieve(element, f"partitioncloud/search-partitions/{uuid}.pdf")

View File

@ -39,5 +39,6 @@ CREATE TABLE contient_user (
CREATE TABLE search_results (
uuid TEXT(36) PRIMARY KEY,
url TEXT,
creation_time TEXT NULL DEFAULT (datetime('now', 'localtime'))
);