add new option type DateOption (thanks to Lohysia)

This commit is contained in:
Emmanuel Garette 2017-02-02 08:57:11 +01:00
parent 1fba3394fe
commit 6b3c17d49b
2 changed files with 16 additions and 2 deletions

View File

@ -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',

View File

@ -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()