make "start" optional in timegen "frequency"

fix #23
This commit is contained in:
boyska 2016-09-15 10:03:53 +02:00
parent 1e902a069d
commit 0a1f78ebb5
No known key found for this signature in database
GPG key ID: 7395DCAE58289CA9

View file

@ -9,18 +9,20 @@ from wtforms import StringField, DateTimeField, validators, \
class FrequencyAlarmForm(Form):
nick = StringField('Alarm nick', validators=[validators.required()],
description='A simple name to recognize this alarm')
start = DateTimeField('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('End date and time',
validators=[validators.optional()],
description='Date after which no alarm will ring, '
'expressed as YYYY-MM-DD HH:MM:SS')
interval = StringField('Frequency',
validators=[validators.required()],
description='in seconds, or human-readable '
'(like 9w3d12h)')
start = DateTimeField('Start date and time',
validators=[validators.optional()],
description='Date before which no alarm will ring, '
'expressed as YYYY-MM-DD HH:MM:SS; if omitted, the '
'alarm will always ring')
end = DateTimeField('End date and time',
validators=[validators.optional()],
description='Date after which no alarm will ring, '
'expressed as YYYY-MM-DD HH:MM:SS; if omitted, the '
'alarm will always ring')
submit = SubmitField('Submit')
def populate_from_timespec(self, timespec):
@ -46,9 +48,12 @@ def frequencyalarm_receive(form):
obj = {
'kind': 'frequency',
'nick': form.nick.data,
'start': int(form.start.data.strftime('%s')),
'interval': form.interval.data,
}
if form.start.data:
obj['start'] = int(form.end.data.strftime('%s'))
else:
obj['start'] = 0
if form.end.data:
obj['end'] = int(form.end.data.strftime('%s'))
return obj