From f3c6b0fb0d417e155b8528dce9247f2e3f33062d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Sat, 14 Oct 2017 19:19:57 +0300 Subject: [PATCH] TimeoutForm prepares timedelta objects. --- hc/front/forms.py | 8 ++++++++ hc/front/views.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/hc/front/forms.py b/hc/front/forms.py index 1e2d58ed..1617a5ef 100644 --- a/hc/front/forms.py +++ b/hc/front/forms.py @@ -1,3 +1,5 @@ +from datetime import timedelta as td + from django import forms from django.core.validators import RegexValidator from hc.front.validators import (CronExpressionValidator, TimezoneValidator, @@ -23,6 +25,12 @@ class TimeoutForm(forms.Form): timeout = forms.IntegerField(min_value=60, max_value=2592000) grace = forms.IntegerField(min_value=60, max_value=2592000) + def clean_timeout(self): + return td(seconds=self.cleaned_data["timeout"]) + + def clean_grace(self): + return td(seconds=self.cleaned_data["grace"]) + class CronForm(forms.Form): schedule = forms.CharField(max_length=100, diff --git a/hc/front/views.py b/hc/front/views.py index 0173e0c5..151cbff8 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -190,8 +190,8 @@ def update_timeout(request, code): return HttpResponseBadRequest() check.kind = "simple" - check.timeout = td(seconds=form.cleaned_data["timeout"]) - check.grace = td(seconds=form.cleaned_data["grace"]) + check.timeout = form.cleaned_data["timeout"] + check.grace = form.cleaned_data["grace"] elif kind == "cron": form = CronForm(request.POST) if not form.is_valid():