def limit_date(value, lower_limit, upper_limit, error): if not value: return if upper_limit: tmp_value = value if callable(upper_limit): tmp_upper_limit = upper_limit() if not isinstance(tmp_upper_limit, (datetime.datetime, datetime.date)): error('callable') else: tmp_upper_limit = upper_limit # If one object doesn't contain time (is date type), convert the other one to date object if not isinstance(tmp_value, datetime.datetime) or not isinstance( tmp_upper_limit, datetime.datetime): if isinstance(tmp_upper_limit, datetime.datetime): tmp_upper_limit = timezone.to_date(tmp_upper_limit) elif isinstance(tmp_value, datetime.datetime): tmp_value = timezone.to_date(tmp_value) if tmp_value > tmp_upper_limit: error('bounds') if lower_limit: tmp_value = value if callable(lower_limit): tmp_lower_limit = lower_limit() if not isinstance(tmp_lower_limit, (datetime.datetime, datetime.date)): error('callable') else: tmp_lower_limit = lower_limit # If one object doesn't contain time (is date type), convert the other one to date object if not isinstance(tmp_value, datetime.datetime) or not isinstance( tmp_lower_limit, datetime.datetime): if isinstance(tmp_lower_limit, datetime.datetime): tmp_lower_limit = timezone.to_date(tmp_lower_limit) elif isinstance(tmp_value, datetime.datetime): tmp_value = timezone.to_date(tmp_value) if tmp_value < tmp_lower_limit: error('bounds')
def limit_date(value, lower_limit, upper_limit, error): if not value: return if upper_limit: tmp_value = value if callable(upper_limit): tmp_upper_limit = upper_limit() if not isinstance(tmp_upper_limit, (datetime.datetime, datetime.date)): error('callable') else: tmp_upper_limit = upper_limit # If one object doesn't contain time (is date type), convert the other one to date object if not isinstance(tmp_value, datetime.datetime) or not isinstance(tmp_upper_limit, datetime.datetime): if isinstance(tmp_upper_limit, datetime.datetime): tmp_upper_limit = timezone.to_date(tmp_upper_limit) elif isinstance(tmp_value, datetime.datetime): tmp_value = timezone.to_date(tmp_value) if tmp_value > tmp_upper_limit: error('bounds') if lower_limit: tmp_value = value if callable(lower_limit): tmp_lower_limit = lower_limit() if not isinstance(tmp_lower_limit, (datetime.datetime, datetime.date)): error('callable') else: tmp_lower_limit = lower_limit # If one object doesn't contain time (is date type), convert the other one to date object if not isinstance(tmp_value, datetime.datetime) or not isinstance(tmp_lower_limit, datetime.datetime): if isinstance(tmp_lower_limit, datetime.datetime): tmp_lower_limit = timezone.to_date(tmp_lower_limit) elif isinstance(tmp_value, datetime.datetime): tmp_value = timezone.to_date(tmp_value) if tmp_value < tmp_lower_limit: error('bounds')
def lower_birthdate_limit(): return timezone_missing.to_date(timezone.now() - datetime.timedelta(days=LOWER_DATE_LIMIT))
def upper_birthdate_limit(): return timezone_missing.to_date(timezone.now())