Skip to main content
Class for creating date range picker parameter widgets that allow users to select a start date and an end date. 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 date 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 DateRangeParameterOption objects. This is functionally equivalent to create_simple but with additional arguments available for user_attribute and parent_name.

create_from_source()

Decorator for creating a parameter populated from a database table or query using a DateRangeDataSource. The decorated function must return a DateRangeDataSource 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_start_date()

Gets the selected start date as a string.
str
The selected start date formatted as a string.

get_selected_end_date()

Gets the selected end date as a string.
str
The selected end date formatted as a string.

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 date range

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

Using create_simple with date_format

Cascading date ranges

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

User-specific date range constraints

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

Date range from database source

This example populates date range constraints from a database query.

Cascading date range from database

This example shows a date 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_start_date and get_selected_end_date) is available to use for DateRangeParameter objects.

Using custom date formats