From 556783c2ab7531c44173c4a7664cba7a04117d94 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 15 Sep 2016 09:44:44 +0200 Subject: [PATCH] add WebUI for randomdir audiogen fix #25 --- larigira/audioform_randomdir.py | 34 +++++++++++++++++++++++++++++++++ setup.py | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 larigira/audioform_randomdir.py diff --git a/larigira/audioform_randomdir.py b/larigira/audioform_randomdir.py new file mode 100644 index 0000000..c4a4c03 --- /dev/null +++ b/larigira/audioform_randomdir.py @@ -0,0 +1,34 @@ +import flask_wtf +from wtforms import StringField, validators, SubmitField, IntegerField + + +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') + howmany = IntegerField('Number', validators=[validators.optional()], + default=1, + description='How many songs to be picked' + 'from this dir; defaults to 1') + submit = SubmitField('Submit') + + def populate_from_audiospec(self, audiospec): + if 'nick' in audiospec: + self.nick.data = audiospec['nick'] + if 'paths' in audiospec: + self.path.data = audiospec['paths'][0] + if 'howmany' in audiospec: + self.howmany.data = audiospec['howmany'] + else: + self.howmany.data = 1 + + +def receive(form): + return { + 'kind': 'randomdir', + 'nick': form.nick.data, + 'paths': [form.path.data], + 'howmany': form.howmany.data or 1 + } + diff --git a/setup.py b/setup.py index 3aec485..e8cfb72 100644 --- a/setup.py +++ b/setup.py @@ -77,10 +77,12 @@ setup(name='larigira', 'larigira.audioform_create': [ 'static = larigira.audioform_static:StaticAudioForm', 'script = larigira.audioform_script:ScriptAudioForm', + 'randomdir = larigira.audioform_randomdir:Form', ], 'larigira.audioform_receive': [ 'static = larigira.audioform_static:staticaudio_receive', 'script = larigira.audioform_script:scriptaudio_receive', + 'randomdir = larigira.audioform_randomdir:receive', ], }, classifiers=[