main #12
@ -2,7 +2,7 @@ from flask import Blueprint, render_template, redirect, url_for
|
|||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from models.distribusi_model import Distribusis
|
from models.distribusi_model import Distribusis
|
||||||
from models.distribusi_file_model import DistribusiFiles
|
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 = Blueprint(
|
||||||
"describer",
|
"describer",
|
||||||
@ -14,29 +14,53 @@ describer = Blueprint(
|
|||||||
|
|
||||||
@describer.route("/<string:distribusiname>")
|
@describer.route("/<string:distribusiname>")
|
||||||
@login_required
|
@login_required
|
||||||
def describe_distribusi_files(distribusiname):
|
def show_distribusi_files(distribusiname):
|
||||||
if not current_user.is_authenticated:
|
if not current_user.is_authenticated:
|
||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
distribusi = Distribusis.query.filter_by(
|
distribusi = Distribusis.query.filter_by(
|
||||||
distribusiname=distribusiname
|
distribusiname=distribusiname
|
||||||
).first()
|
).first()
|
||||||
distribusi_files = DistribusiFiles.query.filter_by(
|
distribusi_file_forms = get_distribusi_file_forms(distribusi.id)
|
||||||
distribusi=distribusi.id
|
|
||||||
).all()
|
|
||||||
# distribusi_file_forms = {}
|
|
||||||
# for distribusi_file in distribusi_files:
|
|
||||||
describe_form = DescribeFileForm()
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"describe.html",
|
"describe.html",
|
||||||
distribusi_files=distribusi_files,
|
distribusi_file_forms=distribusi_file_forms,
|
||||||
describe_form=describe_form,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@describer.route("/describe_file", methods=["POST"])
|
@describer.route("/describe_file/<int:file_id>", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def describe_file(file_name):
|
def describe_file(file_id):
|
||||||
describe_form = DescribeFileForm()
|
distribusi_file = DistribusiFiles.query.filter_by(id=file_id).first()
|
||||||
if describe_form.validate_on_submit():
|
describe_form = DescribeFilesForm(distribusi_file.id, distribusi_file.path)
|
||||||
print(f"{file_name} description: {describe_form.description.data}")
|
print(
|
||||||
return
|
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>
|
</div>
|
||||||
<div class="distribusi_files">
|
<div class="distribusi_files">
|
||||||
{% for file in distribusi_files %}
|
{% for id, describe_form in distribusi_file_forms.items() %}
|
||||||
<p>{{file.path}}</p>
|
<form id={{id}} method="POST" enctype="multipart/form-data" action="{{ url_for('describer.describe_file', file_id=id) }}">
|
||||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('describer.describe_file') }}">
|
|
||||||
{{ describe_form.csrf_token }}
|
{{ describe_form.csrf_token }}
|
||||||
|
<p>{{describe_form.id}}</p>
|
||||||
|
<p>{{describe_form.file_path}}</p>
|
||||||
<fieldset class="">
|
<fieldset class="">
|
||||||
{{ describe_form.description.label }}
|
{{ describe_form.description.label }}
|
||||||
{{ describe_form.description }}
|
{{ describe_form.description }}
|
||||||
|
@ -69,7 +69,7 @@ def SelectNewDistribusi():
|
|||||||
def SelectDescribeDistribusi(distribusiname):
|
def SelectDescribeDistribusi(distribusiname):
|
||||||
return redirect(
|
return redirect(
|
||||||
url_for(
|
url_for(
|
||||||
"describer.describe_distribusi_files",
|
"describer.show_distribusi_files",
|
||||||
distribusiname=distribusiname,
|
distribusiname=distribusiname,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -70,4 +70,4 @@ def add_distribusi_files(path):
|
|||||||
_distribusi_file_with_type(distribusi, full_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 flask_wtf.csrf import CSRFError
|
||||||
|
|
||||||
from adminpage import AdminPage
|
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 describer.describe_files import describer
|
||||||
from distribusikan.distribusikan import distribusikan
|
from distribusikan.distribusikan import distribusikan
|
||||||
from distribusikan.distribusisinfo import DistribusisInfo
|
from distribusikan.distribusisinfo import DistribusisInfo
|
||||||
@ -112,7 +112,7 @@ def handle_csrf_error(e):
|
|||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
def load_user(user_id):
|
def load_user(user_id):
|
||||||
return User.query.get(int(user_id))
|
return db.session.get(User, int(user_id))
|
||||||
|
|
||||||
|
|
||||||
def is_adminuser():
|
def is_adminuser():
|
||||||
|
Loading…
Reference in New Issue
Block a user