@exceptions.rewrap(ValueError, IntegerRequired)
def require_int(value, min=None, max=None):
    """Jinja2 filter used to enforce an integer type in a template.

    Accepts optional min/max constraints.

    Usage:
        {{ my_integer_value|require_int }}
        {{ my_integer_value|require_int(min=0) }}
        {{ my_integer_value|require_int(min=0, max=20) }}
        {{ my_integer_value|require_int(max=20) }}
    """
    value = int(value)

    # check the integer falls within the allowed range if set
    if min is not None and value < min:
        raise IntegerTooSmall("%d is smaller than the minimum allowed value of %d" % (value, min))
    if max is not None and value > max:
        raise IntegerTooLarge("%d is larger than the maximum allowed value of %d" % (value, max))

    return value
dataset/ETHPy150Open shopkeep/shpkpr/shpkpr/template_filters.py/require_int/original