From 1e188761d4ec2c510f6149c9eae4451e73c44475 Mon Sep 17 00:00:00 2001 From: Stefan Frauenknecht Date: Mon, 27 May 2013 22:24:16 +0200 Subject: [PATCH] Validator for agenda_start_time aded. PEP8 issue 'missing whitespace after ','' resolved --- openslides/agenda/signals.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openslides/agenda/signals.py b/openslides/agenda/signals.py index 9f90b5bf0..b4286aa27 100644 --- a/openslides/agenda/signals.py +++ b/openslides/agenda/signals.py @@ -10,10 +10,13 @@ :license: GNU GPL, see LICENSE for more details. """ +from datetime import datetime + from django.dispatch import receiver from django import forms from django.utils.translation import ugettext_lazy, ugettext_noop, ugettext as _ from django.template.loader import render_to_string +from django.core.exceptions import ValidationError from openslides.config.signals import config_signal from openslides.config.api import config, ConfigVariable, ConfigPage @@ -26,6 +29,13 @@ from openslides.projector.api import (get_active_slide, get_slide_from_sid, from .models import Speaker, Item +def validate_start_time(value): + try: + datetime.strptime(value, '%d.%m.%Y %H:%M') + except ValueError: + raise ValidationError(_('Invalid input.')) + + # TODO: Reinsert the datepicker scripts in the template @receiver(config_signal, dispatch_uid='setup_agenda_config_page') @@ -38,6 +48,7 @@ def setup_agenda_config_page(sender, **kwargs): name='agenda_start_event_date_time', default_value='', form_field=forms.CharField( + validators=[validate_start_time, ], widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M'), required=False, label=_('Begin of event'),