wip describe file form part 2
This commit is contained in:
parent
d301ab8b53
commit
30f69cf03c
@ -2,7 +2,7 @@ from flask import Blueprint, render_template, redirect, url_for
|
||||
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_file_form import DescribeFileForm
|
||||
from describer.forms.describe_files_form import DescribeFilesForm
|
||||
|
||||
describer = Blueprint(
|
||||
"describer",
|
||||
@ -14,29 +14,53 @@ describer = Blueprint(
|
||||
|
||||
@describer.route("/<string:distribusiname>")
|
||||
@login_required
|
||||
def describe_distribusi_files(distribusiname):
|
||||
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_files = DistribusiFiles.query.filter_by(
|
||||
distribusi=distribusi.id
|
||||
).all()
|
||||
# distribusi_file_forms = {}
|
||||
# for distribusi_file in distribusi_files:
|
||||
describe_form = DescribeFileForm()
|
||||
distribusi_file_forms = get_distribusi_file_forms(distribusi.id)
|
||||
return render_template(
|
||||
"describe.html",
|
||||
distribusi_files=distribusi_files,
|
||||
describe_form=describe_form,
|
||||
distribusi_file_forms=distribusi_file_forms,
|
||||
)
|
||||
|
||||
|
||||
@describer.route("/describe_file", methods=["POST"])
|
||||
@describer.route("/describe_file/<int:file_id>", methods=["POST"])
|
||||
@login_required
|
||||
def describe_file(file_name):
|
||||
describe_form = DescribeFileForm()
|
||||
if describe_form.validate_on_submit():
|
||||
print(f"{file_name} description: {describe_form.description.data}")
|
||||
return
|
||||
def describe_file(file_id):
|
||||
distribusi_file = DistribusiFiles.query.filter_by(id=file_id).first()
|
||||
describe_form = DescribeFilesForm(distribusi_file.id, distribusi_file.path)
|
||||
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_file_forms = get_distribusi_file_forms(
|
||||
distribusi_file.distribusi
|
||||
)
|
||||
return render_template(
|
||||
"describe.html",
|
||||
distribusi_file_forms=distribusi_file_forms,
|
||||
)
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
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
|
||||
|
@ -1,29 +0,0 @@
|
||||
"""Describe File Form to describe files in the distribusi archive"""
|
||||
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField, validators
|
||||
from wtforms.validators import Length
|
||||
|
||||
|
||||
class DescribeFileForm(FlaskForm):
|
||||
"""DescribeFileForm selection form."""
|
||||
|
||||
alttext = StringField(
|
||||
"Alt-text for this file:",
|
||||
validators=[
|
||||
Length(3, 255),
|
||||
],
|
||||
)
|
||||
searchtags = StringField(
|
||||
"Add search tags, seperated by commas. No need for the '#' sign:",
|
||||
validators=[
|
||||
Length(3, 500),
|
||||
],
|
||||
)
|
||||
description = StringField(
|
||||
"Description of this file:",
|
||||
validators=[
|
||||
Length(3, 4096),
|
||||
],
|
||||
)
|
||||
save = SubmitField("Save")
|
47
verse/describer/forms/describe_files_form.py
Normal file
47
verse/describer/forms/describe_files_form.py
Normal file
@ -0,0 +1,47 @@
|
||||
"""Describe File Form to describe files in the distribusi archive"""
|
||||
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField, validators
|
||||
from wtforms.validators import Length
|
||||
from wtforms.widgets import TextArea
|
||||
|
||||
|
||||
class DescribeFilesForm(FlaskForm):
|
||||
"""DescribeFileForm selection form."""
|
||||
|
||||
alttext = StringField(
|
||||
"Alt-text for this file:",
|
||||
validators=[
|
||||
Length(3, 255),
|
||||
],
|
||||
)
|
||||
searchtags = StringField(
|
||||
"Add search tags, seperated by commas. No need for the '#' sign:",
|
||||
validators=[
|
||||
Length(3, 500),
|
||||
],
|
||||
)
|
||||
description = StringField(
|
||||
"Description of this file:",
|
||||
validators=[
|
||||
Length(3, 4096),
|
||||
],
|
||||
widget=TextArea(),
|
||||
)
|
||||
save = SubmitField("Save")
|
||||
|
||||
def __init__(self, id, file_path=None):
|
||||
super(DescribeFilesForm, self).__init__()
|
||||
self.id = id
|
||||
self.file_path = file_path
|
||||
self.alttext.id = f"alttext-{id}"
|
||||
self.searchtags.id = f"searchtags-{id}"
|
||||
self.description.id = f"description-{id}"
|
||||
self.save.id = f"save-{id}"
|
||||
|
||||
|
||||
# def StringFieldWithId(form_name, **kwargs):
|
||||
# name = kwargs.get('name', 'Bar')
|
||||
# return wtf.StringField(name, render_kw={
|
||||
# 'id': f'{}{}'.format(form_name, name.lower(),
|
||||
# **kwargs.get('render_kw', {})})
|
@ -27,10 +27,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="distribusi_files">
|
||||
{% for file in distribusi_files %}
|
||||
<p>{{file.path}}</p>
|
||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('describer.describe_file') }}">
|
||||
{% for id, describe_form in distribusi_file_forms.items() %}
|
||||
<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>
|
||||
<fieldset class="">
|
||||
{{ describe_form.description.label }}
|
||||
{{ describe_form.description }}
|
||||
|
@ -69,7 +69,7 @@ def SelectNewDistribusi():
|
||||
def SelectDescribeDistribusi(distribusiname):
|
||||
return redirect(
|
||||
url_for(
|
||||
"describer.describe_distribusi_files",
|
||||
"describer.show_distribusi_files",
|
||||
distribusiname=distribusiname,
|
||||
)
|
||||
)
|
||||
|
@ -70,4 +70,4 @@ def add_distribusi_files(path):
|
||||
_distribusi_file_with_type(distribusi, full_path)
|
||||
|
||||
|
||||
add_distribusi_files("2018-12-WttF-Mastodon-and-the-Fediverse")
|
||||
add_distribusi_files("2018-02-16-Extratonality")
|
||||
|
@ -14,7 +14,7 @@ from flask_login import current_user, login_required, logout_user
|
||||
from flask_wtf.csrf import CSRFError
|
||||
|
||||
from adminpage import AdminPage
|
||||
from app import create_app, login_manager
|
||||
from app import db, create_app, login_manager
|
||||
from describer.describe_files import describer
|
||||
from distribusikan.distribusikan import distribusikan
|
||||
from distribusikan.distribusisinfo import DistribusisInfo
|
||||
@ -112,7 +112,7 @@ def handle_csrf_error(e):
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
return db.session.get(User, int(user_id))
|
||||
|
||||
|
||||
def is_adminuser():
|
||||
|
Loading…
Reference in New Issue
Block a user