def not_in_future_f(value): if is_date(value): now = date.today() else: now = datetime.now(pytz.utc) if value > now: raise ValidationError("Can't be in the future.") return value
def before_f(value): if is_date(value): value_dt = date_to_datetime(value) else: value_dt = value if value_dt > max_dt: raise ValidationError('Value is after %s.' % safe_strftime(max_dt, dt_format)) return value
def after(min_dt, dt_format=HUMAN_DATE_FORMAT): if is_date(min_dt): min_dt = date_to_datetime(min_dt) def after_f(value): if is_date(value): value_dt = date_to_datetime(value) else: value_dt = value if value_dt < min_dt: raise ValidationError('Value is before %s.' % safe_strftime(min_dt, dt_format)) return value return after_f