Use this file to discover all available pages before exploring further.
Parameter option for date parameters that can vary based on selection of another parameter.This class can be imported from the squirrels.parameter_options or the squirrels module.
Minimum date constraint. Can be provided as a string (parsed using date_format argument), a datetime.date object, or None. If None, no minimum date constraint applies.
Maximum date constraint. Can be provided as a string (parsed using date_format argument), a datetime.date object, or None. If None, no maximum date constraint applies.
Format of the date string when dates are provided as strings. Uses Python’s strftime format codes (e.g., %Y-%m-%d for ISO format, %m/%d/%Y for US format).
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 DateParameter.
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 DateParameter.
A DateParameterOption 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 DateParameter.
Setting up cascading parameters with varying date ranges
This example shows how to create date options that change their constraints based on the selection of a parent parameter (e.g., different fiscal years with different date ranges).
# Parent parameter for fiscal year@p.SingleSelectParameter.create_with_options( name="fiscal_year", label="Fiscal Year", description="Fiscal year for the report")def fiscal_year_options(): return [ po.SelectParameterOption(id="fy2023", label="FY 2023"), po.SelectParameterOption(id="fy2024", label="FY 2024"), ]# Child date parameter with ranges that vary by fiscal year@p.DateParameter.create_with_options( name="report_date", label="Report Date", description="Date within the selected fiscal year", parent_name="fiscal_year" # Name of the parent parameter above)def report_date_options(): return [ po.DateParameterOption( default_date="2023-01-01", min_date="2023-01-01", max_date="2023-12-31", parent_option_ids="fy2023" # Only applies when "fy2023" is selected ), po.DateParameterOption( default_date="2024-01-01", min_date="2024-01-01", max_date="2024-12-31", parent_option_ids="fy2024" # Only applies when "fy2024" is selected ) ]
This example shows how to provide different date range constraints based on user access levels using the user_groups parameter.
@p.DateParameter.create_with_options( name="transaction_date", label="Transaction Date", description="Date to query transactions", user_attribute="access_level")def transaction_date_options(): return [ po.DateParameterOption( default_date=date.today(), min_date=date(2025, 1, 1), # Recent data only user_groups=["guest"] # Guests can only see recent dates ), po.DateParameterOption( default_date=date.today(), min_date=date(2020, 1, 1), # Can see back to 2020 user_groups=["admin", "member"] # Members and admins see full history ) ]
If custom user fields are defined in pyconfigs/user.py, then they can be used to restrict date constraints as well. To do so, the user_attribute argument must be prefixed with custom_fields..
@p.DateParameter.create_with_options( name="analysis_date", label="Analysis Date", description="Date for analysis", user_attribute="custom_fields.department")def analysis_date_options(): return [ po.DateParameterOption( default_date=date.today(), min_date=date(2024, 6, 1), # Recent data only user_groups=["sales"] # Sales team sees only recent dates ), po.DateParameterOption( default_date=date.today(), min_date=date(2020, 1, 1), # Historical data access user_groups=["analytics"] # Analytics team sees full history ) ]