from flask import ( Blueprint, render_template, redirect, url_for, send_from_directory, ) from flask_login import current_user, login_required from models.distribusi_model import Distribusis from models.distribusi_file_model import DistribusiFiles from describer.forms.describe_files_form import DescribeFilesForm describer = Blueprint( "describer", __name__, template_folder="templates/describe_files", static_folder="static", ) @describer.route("/") @login_required def show_distribusi_files(distribusiname): if not current_user.is_authenticated: return redirect(url_for("index")) distribusi = Distribusis.query.filter_by( distribusiname=distribusiname ).first() distribusi_file_forms = get_distribusi_file_forms(distribusi.id) return render_template( "describe.html", distribusi_file_forms=distribusi_file_forms, ) @describer.route("/describe_file/", methods=["POST"]) @login_required def describe_file(file_id): distribusi_file = DistribusiFiles.query.filter_by(id=file_id).first() describe_form = DescribeFilesForm( distribusi_file.id, distribusi_file.path, distribusi_file.type ) print( f"file: {describe_form.file_path} description: {describe_form.description.data}" ) print( f"file: {describe_form.file_path} searchtags: {describe_form.searchtags.data}" ) print( f"file: {describe_form.file_path} alttext: {describe_form.alttext.data}" ) distribusi = Distribusis.query.filter_by( id=distribusi_file.distribusi ).first() return redirect( url_for( "describer.show_distribusi_files", distribusiname=distribusi.distribusiname, ) ) @describer.route("/stash/") def send_stash_file(path): return send_from_directory("stash", path) def get_distribusi_file_forms(distribusi_id): distribusi_file_forms = {} distribusi_files = DistribusiFiles.query.filter_by( distribusi=distribusi_id ).all() for distribusi_file in distribusi_files: describe_form = DescribeFilesForm( distribusi_file.id, distribusi_file.path, distribusi_file.type ) describe_form.description.data = distribusi_file.description describe_form.alttext.data = distribusi_file.alttext describe_form.searchtags.data = distribusi_file.tags distribusi_file_forms[distribusi_file.id] = describe_form return distribusi_file_forms