parent
4e2e93b43c
commit
82681eda15
5 changed files with 39 additions and 0 deletions
|
@ -11,6 +11,14 @@ class ScriptAudioForm(Form):
|
|||
description='arguments, separated by spaces')
|
||||
submit = SubmitField(u'Submit')
|
||||
|
||||
def populate_from_audiospec(self, audiospec):
|
||||
if 'nick' in audiospec:
|
||||
self.nick.data = audiospec['nick']
|
||||
if 'name' in audiospec:
|
||||
self.name.data = audiospec['name']
|
||||
if 'args' in audiospec:
|
||||
self.args.data = audiospec['args']
|
||||
|
||||
def validate_name(form, field):
|
||||
if '/' in field.data:
|
||||
raise ValidationError("Name cannot have slashes: "
|
||||
|
|
|
@ -11,6 +11,12 @@ class StaticAudioForm(Form):
|
|||
description='Full path to audio file')
|
||||
submit = SubmitField(u'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]
|
||||
|
||||
|
||||
def staticaudio_receive(form):
|
||||
return {
|
||||
|
|
|
@ -89,6 +89,27 @@ def addaudio_kind(kind):
|
|||
return render_template('add_audio_kind.html', form=form, kind=kind)
|
||||
|
||||
|
||||
@db.route('/edit/audio/<int:actionid>', methods=['GET', 'POST'])
|
||||
def edit_audio(actionid):
|
||||
model = get_model()
|
||||
audiospec = model.get_action_by_id(actionid)
|
||||
kind = audiospec['kind']
|
||||
Form, receiver = tuple(forms.get_audioform(kind))
|
||||
form = Form()
|
||||
if request.method == 'GET':
|
||||
form.populate_from_audiospec(audiospec)
|
||||
if request.method == 'POST' and form.validate():
|
||||
data = receiver(form)
|
||||
model.update_action(actionid, data)
|
||||
model.reload()
|
||||
return redirect(url_for('db.list'))
|
||||
return render_template('add_audio_kind.html',
|
||||
form=form,
|
||||
kind=kind,
|
||||
mode='edit',
|
||||
)
|
||||
|
||||
|
||||
@db.route('/edit/event/<alarmid>')
|
||||
def edit_event(alarmid):
|
||||
model = current_app.larigira.controller.monitor.model
|
||||
|
|
|
@ -34,6 +34,7 @@ $(function() {
|
|||
{% for a in actions %}
|
||||
<li>
|
||||
<strong> {{a.nick}} </strong>
|
||||
<small><a class="button" href="{{url_for('db.edit_audio', actionid=a.eid)}}">Edit</a></small>
|
||||
{{dict_table(a, ['nick'])}}
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
|
@ -62,6 +62,9 @@ class EventModel(object):
|
|||
def update_alarm(self, alarmid, new_fields={}):
|
||||
return self.alarms.update(new_fields, eids=[alarmid])
|
||||
|
||||
def update_action(self, actionid, new_fields={}):
|
||||
return self.actions.update(new_fields, eids=[actionid])
|
||||
|
||||
|
||||
class Monitor(ParentedLet):
|
||||
'''
|
||||
|
|
Loading…
Reference in a new issue