Skip to main content
Class for creating numeric range parameter widgets that allow users to select a lower and upper numeric value. This class can be imported from the squirrels.parameters or the squirrels module.

Factory methods

Factory methods are class methods that create and configure parameter instances. These methods are typically used in the pyconfigs/parameters.py file to create the parameter configurations (which describes the “shape” of the parameter but does not include the realtime user selections).

create_simple()

Decorator for creating a simple numeric range parameter that doesn’t involve user attributes or parent parameters. The body of the decorated function does not need to return anything (i.e., it can simply be pass).

create_with_options()

Decorator for creating a parameter with options that can vary based on user attributes or parent parameter selections. The decorated function must return a list of NumberRangeParameterOption objects.

create_from_source()

Decorator for creating a parameter populated from a database table or query using a NumberRangeDataSource. The decorated function must return a NumberRangeDataSource object.

Instance methods

Instance methods are available on parameter instances at query time (in context.py or data models) to retrieve selected values.

get_selected_lower_value()

Gets the selected lower numeric value as a float.
float
The selected lower numeric value converted from Decimal to float.

get_selected_upper_value()

Gets the selected upper numeric value as a float.
float
The selected upper numeric value converted from Decimal to float.

is_enabled()

Returns True if the parameter has a valid option after applying user attribute and parent parameter selections, False otherwise.
bool
True if the parameter has a valid option, False otherwise.

Examples for factory methods

All examples below are defined in the pyconfigs/parameters.py file.

Using create_simple for basic numeric range

For parameters that only need a single set of constraints, use create_simple. The numeric range parameters are passed directly to the decorator.

Number range with decimal precision

This example uses decimal values for precise range selection. Regardless of whether Decimal, float, or string values are used, the exact precision will always be maintained (without floating point errors).

Cascading number range parameters

This example shows how numeric range constraints can vary based on a parent parameter selection.

User-specific number range constraints

This example provides different numeric range constraints based on user access levels.

Number range from database source

This example populates numeric range constraints from a database query.

Cascading number range from database

This example shows a number range parameter whose constraints come from a database and depend on a parent parameter.

Examples for instance methods

Once parameters are configured, you can use instance methods in your models to access the selected values. The parameter instances are available through the context object (e.g., sqrl.prms).

Basic usage in context.py

Basic usage in Jinja SQL models

The following example works but is not recommended. See tip below for why.
It is generally better to only use the instance methods in context.py to transform parameter selections into context variables. Using the instance methods directly in the data models is not recommended.IDEs can provide code suggestions for the available instance methods in Python instead of having to memorize which method (such as get_selected_lower_value) is available to use for NumberRangeParameter objects.

Using range values in calculations