Use this file to discover all available pages before exploring further.
Parameter option for number parameters that can vary based on selection of another parameter.This class can be imported from the squirrels.parameter_options or the squirrels module.
Increment or step value for the number input. Must fit evenly between min_value and max_value. Can be provided as a Decimal, int, float, or string representation of a number.Must fit evenly between min_value and max_value. Increment must be specified if the difference is not divisible by 1.
Default value for this option. Must be selectable based on min_value, max_value, and increment. Can be provided as a Decimal, int, float, string representation of a number, or None. If None, defaults to min_value.
User group(s) this option is visible for. Only applies if user_attribute is provided to the factory method create_with_options associated to the NumberParameter.
Parent option id(s) that must be selected for this option to be visible. Only applies if parent_name is provided to the factory method create_with_options associated to the NumberParameter.
A NumberParameterOption 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 NumberParameter.
from squirrels import parameters as p, parameter_options as po@p.NumberParameter.create_with_options( name="threshold", label="Threshold", description="Threshold value for filtering")def threshold_options(): return [ po.NumberParameterOption( min_value=0, max_value=1000, default_value=100 ) ]
In addition, the following are some additional examples for creating a NumberParameterOption object.
Setting up cascading parameters with varying number ranges
This example shows how to create number options that change their constraints based on the selection of a parent parameter (e.g., different budget categories with different value ranges).
# Parent parameter for budget category@p.SingleSelectParameter.create_with_options( name="budget_category", label="Budget Category", description="Category of budget")def budget_category_options(): return [ po.SelectParameterOption(id="small", label="Small Projects"), po.SelectParameterOption(id="large", label="Large Projects"), ]# Child number parameter with ranges that vary by category@p.NumberParameter.create_with_options( name="budget_amount", label="Budget Amount", description="Budget amount based on category", parent_name="budget_category" # Name of the parent parameter above)def budget_amount_options(): return [ po.NumberParameterOption( min_value=1000, max_value=10000, default_value=5000, parent_option_ids="small" # Only applies when "small" is selected ), po.NumberParameterOption( min_value=25000, max_value=500000, default_value=50000, parent_option_ids="large" # Only applies when "large" is selected ) ]
This example shows how to provide different value constraints based on user access levels using the user_groups parameter.
@p.NumberParameter.create_with_options( name="discount_percentage", label="Discount Percentage", description="Discount percentage to apply", user_attribute="access_level")def discount_percentage_options(): return [ po.NumberParameterOption( min_value=0, max_value=10, default_value=5, user_groups=["member"] # Members can apply up to 10% discount ), po.NumberParameterOption( min_value=0, max_value=50, default_value=10, user_groups=["admin"] # Admins can apply up to 50% ) ]
If custom user fields are defined in pyconfigs/user.py, then they can be used to restrict value constraints as well. To do so, the user_attribute argument must be prefixed with custom_fields..