UI for cron timegen
This commit is contained in:
parent
72c4de38af
commit
19c93125dd
3 changed files with 44 additions and 0 deletions
39
larigira/timeform_cron.py
Normal file
39
larigira/timeform_cron.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import logging
|
||||
|
||||
from flask_wtf import Form
|
||||
from wtforms import StringField, validators, SubmitField, ValidationError
|
||||
from croniter import croniter
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CronAlarmForm(Form):
|
||||
nick = StringField(
|
||||
"Alarm nick",
|
||||
validators=[validators.required()],
|
||||
description="A simple name to recognize this alarm",
|
||||
)
|
||||
cron_format = StringField(
|
||||
"cron-like format",
|
||||
validators=[validators.required()],
|
||||
description="the frequency specification, as in the `cron` command",
|
||||
)
|
||||
submit = SubmitField("Submit")
|
||||
|
||||
def populate_from_timespec(self, timespec):
|
||||
if "nick" in timespec:
|
||||
self.nick.data = timespec["nick"]
|
||||
if "cron_format" in timespec:
|
||||
self.cron_format.data = timespec["cron_format"]
|
||||
|
||||
def validate_cron_format(self, field):
|
||||
if not croniter.is_valid(field.data):
|
||||
raise ValidationError("formato di cron non valido")
|
||||
|
||||
|
||||
def cronalarm_receive(form):
|
||||
return {
|
||||
"kind": "cron",
|
||||
"nick": form.nick.data,
|
||||
"cron_format": form.cron_format.data,
|
||||
}
|
|
@ -9,6 +9,9 @@ log = logging.getLogger("time-cron")
|
|||
|
||||
|
||||
class CronAlarm(Alarm):
|
||||
|
||||
description = "Frequency specified by cron-like format. nerds preferred"
|
||||
|
||||
def __init__(self, obj):
|
||||
super().__init__()
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -79,10 +79,12 @@ setup(name='larigira',
|
|||
'larigira.timeform_create': [
|
||||
'single = larigira.timeform_base:SingleAlarmForm',
|
||||
'frequency = larigira.timeform_base:FrequencyAlarmForm',
|
||||
'cron = larigira.timeform_cron:CronAlarmForm',
|
||||
],
|
||||
'larigira.timeform_receive': [
|
||||
'single = larigira.timeform_base:singlealarm_receive',
|
||||
'frequency = larigira.timeform_base:frequencyalarm_receive',
|
||||
'cron = larigira.timeform_cron:cronalarm_receive',
|
||||
],
|
||||
'larigira.audioform_create': [
|
||||
'static = larigira.audioform_static:StaticAudioForm',
|
||||
|
|
Loading…
Reference in a new issue