Skip to main content
Class for creating date picker parameter widgets that allow users to select a single 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 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 DateParameterOption 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 DateDataSource. The decorated function must return a DateDataSource 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_date()

Gets the selected date as a string.
str
The selected 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 picker

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

Using create_simple with date_format

Cascading date parameters

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

User-specific date defaults

This example provides different default dates based on user groups.
If custom user fields are defined in pyconfigs/user.py, then they can be used to restrict visibility of parameter options as well. To do so, the user_attribute argument must be prefixed with custom_fields..

Date parameter from database source

This example populates date constraints from a database query.

Cascading date from database source

This example shows a date 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_date) is available to use for DateParameter objects.

Using custom date formats