add new option type DateOption (thanks to Lohysia)
This commit is contained in:
parent
1fba3394fe
commit
6b3c17d49b
@ -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',
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user