Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.pysquirrels.com/llms.txt

Use this file to discover all available pages before exploring further.

Parameter option for number range parameters that can vary based on selection of another parameter. This class can be imported from the squirrels.parameter_options or the squirrels module.

Constructor

Creates a NumberRangeParameterOption object. Typically used in pyconfigs/parameters.py.
def __init__(
    self, min_value: decimal.Decimal | int | float | str, 
    max_value: decimal.Decimal | int | float | str, 
    *, increment: decimal.Decimal | int | float | str = 1, 
    default_lower_value: decimal.Decimal | int | float | str | None = None, 
    default_upper_value: decimal.Decimal | int | float | str | None = None, 
    user_groups: Iterable[Any] | str = frozenset(), 
    parent_option_ids: Iterable[str] | str = frozenset()
) -> None:

Examples

A NumberRangeParameterOption object is created in the pyconfigs/parameters.py file. It must be created in a function decorated with the create_with_options factory method from NumberRangeParameter.

Usage example in parameters.py

from squirrels import parameters as p, parameter_options as po

@p.NumberRangeParameter.create_with_options(
    name="price_range", 
    label="Price Range",
    description="Price range for filtering products"
)
def price_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=0,
            max_value=1000,
            default_lower_value=0,
            default_upper_value=100
        )
    ]
In addition, the following are some additional examples for creating a NumberRangeParameterOption object.

Setting up cascading parameters with varying number ranges

This example shows how to create number range options that change their constraints based on the selection of a parent parameter (e.g., different product categories with different price ranges).
# Parent parameter for product category
@p.SingleSelectParameter.create_with_options(
    name="product_category", 
    label="Product Category",
    description="Category of products"
)
def product_category_options():
    return [
        po.SelectParameterOption(id="electronics", label="Electronics"),
        po.SelectParameterOption(id="furniture", label="Furniture"),
    ]

# Child number range parameter with ranges that vary by category
@p.NumberRangeParameter.create_with_options(
    name="price_range", 
    label="Price Range",
    description="Price range based on product category",
    parent_name="product_category"  # Name of the parent parameter above
)
def price_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=0, 
            max_value=2000,
            increment=10,
            default_lower_value=50,
            default_upper_value=500,
            parent_option_ids="electronics"  # Only applies when "electronics" is selected
        ),
        po.NumberRangeParameterOption(
            min_value=0, 
            max_value=10000,
            increment=10,
            default_lower_value=100,
            default_upper_value=1000,
            parent_option_ids="furniture"  # Only applies when "furniture" is selected
        )
    ]

Restricting value ranges by user groups

This example shows how to provide different value range constraints based on user access levels using the user_groups parameter.
@p.NumberRangeParameter.create_with_options(
    name="salary_range", 
    label="Salary Range",
    description="Salary range for search",
    user_attribute="access_level"
)
def salary_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=20000,
            max_value=80000,
            increment=1000,
            default_lower_value=30000,
            default_upper_value=60000,
            user_groups=["member"]  # Members see limited salary range
        ),
        po.NumberRangeParameterOption(
            min_value=20000,
            max_value=500000,
            increment=1000,
            default_lower_value=30000,
            default_upper_value=100000,
            user_groups=["admin"]  # Admins see full salary range
        )
    ]
If custom user fields are defined in pyconfigs/user.py, then they can be used to restrict value range constraints as well. To do so, the user_attribute argument must be prefixed with custom_fields..
@p.NumberRangeParameter.create_with_options(
    name="commission_range", 
    label="Commission Range",
    description="Commission range as percentage",
    user_attribute="custom_fields.department"
)
def commission_range_options():
    return [
        po.NumberRangeParameterOption(
            min_value=0,
            max_value=10,
            default_lower_value=1,
            default_upper_value=5,
            user_groups=["sales"]  # Sales team sees standard commission range
        ),
        po.NumberRangeParameterOption(
            min_value=0,
            max_value=50,
            default_lower_value=0,
            default_upper_value=15,
            user_groups=["executive"]  # Executives see full commission range
        )
    ]