def validate_year( value ): # {{{1
""" it validates ``value.year`` newer than 1900 and less than 2 years from
now.
``date`` and ``datetime`` have this property.
Event dates which are more than two years in the future are very likely to
be a human mistake entering the data.
This validator is needed because some functions like datetime.strftime()
raise a ValueError when the year is older than 1900. See the discussion at
http://bugs.python.org/issue1777412
"""
if value.year <= 1900:
raise ValidationError(
_( u'%(year)s is before 1900, which is not allowed' ) % \
{'year': value.year,} )
if value > datetime.date.today() + relativedelta( years = 4 ):
raise ValidationError(
_( u'%(year)s is more than four years in the future, ' \
'which is not allowed' ) % {'year': value.year,} )
评论列表
文章目录