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 thepyconfigs/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 text 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 bepass).
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 TextParameterOption objects.create_from_source()
Decorator for creating a parameter populated from a database table or query using a TextDataSource. The decorated function must return a TextDataSource object.Instance methods
Instance methods are available on parameter instances at query time (incontext.py or data models) to retrieve selected values.
get_entered_text()
Gets the entered text. Returns a TextValue object that cannot be converted to string except through placeholders (to avoid SQL injection).TextValue
A TextValue object containing the user’s entered text. This object has transformation methods like
apply(), apply_percent_wrap(), apply_as_bool(), apply_as_number(), and apply_as_datetime() for safe usage in queries via placeholders.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 thepyconfigs/parameters.py file.
Using create_simple for basic text input
For parameters that only need a single default value, usecreate_simple. The default text is passed directly to the decorator.
Using textarea input type
This example creates a multi-line text input using the textarea type.Cascading text parameter with varying defaults
This example shows how default text values change based on a parent parameter selection.Text parameter with user-specific defaults
This example provides different default values based on user access levels.Text parameter from database source
This example populates default text from a database table.Cascading text from database source
This example shows a text parameter whose default comes from a database and depends on a parent parameter.Examples for instance methods
Once parameters are configured, you can use instance methods in your models to access the entered text. The parameter instances are available through the context object (e.g.,sqrl.prms).
Basic usage in context.py
The TextValue object returned byget_entered_text() cannot be directly converted to string. It must be used through placeholders for SQL injection safety.