From 6b3c17d49b6679c4750182c75b9df55cd1b70d35 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 2 Feb 2017 08:57:11 +0100 Subject: [PATCH] add new option type DateOption (thanks to Lohysia) --- tiramisu/option/__init__.py | 4 ++-- tiramisu/option/option.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tiramisu/option/__init__.py b/tiramisu/option/__init__.py index 9084465..a11cb64 100644 --- a/tiramisu/option/__init__.py +++ b/tiramisu/option/__init__.py @@ -6,12 +6,12 @@ from .option import (ChoiceOption, BoolOption, IntOption, FloatOption, StrOption, UnicodeOption, IPOption, PortOption, NetworkOption, NetmaskOption, BroadcastOption, DomainnameOption, EmailOption, URLOption, UsernameOption, - FilenameOption, PasswordOption) + DateOption, FilenameOption, PasswordOption) __all__ = ('MasterSlaves', 'OptionDescription', 'DynOptionDescription', 'SynDynOptionDescription', 'Option', 'SymLinkOption', - 'DynSymLinkOption', 'ChoiceOption', 'BoolOption', + 'DynSymLinkOption', 'ChoiceOption', 'BoolOption', 'DateOption', 'IntOption', 'FloatOption', 'StrOption', 'UnicodeOption', 'IPOption', 'PortOption', 'NetworkOption', 'NetmaskOption', 'BroadcastOption', 'DomainnameOption', 'EmailOption', 'URLOption', diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 4491b95..15c471c 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -619,3 +619,17 @@ class FilenameOption(_RegexpOption): __slots__ = tuple() _regexp = re.compile(r"^[a-zA-Z0-9\-\._~/+]+$") _display_name = _('file name') + + +class DateOption(Option): + __slots__ = tuple() + _display_name = _('date') + + def _validate(self, value, context=undefined, current_opt=undefined): + err = self._impl_valid_unicode(value) + if err: + return err + try: + datetime.datetime.strptime(value,"%Y-%m-%d") + except ValueError, err: + return ValueError()