WebUI completion for dirs
This commit is contained in:
parent
e6bee6865f
commit
ef44b06bfb
4 changed files with 46 additions and 13 deletions
|
@ -2,12 +2,15 @@ from pytimeparse.timeparse import timeparse
|
|||
from flask_wtf import Form
|
||||
from wtforms import StringField, validators, SubmitField, ValidationError
|
||||
|
||||
from larigira.formutils import AutocompleteStringField
|
||||
|
||||
|
||||
class AudioForm(Form):
|
||||
nick = StringField('Audio nick', validators=[validators.required()],
|
||||
description='A simple name to recognize this audio')
|
||||
path = StringField('Path', validators=[validators.required()],
|
||||
description='Directory to pick file from')
|
||||
path = AutocompleteStringField('dl-suggested-dirs',
|
||||
'Path', validators=[validators.required()],
|
||||
description='Directory to pick file from')
|
||||
maxage = StringField('Max age',
|
||||
validators=[validators.required()],
|
||||
description='in seconds, or human-readable '
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import flask_wtf
|
||||
from wtforms import StringField, validators, SubmitField, IntegerField
|
||||
|
||||
from larigira.formutils import AutocompleteStringField
|
||||
|
||||
|
||||
class Form(flask_wtf.Form):
|
||||
nick = StringField('Audio nick', validators=[validators.required()],
|
||||
description='A simple name to recognize this audio')
|
||||
path = StringField('Path', validators=[validators.required()],
|
||||
description='Full path to source directory')
|
||||
path = AutocompleteStringField('dl-suggested-dirs',
|
||||
'Path', validators=[validators.required()],
|
||||
description='Full path to source directory')
|
||||
howmany = IntegerField('Number', validators=[validators.optional()],
|
||||
default=1,
|
||||
description='How many songs to be picked'
|
||||
|
|
|
@ -43,6 +43,29 @@ def get_suggested_files():
|
|||
return files
|
||||
|
||||
|
||||
def get_suggested_dirs():
|
||||
dirset = set()
|
||||
for f in get_suggested_files():
|
||||
dirpath = os.path.dirname(f)
|
||||
while dirpath:
|
||||
if dirpath in dirset:
|
||||
break
|
||||
dirset.add(dirpath)
|
||||
dirpath = os.path.dirname(dirpath)
|
||||
|
||||
return list(dirset)
|
||||
|
||||
|
||||
def get_suggestions():
|
||||
files = get_suggested_files()
|
||||
if len(files) > 200:
|
||||
current_app.logger.warn("Too many suggested files, cropping")
|
||||
files = files[:200]
|
||||
return dict(
|
||||
files=files,
|
||||
dirs=get_suggested_dirs())
|
||||
|
||||
|
||||
@db.route('/')
|
||||
def home():
|
||||
return render_template('dbadmin_base.html')
|
||||
|
@ -81,7 +104,8 @@ def edit_time(alarmid):
|
|||
data = receiver(form)
|
||||
model.update_alarm(alarmid, data)
|
||||
model.reload()
|
||||
return redirect(url_for('db.list', _anchor='event-%d' % alarmid))
|
||||
return redirect(url_for('db.events_list',
|
||||
_anchor='event-%d' % alarmid))
|
||||
return render_template('add_time_kind.html',
|
||||
form=form,
|
||||
kind=kind,
|
||||
|
@ -124,7 +148,8 @@ def addaudio_kind(kind):
|
|||
return jsonify(dict(inserted=eid, data=data))
|
||||
|
||||
return render_template('add_audio_kind.html', form=form, kind=kind,
|
||||
suggested_files=get_suggested_files())
|
||||
suggestions=get_suggestions()
|
||||
)
|
||||
|
||||
|
||||
@db.route('/edit/audio/<int:actionid>', methods=['GET', 'POST'])
|
||||
|
@ -140,12 +165,12 @@ def edit_audio(actionid):
|
|||
data = receiver(form)
|
||||
model.update_action(actionid, data)
|
||||
model.reload()
|
||||
return redirect(url_for('db.list'))
|
||||
return redirect(url_for('db.events_list'))
|
||||
return render_template('add_audio_kind.html',
|
||||
form=form,
|
||||
kind=kind,
|
||||
mode='edit',
|
||||
suggested_files=get_suggested_files()
|
||||
suggestions=get_suggestions()
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -10,11 +10,13 @@
|
|||
resubmit
|
||||
</div>
|
||||
{% endif %}
|
||||
<datalist id="dl-suggested-files">
|
||||
{% for fname in suggested_files %}
|
||||
<option value="{{fname}}">
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
{% for category in suggestions %}
|
||||
<datalist id="dl-suggested-{{category}}">
|
||||
{% for fname in suggestions[category] %}
|
||||
<option value="{{fname}}">
|
||||
{% endfor %}
|
||||
</datalist>
|
||||
{% endfor %}
|
||||
<div class="container-fluid">
|
||||
{{wtf.quick_form(form)}}
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue