WebUI autocomplete scripts

This commit is contained in:
boyska 2017-01-03 20:40:56 +01:00
parent ef44b06bfb
commit 2e983ffed2
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9
2 changed files with 15 additions and 3 deletions

View file

@ -1,12 +1,15 @@
from flask_wtf import Form
from wtforms import StringField, validators, SubmitField, ValidationError
from larigira.formutils import AutocompleteStringField
class ScriptAudioForm(Form):
nick = StringField('Audio nick', validators=[validators.required()],
description='A simple name to recognize this audio')
name = StringField('Name', validators=[validators.required()],
description='filename (NOT path) of the script')
name = AutocompleteStringField(
'dl-suggested-scripts',
'Name', validators=[validators.required()],
description='filename (NOT path) of the script')
args = StringField('Arguments',
description='arguments, separated by ";"')
submit = SubmitField('Submit')

View file

@ -56,6 +56,13 @@ def get_suggested_dirs():
return list(dirset)
def get_suggested_scripts():
base = get_conf()['SCRIPTS_PATH']
fnames = [f for f in os.listdir(base)
if os.access(os.path.join(base, f), os.R_OK | os.X_OK)]
return fnames
def get_suggestions():
files = get_suggested_files()
if len(files) > 200:
@ -63,7 +70,9 @@ def get_suggestions():
files = files[:200]
return dict(
files=files,
dirs=get_suggested_dirs())
dirs=get_suggested_dirs(),
scripts=get_suggested_scripts(),
)
@db.route('/')