wip describe file now shows the files to be described

This commit is contained in:
crunk 2024-05-27 18:54:55 +02:00
parent 30f69cf03c
commit 8cf5ca198b
5 changed files with 55 additions and 12 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@
*.pyc
*.egg-info/
.eggs/
.ruff_cache
build/
dist/
pip-wheel-metadata/

View File

@ -1,4 +1,10 @@
from flask import Blueprint, render_template, redirect, url_for
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
@ -31,7 +37,9 @@ def show_distribusi_files(distribusiname):
@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)
describe_form = DescribeFilesForm(
distribusi_file.id, distribusi_file.path, distribusi_file.type
)
print(
f"file: {describe_form.file_path} description: {describe_form.description.data}"
)
@ -41,14 +49,20 @@ def describe_file(file_id):
print(
f"file: {describe_form.file_path} alttext: {describe_form.alttext.data}"
)
distribusi_file_forms = get_distribusi_file_forms(
distribusi_file.distribusi
)
return render_template(
"describe.html",
distribusi_file_forms=distribusi_file_forms,
distribusi = Distribusis.query.filter_by(
id=distribusi_file.distribusi
).first()
return redirect(
url_for(
"describer.show_distribusi_files",
distribusiname=distribusi.distribusiname,
)
)
@describer.route("/stash/<path:path>")
def send_stash_file(path):
return send_from_directory("stash", path)
def get_distribusi_file_forms(distribusi_id):
distribusi_file_forms = {}
@ -57,7 +71,7 @@ def get_distribusi_file_forms(distribusi_id):
).all()
for distribusi_file in distribusi_files:
describe_form = DescribeFilesForm(
distribusi_file.id, distribusi_file.path
distribusi_file.id, distribusi_file.path, distribusi_file.type
)
describe_form.description.data = distribusi_file.description
describe_form.alttext.data = distribusi_file.alttext

View File

@ -30,10 +30,11 @@ class DescribeFilesForm(FlaskForm):
)
save = SubmitField("Save")
def __init__(self, id, file_path=None):
def __init__(self, id, file_path=None, type=None):
super(DescribeFilesForm, self).__init__()
self.id = id
self.file_path = file_path
self.type = type
self.alttext.id = f"alttext-{id}"
self.searchtags.id = f"searchtags-{id}"
self.description.id = f"description-{id}"

View File

@ -28,10 +28,19 @@
</div>
<div class="distribusi_files">
{% for id, describe_form in distribusi_file_forms.items() %}
<div class="distribusi_file">
{% if describe_form.type == "image" %}
<img src="{{describe_form.file_path}}" alt="" />
{% elif describe_form.type == "video" %}
<video src="{{describe_form.file_path}}" preload="auto" alt="" controls></video>
{% elif describe_form.type == "audio" %}
<audio src="{{describe_form.file_path}}" preload="auto" alt="" controls></audio>
{% else %}
<a href="{{describe_form.file_path}}">file: {{describe_form.file_path}}</a>
{% endif %}
<form id={{id}} method="POST" enctype="multipart/form-data" action="{{ url_for('describer.describe_file', file_id=id) }}">
{{ describe_form.csrf_token }}
<p>{{describe_form.id}}</p>
<p>{{describe_form.file_path}}</p>
<p>File path: {{describe_form.file_path}}</p>
<fieldset class="">
{{ describe_form.description.label }}
{{ describe_form.description }}
@ -57,6 +66,7 @@
{{ describe_form.save }}
</fieldset>
</form>
</div>
{% endfor%}
</div>

View File

@ -174,6 +174,23 @@ a:active {
content: "$ ";
}
.distribusi_file {
margin-top: 1em;
padding: 0.5em;
padding-left: auto;
padding-right: auto;
width: 45em;
background-color:#fdfdfd;
text-decoration: none;
scroll-behavior: smooth;
border-style: outset;
}
.distribusi_file > img, video {
max-width: 100%;
max-height: 100%;
}
@media (prefers-reduced-motion: no-preference) {
@keyframes flash {
50% { opacity: 0; }