Merge pull request #685 from normanjaeckel/Issue_677
Validator for agenda_start_time aded.
This commit is contained in:
commit
36ff05f977
@ -10,10 +10,13 @@
|
|||||||
:license: GNU GPL, see LICENSE for more details.
|
:license: GNU GPL, see LICENSE for more details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy, ugettext_noop, ugettext as _
|
from django.utils.translation import ugettext_lazy, ugettext_noop, ugettext as _
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from openslides.config.signals import config_signal
|
from openslides.config.signals import config_signal
|
||||||
from openslides.config.api import config, ConfigVariable, ConfigPage
|
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
|
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
|
# TODO: Reinsert the datepicker scripts in the template
|
||||||
|
|
||||||
@receiver(config_signal, dispatch_uid='setup_agenda_config_page')
|
@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',
|
name='agenda_start_event_date_time',
|
||||||
default_value='',
|
default_value='',
|
||||||
form_field=forms.CharField(
|
form_field=forms.CharField(
|
||||||
|
validators=[validate_start_time, ],
|
||||||
widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M'),
|
widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Begin of event'),
|
label=_('Begin of event'),
|
||||||
|
@ -216,3 +216,12 @@ class ConfigTest(TestCase):
|
|||||||
response = self.client.get('/config/agenda/')
|
response = self.client.get('/config/agenda/')
|
||||||
self.assertContains(response, 'timepicker.css', status_code=200)
|
self.assertContains(response, 'timepicker.css', status_code=200)
|
||||||
self.assertContains(response, 'jquery-ui-timepicker-addon.min.js', status_code=200)
|
self.assertContains(response, 'jquery-ui-timepicker-addon.min.js', status_code=200)
|
||||||
|
|
||||||
|
def test_wrong_input(self):
|
||||||
|
response = self.client.post(
|
||||||
|
'/config/agenda/',
|
||||||
|
{'agenda_start_event_date_time': 'wrong_format',
|
||||||
|
'agenda_show_last_speakers': '3'})
|
||||||
|
self.assertFormError(response, form='form',
|
||||||
|
field='agenda_start_event_date_time',
|
||||||
|
errors='Invalid input.')
|
||||||
|
Loading…
Reference in New Issue
Block a user