partitioncloud-server/partitioncloud/modules/partition.py

56 lines
1.2 KiB
Python
Raw Normal View History

2022-08-16 18:13:00 +02:00
#!/usr/bin/python3
"""
Partition module
"""
import os
from flask import Blueprint, abort, send_file, render_template
2022-08-16 18:13:00 +02:00
from .db import get_db
from .auth import login_required, admin_required
from .utils import get_all_partitions
2022-08-16 18:13:00 +02:00
bp = Blueprint("partition", __name__, url_prefix="/partition")
@bp.route("/<uuid>")
@login_required
def partition(uuid):
db = get_db()
partition = db.execute(
"""
SELECT * FROM partition
WHERE uuid = ?
""",
(uuid,)
).fetchone()
if partition is None:
abort(404)
2022-10-03 20:45:10 +02:00
return send_file(
os.path.join("partitions", f"{uuid}.pdf"),
download_name = f"{partition['name']}.pdf"
)
2022-08-17 09:44:31 +02:00
@bp.route("/search/<uuid>")
@login_required
def partition_search(uuid):
db = get_db()
partition = db.execute(
"""
SELECT * FROM search_results
WHERE uuid = ?
""",
(uuid,)
).fetchone()
if partition is None:
abort(404)
return send_file(os.path.join("search-partitions", f"{uuid}.pdf"))
@bp.route("/")
@admin_required
def index():
partitions = get_all_partitions().fetchall()
2022-08-31 13:54:13 +02:00
return render_template("admin/partitions.html", partitions=partitions)