From facde97f80548faab5f2b07236abc410059b53e3 Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 18 Jul 2016 14:38:03 +0200 Subject: [PATCH] WebUI supports frequency timegen --- larigira/timeform_frequency.py | 35 ++++++++++++++++++++++++++++++++++ setup.py | 2 ++ 2 files changed, 37 insertions(+) create mode 100644 larigira/timeform_frequency.py diff --git a/larigira/timeform_frequency.py b/larigira/timeform_frequency.py new file mode 100644 index 0000000..9d5fd37 --- /dev/null +++ b/larigira/timeform_frequency.py @@ -0,0 +1,35 @@ +from __future__ import print_function + +from flask_wtf import Form +from wtforms import StringField, DateTimeField, IntegerField, validators, \ + SubmitField + + +class FrequencyAlarmForm(Form): + nick = StringField(u'Alarm nick', validators=[validators.required()], + description='A simple name to recognize this alarm') + start = DateTimeField(u'Start date and time', + validators=[validators.required()], + description='Date before which no alarm will ring, ' + 'expressed as YYYY-MM-DD HH:MM:SS') + end = DateTimeField(u'End date and time', + validators=[validators.optional()], + description='Date after which no alarm will ring, ' + 'expressed as YYYY-MM-DD HH:MM:SS') + interval = IntegerField(u'Frequency', + validators=[validators.required()], + description='in seconds') + submit = SubmitField(u'Submit') + + +def frequencyalarm_receive(form): + obj = { + 'kind': 'frequency', + 'nick': form.nick.data, + 'start': int(form.start.data.strftime('%s')), + 'interval': form.interval.data, + } + if form.end.data: + obj['end'] = int(form.end.data.strftime('%s')) + return obj + diff --git a/setup.py b/setup.py index c50f065..dc90bf0 100644 --- a/setup.py +++ b/setup.py @@ -67,9 +67,11 @@ setup(name='larigira', ], 'larigira.timeform_create': [ 'single = larigira.timeform_single:SingleAlarmForm', + 'frequency = larigira.timeform_frequency:FrequencyAlarmForm', ], 'larigira.timeform_receive': [ 'single = larigira.timeform_single:singlealarm_receive', + 'frequency = larigira.timeform_frequency:frequencyalarm_receive', ], 'larigira.audioform_create': [ 'static = larigira.audioform_static:StaticAudioForm',