utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:grical 作者: wikical 项目源码 文件源码
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,} )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号