parent
d7fcdd3f09
commit
4e2e93b43c
5 changed files with 53 additions and 7 deletions
|
@ -13,6 +13,10 @@ from larigira import forms
|
||||||
db = Blueprint('db', __name__, url_prefix='/db', template_folder='templates')
|
db = Blueprint('db', __name__, url_prefix='/db', template_folder='templates')
|
||||||
|
|
||||||
|
|
||||||
|
def get_model():
|
||||||
|
return current_app.larigira.controller.monitor.model
|
||||||
|
|
||||||
|
|
||||||
@db.route('/')
|
@db.route('/')
|
||||||
def home():
|
def home():
|
||||||
return render_template('dbadmin_base.html')
|
return render_template('dbadmin_base.html')
|
||||||
|
@ -33,17 +37,37 @@ def addtime():
|
||||||
return render_template('add_time.html', kinds=kinds)
|
return render_template('add_time.html', kinds=kinds)
|
||||||
|
|
||||||
|
|
||||||
|
@db.route('/edit/time/<int:alarmid>', methods=['GET', 'POST'])
|
||||||
|
def edit_time(alarmid):
|
||||||
|
model = get_model()
|
||||||
|
timespec = model.get_alarm_by_id(alarmid)
|
||||||
|
kind = timespec['kind']
|
||||||
|
Form, receiver = tuple(forms.get_timeform(kind))
|
||||||
|
form = Form()
|
||||||
|
if request.method == 'GET':
|
||||||
|
form.populate_from_timespec(timespec)
|
||||||
|
if request.method == 'POST' and form.validate():
|
||||||
|
data = receiver(form)
|
||||||
|
model.update_alarm(alarmid, data)
|
||||||
|
model.reload()
|
||||||
|
return redirect(url_for('db.list', _anchor='event-%d' % alarmid))
|
||||||
|
return render_template('add_time_kind.html',
|
||||||
|
form=form,
|
||||||
|
kind=kind,
|
||||||
|
mode='edit',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@db.route('/add/time/<kind>', methods=['GET', 'POST'])
|
@db.route('/add/time/<kind>', methods=['GET', 'POST'])
|
||||||
def addtime_kind(kind):
|
def addtime_kind(kind):
|
||||||
Form, receiver = tuple(forms.get_timeform(kind))
|
Form, receiver = tuple(forms.get_timeform(kind))
|
||||||
form = Form()
|
form = Form()
|
||||||
if request.method == 'POST' and form.validate():
|
if request.method == 'POST' and form.validate():
|
||||||
data = receiver(form)
|
data = receiver(form)
|
||||||
model = current_app.larigira.controller.monitor.model
|
eid = get_model().add_alarm(data)
|
||||||
eid = model.add_alarm(data)
|
|
||||||
return redirect(url_for('db.edit_event', alarmid=eid))
|
return redirect(url_for('db.edit_event', alarmid=eid))
|
||||||
|
|
||||||
return render_template('add_time_kind.html', form=form, kind=kind)
|
return render_template('add_time_kind.html', form=form, kind=kind, mode='add')
|
||||||
|
|
||||||
|
|
||||||
@db.route('/add/audio')
|
@db.route('/add/audio')
|
||||||
|
|
|
@ -10,6 +10,11 @@
|
||||||
resubmit
|
resubmit
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if mode == 'edit' %}
|
||||||
|
<div class="alert alert-info">
|
||||||
|
<strong>Note:</strong> You can change parameters, but you cannot change the <em>kind</em> of this alarm (yet)
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
{{wtf.quick_form(form)}}
|
{{wtf.quick_form(form)}}
|
||||||
|
|
|
@ -17,17 +17,19 @@ $(function() {
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
{% for e, actions in events %}
|
{% for e, actions in events %}
|
||||||
<div class="event row">
|
<div class="event row" id="event-{{e.eid}}">
|
||||||
<h2>Event {{e.eid}} <small>{{e.nick if 'nick'}}</small> </h2>
|
<h2>Event {{e.eid}} <small>{{e.nick if 'nick'}}</small> </h2>
|
||||||
<div class="col-md-8">
|
<div class="col-md-8">
|
||||||
<h3>Time</h3>
|
<h3>Time</h3>
|
||||||
|
<a class="button" href="{{url_for('db.edit_time', alarmid=e.eid)}}">
|
||||||
|
Change time for this event</a>
|
||||||
{{dict_table(e, ['nick', 'actions'])}}
|
{{dict_table(e, ['nick', 'actions'])}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="actions col-md-4">
|
<div class="actions col-md-4">
|
||||||
<h3>Audio</h3>
|
<h3>Audio</h3>
|
||||||
<a class="button" href="{{url_for('db.edit_event', alarmid=e.eid)}}">
|
<a class="button" href="{{url_for('db.edit_event', alarmid=e.eid)}}">
|
||||||
Change audio for this event</a>
|
Change audios for this event</a>
|
||||||
<ol>
|
<ol>
|
||||||
{% for a in actions %}
|
{% for a in actions %}
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from __future__ import print_function
|
from datetime import datetime
|
||||||
|
|
||||||
from pytimeparse.timeparse import timeparse
|
from pytimeparse.timeparse import timeparse
|
||||||
from flask_wtf import Form
|
from flask_wtf import Form
|
||||||
|
@ -23,6 +23,15 @@ class FrequencyAlarmForm(Form):
|
||||||
'(like 9w3d12h)')
|
'(like 9w3d12h)')
|
||||||
submit = SubmitField(u'Submit')
|
submit = SubmitField(u'Submit')
|
||||||
|
|
||||||
|
def populate_from_timespec(self, timespec):
|
||||||
|
if 'nick' in timespec:
|
||||||
|
self.nick.data = timespec['nick']
|
||||||
|
if 'start' in timespec:
|
||||||
|
self.start.data = datetime.fromtimestamp(timespec['start'])
|
||||||
|
if 'end' in timespec:
|
||||||
|
self.end.data = datetime.fromtimestamp(timespec['end'])
|
||||||
|
self.interval.data = timespec['interval']
|
||||||
|
|
||||||
def validate_interval(form, field):
|
def validate_interval(form, field):
|
||||||
try:
|
try:
|
||||||
int(field.data)
|
int(field.data)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from __future__ import print_function
|
from datetime import datetime
|
||||||
|
|
||||||
from flask_wtf import Form
|
from flask_wtf import Form
|
||||||
from wtforms import StringField, DateTimeField, validators, SubmitField
|
from wtforms import StringField, DateTimeField, validators, SubmitField
|
||||||
|
@ -12,6 +12,12 @@ class SingleAlarmForm(Form):
|
||||||
'YYYY-MM-DD HH:MM:SS')
|
'YYYY-MM-DD HH:MM:SS')
|
||||||
submit = SubmitField(u'Submit')
|
submit = SubmitField(u'Submit')
|
||||||
|
|
||||||
|
def populate_from_timespec(self, timespec):
|
||||||
|
if 'nick' in timespec:
|
||||||
|
self.nick.data = timespec['nick']
|
||||||
|
if 'timestamp' in timespec:
|
||||||
|
self.dt.data = datetime.fromtimestamp(timespec['timestamp'])
|
||||||
|
|
||||||
|
|
||||||
def singlealarm_receive(form):
|
def singlealarm_receive(form):
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue