Пример #1
0
def date_validator(value, error_message='ingrese una fecha válida'):
    if value is None:
        return None

    try:
        data_valid = validators.date(value,
                                     coerce_value=True,
                                     allow_empty=True)

    except Exception as e:
        raise BadRequest(4010, error_message)

    return data_valid
Пример #2
0
def is_date(value,
            minimum = None,
            maximum = None,
            coerce_value = False,
            **kwargs):
    """Indicate whether ``value`` is a :class:`date <python:datetime.date>`.

    :param value: The value to evaluate.

    :param minimum: If supplied, will make sure that ``value`` is on or after
      this value.
    :type minimum: :class:`datetime <python:datetime.datetime>` /
      :class:`date <python:datetime.date>` / compliant :class:`str <python:str>`
      / :obj:`None <python:None>`

    :param maximum: If supplied, will make sure that ``value`` is on or before this
      value.
    :type maximum: :class:`datetime <python:datetime.datetime>` /
      :class:`date <python:datetime.date>` / compliant :class:`str <python:str>`
      / :obj:`None <python:None>`

    :param coerce_value: If ``True``, will return ``True`` if ``value`` can be
      coerced to a :class:`date <python:datetime.date>`. If ``False``,
      will only return ``True`` if ``value`` is a date value only. Defaults to
      ``False``.
    :type coerce_value: :class:`bool <python:bool>`

    :returns: ``True`` if ``value`` is valid, ``False`` if it is not.
    :rtype: :class:`bool <python:bool>`

    :raises SyntaxError: if ``kwargs`` contains duplicate keyword parameters or duplicates
      keyword parameters passed to the underlying validator

    """
    try:
        value = validators.date(value,
                                minimum = minimum,
                                maximum = maximum,
                                coerce_value = coerce_value,
                                **kwargs)
    except SyntaxError as error:
        raise error
    except Exception:
        return False

    return True
def from_date(value):
    return validators.date(value, allow_empty=True)