"""The predefined, centrally managed waffle switches of the Smarter platform."""
from dataclasses import dataclass
# pylint: disable=C0115
[docs]
@dataclass(frozen=True)
class SmarterWaffleSwitch:
"""The definition of one managed waffle switch: its name, its admin comment, and its default state."""
name: str
comment: str
default: bool
[docs]
def to_json(self) -> dict[str, str | bool]:
"""Return the switch's name, comment and default as a dict."""
return {
"name": self.name,
"comment": self.comment,
"default": self.default,
}
[docs]
class SmarterWaffleSwitches:
"""
Enumerated data type for predefined, managed Smarter waffle switches.
This class defines the fixed set of feature flags (Waffle switches) used by the Smarter Platform.
Each class attribute represents a unique, centrally managed switch. These switches are
automatically verified and created (if missing) during deployments, ensuring consistency
and preventing runtime errors due to missing flags.
.. note::
Only switches defined in this class are considered valid for use in the Smarter codebase.
To add a new feature flag, declare it as a class attribute here.
**Example**
.. code-block:: python
from smarter.lib.django.waffle import SmarterWaffleSwitches, switch_is_active
if switch_is_active(SmarterWaffleSwitches.API_LOGGING):
print("API logging is enabled.")
"""
_all: list[str] = []
"""Every switch's name, in sorted order, built by :attr:`all` on first use."""
_all_set: frozenset[str] = frozenset()
"""Every switch's name, as a set, built by :attr:`all_set` on first use."""
ALLOW_API_GET = "allow_api_get"
"""Allows GET requests to the API endpoints, which are normally restricted to POST requests."""
ACCOUNT_LOGGING = "log_account"
"""Enables logging throughout the smarter.app.account namespace."""
ACCOUNT_MIXIN_LOGGING = "log_account_mixin"
"""Enables logging within the smarter.apps.account.mixins.AccountMixin class."""
API_LOGGING = "log_api"
"""Enables logging throughout the smarter.api namespace."""
CACHE_LOGGING = "log_caching"
"""Enables detailed logging for caching operations including cache hits, misses, and errors."""
CONNECTION_LOGGING = "log_connection"
"""Enables logging throughout the smarter.app.connection namespace."""
DOODLE_LOGGING = "log_doodle"
"""Enables logging throughout the smarter.app.doodle namespace."""
GUARDRAIL_LOGGING = "log_guardrail"
"""Enables logging throughout the smarter.app.guardrail namespace."""
PROMPT_LOGGING = "log_prompt"
"""Enables logging throughout the smarter.app.prompt namespace."""
PROXY_LOGGING = "log_proxy"
"""Enables logging throughout the smarter.app.proxy namespace."""
CHATAPP_LOGGING = "log_chatapp"
"""For the React Prompt UI component.
Enables debug-level javascript console logging inside the browser
"""
LLM_CLIENT_LOGGING = "log_llmclient"
"""Enables logging throughout the smarter.app.llmclient namespace."""
LLM_CLIENT_HELPER_LOGGING = "log_llmclienthelper"
"""Enables logging within the smarter.apps.llmclient.model.LLMClientHelper class."""
LLM_HOST_LOGGING = "log_llm_host"
"""Enables logging throughout the smarter.app.llmhost namespace."""
INFRASTRUCTURE_LOGGING = "log_infrastructure"
"""Enables logging throughout the smarter.app.infrastructure namespace."""
EXTENSION_LOGGING = "log_extension"
"""Enables logging within the smarter.apps.llmtool.extension namespace."""
MCPCLIENT_LOGGING = "log_mcpclient"
"""Enables logging within the smarter.apps.mcpclient namespace."""
MCPSERVER_LOGGING = "log_mcpserver"
"""Enables logging within the smarter.apps.mcpserver namespace."""
ORCHESTRATOR = "log_orchestrator"
"""Enables logging within the smarter.apps.orchestror namespace."""
SECRET_LOGGING = "log_secret"
"""Enables logging throughout the smarter.app.secret namespace."""
VECTORSEARCH_LOGGING = "log_vectorsearch"
"""Enables logging throughout the smarter.app.vectorsearch namespace."""
VECTORSTORE_LOGGING = "log_vectorstore"
"""Enables logging throughout the smarter.app.vectorstore namespace."""
CSRF_SUPPRESS_FOR_LLM_CLIENTS = "disable_csrf_middleware_for_llmclients"
"""Disables CSRF middleware checks for prompt completion endpoints."""
ENABLE_DEBUG_MODE = "enable_debug_mode"
"""Enables debug mode for the entire Smarter application, which may include additional logging and diagnostic information."""
ENABLE_JOURNAL = "enable_journal"
"""Enables the Smarter Journal feature."""
ENABLE_OAUTH2 = "enable_oauth2"
"""Enables OAuth2 authentication support."""
ENABLE_ACCOUNT_REGISTRATION = "enable_account_registration"
"""Enables account registration link."""
ENABLE_LOGIN_FOOTER_LINKS = "enable_login_footer_links"
"""Enables additional links in the login page footer, such as 'Legal' and 'Contact'."""
ENABLE_MULTITENANT_AUTHENTICATION = "enable_multitenant_authentication"
"""Enables multi-tenant authentication support for hosted Smarter platforms."""
ENABLE_MIDDLEWARE_SENSITIVE_FILES = "enable_middleware_block_sensitive_files"
"""Enables SmarterBlockSensitiveFilesMiddleware."""
ENABLE_MIDDLEWARE_EXCESSIVE_404 = "enable_middleware_block_excessive_404"
"""Enables SmarterBlockExcessive404Middleware."""
ENABLE_MIDDLEWARE_CORS = "enable_middleware_cors"
"""Enables SmarterCorsMiddleware."""
ENABLE_MIDDLEWARE_CSRF = "enable_middleware_csrf"
"""Enables Django's built-in CSRF middleware for enhanced security against cross-site request forgery attacks."""
ENABLE_MIDDLEWARE_HTML_MINIFY = "enable_middleware_html_minify"
"""Enables HTML minification for responses with 'text/html' content type using BeautifulSoup, while skipping minification for certain paths and content types to avoid issues with non-HTML responses."""
ENABLE_DOODLE = "enable_doodle"
"""Enables the Doodle, the sign-in page's illustration of the day.
Inactive, the page shows the plain base scene.
"""
ENABLE_DOODLE_AI_CREDIT = "enable_doodle_ai_credit"
"""Enables the credit below a doodle that a Smarter AI application chose or drew, in place of the project's description."""
ENABLE_DOODLE_AUTO_APPROVE = "enable_doodle_auto_approve"
"""Shows a doodle that the Smarter Doodle Artist drew without a superuser's approval in the admin."""
ENABLE_DOODLE_LLM_ARTWORK = "enable_doodle_llm_artwork"
"""Lets the Smarter Doodle Editor choose a holiday that the catalog has no theme for, which the Smarter Doodle Artist draws."""
ENABLE_DOODLE_TRENDS = "enable_doodle_trends"
"""Tells the Smarter Doodle Editor what each region is reading about on Wikipedia, for today and tomorrow."""
ENABLE_LLM_PRICE_CHECKER = "enable_llm_price_checker"
"""Lets the Smarter LLM Price Checker, an LLMClient, update the LLM prices every week from the providers' pricing pages."""
ENABLE_DOODLE_LLM_EDITOR = "enable_doodle_llm_editor"
"""Lets the Smarter Doodle Editor, an LLMClient, choose each region's doodle of each new day."""
ENABLE_DOODLE_ANIMATION = "enable_doodle_animation"
"""Enables the Doodle's animations.
Inactive, every doodle is a still image.
"""
ENABLE_DOODLE_CAPTION = "enable_doodle_caption"
"""Enables the caption below a themed Doodle, e.g. Happy Diwali!, and its link."""
ENABLE_DOODLE_REGIONAL = "enable_doodle_regional"
"""Enables regional doodles, by the browser's time zone.
Inactive, every visitor sees the global doodle.
"""
ENABLE_WEB_CONSOLE_DID_YOU_KNOW = "enable_web_console_did_you_know"
"""Enables the Did you know? note, a fact of the day about The Smarter Project, below the web console's title."""
ENABLE_WEB_CONSOLE_ONBOARDING_HINTS = "enable_web_console_onboarding_hints"
"""Enables the onboarding hints, which point a new user from the sidebar to the Get Weather LLMClient, and the workbench's guided tour."""
ENABLE_WEB_CONSOLE_SERVER_LOGS = "enable_web_console_server_logs"
"""Enables SmarterRequestLogContextMiddleware, which adds request-specific context to log records for enhanced logging capabilities."""
ENABLE_MIDDLEWARE_SMARTER_JSON_ERROR = "enable_middleware_smarter_json_error"
"""Enables SmarterJsonErrorMiddleware, which converts error responses to JSON format when the client expects JSON."""
ENABLE_MIDDLEWARE_SMARTER_TOKEN_AUTH = "enable_middleware_smarter_token_auth"
"""Enables SmarterTokenAuthenticationMiddleware, which provides token-based authentication for API endpoints."""
ENABLE_MIDDLEWARE_SECURITY = "enable_middleware_security"
"""Enables SmarterSecurityMiddleware."""
ENABLE_REACTAPP_DEBUG_MODE = "enable_reactapp_debug_mode"
"""Enables React app debug mode within the Smarter React Prompt component."""
ENABLE_PLUGIN_FUZZY_MATCHING = "enable_plugin_fuzzy_matching"
"""Enables typo tolerant (Levenshtein distance) matching of plugin selector search terms."""
ENABLE_PLUGIN_THESAURUS_MATCHING = "enable_plugin_thesaurus_matching"
"""Enables synonym (WordNet thesaurus) matching of plugin selector search terms."""
ENABLE_NEW_USER_PASSWORD_EMAIL = "enable_new_user_password_email"
"""Enables sending textemail with password to new users."""
ENABLE_SLACK_INVITATION_EMAIL = "enable_slack_invitation_email"
"""Enables the Celery Beat task that invites account contacts to the Slack workspace, two days after their welcome email."""
ENABLE_SMARTER_PAGE_CACHING = "enable_smarter_page_caching"
"""Enables the Smarter user-based page caching decorator for user-facing pages to improve performance."""
ENABLE_LLMCLIENT_ENDPOINTS_PAGE = "llmclient_enable_endpoints_page"
"""Enables the page that a browser receives from a GET of a deployed LLMClient's endpoints."""
ENABLE_FORMATTED_LOGGING = "enable_formatted_logging"
"""Enables formatted logging with ANSI color codes for enhanced readability in logs."""
MANIFEST_LOGGING = "log_manifest_brokers"
"""Enables detailed diagnostic logging for manifest initialization, validation and brokered operations."""
MIDDLEWARE_LOGGING = "log_middleware"
"""Enables detailed diagnostic logging for all middleware operations."""
PLUGIN_LOGGING = "log_plugin"
"""Enables logging throughout the smarter.app.plugin namespace."""
PROVIDER_LOGGING = "log_provider"
"""Enables logging throughout the smarter.app.provider namespace."""
REQUEST_MIXIN_LOGGING = "log_request_mixin"
"""Enables detailed diagnostic logging for the SmarterRequestMixin class."""
RECEIVER_LOGGING = "log_receivers"
"""Enables logging in all Django signal receivers throughout the Smarter codebase."""
TASK_LOGGING = "log_tasks"
"""Enables logging in all Celery tasks throughout the Smarter codebase."""
VALIDATOR_LOGGING = "log_validators"
"""Enables logging in all Django model field validators throughout the Smarter codebase."""
VIEW_LOGGING = "log_views"
"""Enables logging in all Django views throughout the Smarter codebase."""
switches = {
ALLOW_API_GET: SmarterWaffleSwitch(
name=ALLOW_API_GET,
comment="Allows GET requests to the API endpoints, which are normally restricted to POST requests.",
default=False,
),
ACCOUNT_LOGGING: SmarterWaffleSwitch(
name=ACCOUNT_LOGGING,
comment="Enables logging throughout the smarter.app.account namespace.",
default=False,
),
ACCOUNT_MIXIN_LOGGING: SmarterWaffleSwitch(
name=ACCOUNT_MIXIN_LOGGING,
comment="Enables logging within the smarter.apps.account.mixins.AccountMixin class.",
default=False,
),
API_LOGGING: SmarterWaffleSwitch(
name=API_LOGGING,
comment="Enables logging throughout the smarter.api namespace.",
default=True,
),
CACHE_LOGGING: SmarterWaffleSwitch(
name=CACHE_LOGGING,
comment="Enables detailed logging for caching operations including cache hits, misses, and errors.",
default=False,
),
PROMPT_LOGGING: SmarterWaffleSwitch(
name=PROMPT_LOGGING,
comment="Enables logging throughout the smarter.app.prompt namespace.",
default=True,
),
PROXY_LOGGING: SmarterWaffleSwitch(
name=PROXY_LOGGING,
comment="Enables logging throughout the smarter.app.proxy namespace.",
default=True,
),
CHATAPP_LOGGING: SmarterWaffleSwitch(
name=CHATAPP_LOGGING,
comment="For the React Prompt UI component. Enables debug-level javascript console logging inside the browser",
default=True,
),
LLM_CLIENT_LOGGING: SmarterWaffleSwitch(
name=LLM_CLIENT_LOGGING,
comment="Enables logging throughout the smarter.app.llmclient namespace.",
default=True,
),
CONNECTION_LOGGING: SmarterWaffleSwitch(
name=CONNECTION_LOGGING,
comment="Enables logging throughout the smarter.app.connection namespace.",
default=True,
),
DOODLE_LOGGING: SmarterWaffleSwitch(
name=DOODLE_LOGGING,
comment="Enables logging throughout the smarter.app.doodle namespace.",
default=True,
),
GUARDRAIL_LOGGING: SmarterWaffleSwitch(
name=GUARDRAIL_LOGGING,
comment="Enables logging throughout the smarter.app.guardrail namespace",
default=True,
),
LLM_HOST_LOGGING: SmarterWaffleSwitch(
name=LLM_HOST_LOGGING,
comment="Enables logging throughout the smarter.app.llmhost namespace.",
default=True,
),
INFRASTRUCTURE_LOGGING: SmarterWaffleSwitch(
name=INFRASTRUCTURE_LOGGING,
comment="Enables logging throughout the smarter.app.infrastructure namespace.",
default=True,
),
EXTENSION_LOGGING: SmarterWaffleSwitch(
name=EXTENSION_LOGGING,
comment="Enables logging throughout the smarter.apps.llmtool.extension namespace.",
default=True,
),
MCPCLIENT_LOGGING: SmarterWaffleSwitch(
name=MCPCLIENT_LOGGING,
comment="Enables logging throughout the smarter.app.mcpclient namespace.",
default=True,
),
MCPSERVER_LOGGING: SmarterWaffleSwitch(
name=MCPSERVER_LOGGING,
comment="Enables logging throughout the smarter.app.mcpserver namespace.",
default=True,
),
ORCHESTRATOR: SmarterWaffleSwitch(
name=ORCHESTRATOR,
comment="Enables logging throughout the smarter.app.orchestrator namespace.",
default=True,
),
SECRET_LOGGING: SmarterWaffleSwitch(
name=SECRET_LOGGING,
comment="Enables logging throughout the smarter.app.secret namespace.",
default=True,
),
VECTORSEARCH_LOGGING: SmarterWaffleSwitch(
name=VECTORSEARCH_LOGGING,
comment="Enables logging throughout the smarter.app.vectorsearch namespace.",
default=True,
),
VECTORSTORE_LOGGING: SmarterWaffleSwitch(
name=VECTORSTORE_LOGGING,
comment="Enables logging throughout the smarter.app.vectorstore namespace.",
default=True,
),
LLM_CLIENT_HELPER_LOGGING: SmarterWaffleSwitch(
name=LLM_CLIENT_HELPER_LOGGING,
comment="Enables logging within the smarter.apps.llmclient.model.LLMClientHelper class.",
default=False,
),
CSRF_SUPPRESS_FOR_LLM_CLIENTS: SmarterWaffleSwitch(
name=CSRF_SUPPRESS_FOR_LLM_CLIENTS,
comment="Disables CSRF middleware checks for prompt completion endpoints.",
default=False,
),
ENABLE_DEBUG_MODE: SmarterWaffleSwitch(
name=ENABLE_DEBUG_MODE,
comment="Enables debug mode for the entire Smarter application, which may include additional logging and diagnostic information.",
default=False,
),
ENABLE_JOURNAL: SmarterWaffleSwitch(
name=ENABLE_JOURNAL,
comment=(
"Enables the Smarter Journal feature, the audit trail of every api command and prompt. On by default, "
"so that a new platform keeps one from the start."
),
default=True,
),
ENABLE_OAUTH2: SmarterWaffleSwitch(
name=ENABLE_OAUTH2,
comment="Enables OAuth2 authentication support.",
default=False,
),
ENABLE_SMARTER_PAGE_CACHING: SmarterWaffleSwitch(
name="enable_smarter_page_caching",
comment="Enables the Smarter user-based page caching decorator for user-facing pages to improve performance.",
default=True,
),
ENABLE_ACCOUNT_REGISTRATION: SmarterWaffleSwitch(
name=ENABLE_ACCOUNT_REGISTRATION,
comment="Enables account registration link.",
default=False,
),
ENABLE_LOGIN_FOOTER_LINKS: SmarterWaffleSwitch(
name=ENABLE_LOGIN_FOOTER_LINKS,
comment="Enables additional links in the login page footer, such as 'Legal' and 'Contact'.",
default=False,
),
ENABLE_MULTITENANT_AUTHENTICATION: SmarterWaffleSwitch(
name=ENABLE_MULTITENANT_AUTHENTICATION,
comment="Enables multi-tenant authentication support for hosted Smarter platforms.",
default=False,
),
ENABLE_MIDDLEWARE_SENSITIVE_FILES: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_SENSITIVE_FILES,
comment="Enables SmarterBlockSensitiveFilesMiddleware",
default=True,
),
ENABLE_MIDDLEWARE_EXCESSIVE_404: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_EXCESSIVE_404,
comment="Enables SmarterBlockExcessive404Middleware",
default=True,
),
ENABLE_MIDDLEWARE_SMARTER_TOKEN_AUTH: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_SMARTER_TOKEN_AUTH,
comment="Enables SmarterTokenAuthenticationMiddleware, which provides token-based authentication for API endpoints.",
default=True,
),
ENABLE_MIDDLEWARE_CORS: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_CORS,
comment="Enables SmarterCorsMiddleware",
default=True,
),
ENABLE_MIDDLEWARE_CSRF: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_CSRF,
comment="Enables Django's built-in CSRF middleware for enhanced security against cross-site request forgery attacks.",
default=True,
),
ENABLE_MIDDLEWARE_HTML_MINIFY: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_HTML_MINIFY,
comment="Enables HTML minification for responses with 'text/html' content type using BeautifulSoup, while skipping minification for certain paths and content types to avoid issues with non-HTML responses.",
default=True,
),
ENABLE_DOODLE: SmarterWaffleSwitch(
name=ENABLE_DOODLE,
comment=(
"Enables the Doodle, the sign-in page's illustration of the day. "
"Inactive, the page shows the plain base scene."
),
default=True,
),
ENABLE_DOODLE_AI_CREDIT: SmarterWaffleSwitch(
name=ENABLE_DOODLE_AI_CREDIT,
comment=(
"Enables the credit below a doodle that a Smarter AI application chose or drew, "
"in place of the project's description."
),
default=True,
),
ENABLE_DOODLE_AUTO_APPROVE: SmarterWaffleSwitch(
name=ENABLE_DOODLE_AUTO_APPROVE,
comment=(
"Shows a doodle that the Smarter Doodle Artist drew without a superuser's approval " "in the admin."
),
default=False,
),
ENABLE_DOODLE_LLM_ARTWORK: SmarterWaffleSwitch(
name=ENABLE_DOODLE_LLM_ARTWORK,
comment=(
"Lets the Smarter Doodle Editor choose a holiday that the catalog has no theme for, "
"which the Smarter Doodle Artist draws."
),
default=True,
),
ENABLE_DOODLE_TRENDS: SmarterWaffleSwitch(
name=ENABLE_DOODLE_TRENDS,
comment=(
"Tells the Smarter Doodle Editor what each region is reading about on Wikipedia, "
"for today and tomorrow."
),
default=True,
),
ENABLE_LLM_PRICE_CHECKER: SmarterWaffleSwitch(
name=ENABLE_LLM_PRICE_CHECKER,
comment=(
"Lets the Smarter LLM Price Checker, an LLMClient, update the LLM prices every week "
"from the providers' pricing pages. A price that a person set is never changed."
),
default=True,
),
ENABLE_DOODLE_LLM_EDITOR: SmarterWaffleSwitch(
name=ENABLE_DOODLE_LLM_EDITOR,
comment="Lets the Smarter Doodle Editor, an LLMClient, choose each region's doodle of each new day.",
default=True,
),
ENABLE_DOODLE_ANIMATION: SmarterWaffleSwitch(
name=ENABLE_DOODLE_ANIMATION,
comment="Enables the Doodle's animations. Inactive, every doodle is a still image.",
default=True,
),
ENABLE_DOODLE_CAPTION: SmarterWaffleSwitch(
name=ENABLE_DOODLE_CAPTION,
comment="Enables the caption below a themed Doodle, e.g. Happy Diwali!, and its link.",
default=True,
),
ENABLE_DOODLE_REGIONAL: SmarterWaffleSwitch(
name=ENABLE_DOODLE_REGIONAL,
comment=(
"Enables regional doodles, by the browser's time zone. "
"Inactive, every visitor sees the global doodle."
),
default=True,
),
ENABLE_WEB_CONSOLE_DID_YOU_KNOW: SmarterWaffleSwitch(
name=ENABLE_WEB_CONSOLE_DID_YOU_KNOW,
comment="Enables the Did you know? note, a fact of the day about The Smarter Project, below the web console's title.",
default=True,
),
ENABLE_WEB_CONSOLE_ONBOARDING_HINTS: SmarterWaffleSwitch(
name=ENABLE_WEB_CONSOLE_ONBOARDING_HINTS,
comment=(
"Enables the onboarding hints, which point a new user from the sidebar to the Get Weather "
"LLMClient, and the workbench's guided tour."
),
default=True,
),
ENABLE_WEB_CONSOLE_SERVER_LOGS: SmarterWaffleSwitch(
name=ENABLE_WEB_CONSOLE_SERVER_LOGS,
comment="Enables SmarterRequestLogContextMiddleware, which adds request-specific context to log records for enhanced logging capabilities.",
default=True,
),
ENABLE_MIDDLEWARE_SMARTER_JSON_ERROR: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_SMARTER_JSON_ERROR,
comment="Enables SmarterJsonErrorMiddleware, which converts error responses to JSON format when the client expects JSON.",
default=True,
),
ENABLE_MIDDLEWARE_SECURITY: SmarterWaffleSwitch(
name=ENABLE_MIDDLEWARE_SECURITY,
comment="Enables SmarterSecurityMiddleware",
default=True,
),
ENABLE_REACTAPP_DEBUG_MODE: SmarterWaffleSwitch(
name=ENABLE_REACTAPP_DEBUG_MODE,
comment="Enables React app debug mode within the Smarter React Prompt component.",
default=False,
),
ENABLE_LLMCLIENT_ENDPOINTS_PAGE: SmarterWaffleSwitch(
name=ENABLE_LLMCLIENT_ENDPOINTS_PAGE,
comment=(
"Enables the page that a browser receives from a GET of a deployed LLMClient's endpoints: its "
"curl commands, its manifest and The Smarter Project. Inactive, a GET is the api's, a 405."
),
default=False,
),
ENABLE_PLUGIN_FUZZY_MATCHING: SmarterWaffleSwitch(
name=ENABLE_PLUGIN_FUZZY_MATCHING,
comment="Enables typo tolerant (Levenshtein distance) matching of plugin selector search terms.",
default=True,
),
ENABLE_PLUGIN_THESAURUS_MATCHING: SmarterWaffleSwitch(
name=ENABLE_PLUGIN_THESAURUS_MATCHING,
comment="Enables synonym (WordNet thesaurus) matching of plugin selector search terms.",
default=True,
),
ENABLE_NEW_USER_PASSWORD_EMAIL: SmarterWaffleSwitch(
name=ENABLE_NEW_USER_PASSWORD_EMAIL,
comment="Enables sending textemail with password to new users.",
default=False,
),
ENABLE_SLACK_INVITATION_EMAIL: SmarterWaffleSwitch(
name=ENABLE_SLACK_INVITATION_EMAIL,
comment="Enables the Celery Beat task that invites account contacts to the Slack workspace, two days after their welcome email.",
default=False,
),
ENABLE_FORMATTED_LOGGING: SmarterWaffleSwitch(
name=ENABLE_FORMATTED_LOGGING,
comment="Enables formatted logging with ANSI color codes for enhanced readability in logs.",
default=True,
),
MANIFEST_LOGGING: SmarterWaffleSwitch(
name=MANIFEST_LOGGING,
comment="Enables detailed diagnostic logging for manifest initialization, validation and brokered operations.",
default=True,
),
MIDDLEWARE_LOGGING: SmarterWaffleSwitch(
name=MIDDLEWARE_LOGGING,
comment="Enables detailed diagnostic logging for all middleware operations.",
default=False,
),
PLUGIN_LOGGING: SmarterWaffleSwitch(
name=PLUGIN_LOGGING,
comment="Enables logging throughout the smarter.app.plugin namespace.",
default=True,
),
PROVIDER_LOGGING: SmarterWaffleSwitch(
name=PROVIDER_LOGGING,
comment="Enables logging throughout the smarter.app.provider namespace.",
default=True,
),
REQUEST_MIXIN_LOGGING: SmarterWaffleSwitch(
name=REQUEST_MIXIN_LOGGING,
comment="Enables detailed diagnostic logging for the SmarterRequestMixin class.",
default=False,
),
RECEIVER_LOGGING: SmarterWaffleSwitch(
name=RECEIVER_LOGGING,
comment="Enables logging in all Django signal receivers throughout the Smarter codebase.",
default=True,
),
TASK_LOGGING: SmarterWaffleSwitch(
name=TASK_LOGGING,
comment="Enables logging in all Celery tasks throughout the Smarter codebase.",
default=True,
),
VALIDATOR_LOGGING: SmarterWaffleSwitch(
name=VALIDATOR_LOGGING,
comment="Enables logging in all Django model field validators throughout the Smarter codebase.",
default=False,
),
VIEW_LOGGING: SmarterWaffleSwitch(
name=VIEW_LOGGING,
comment="Enables logging in all Django views throughout the Smarter codebase.",
default=True,
),
}
@property
def all(self) -> list[str]:
"""
Return every switch's name.
:returns: The names of the switches, i.e. the values of the upper-case string attributes,
in the sorted order of the attributes.
"""
if not self._all:
names = []
for attr in dir(self):
if not attr.isupper():
continue
value = getattr(self, attr)
if isinstance(value, str):
names.append(value)
self._all = names
return self._all
@property
def all_set(self) -> frozenset[str]:
"""
Return every switch's name, as a set.
:func:`~smarter.lib.django.waffle.switch_is_active` tests membership in it on every
check of a switch, which a set answers without scanning a list.
:returns: The names of the switches.
"""
if not self._all_set:
self._all_set = frozenset(self.all)
return self._all_set
smarter_waffle_switches = SmarterWaffleSwitches()
"""Singleton instance of SmarterWaffleSwitches to be used throughout the codebase."""
__all__ = ["SmarterWaffleSwitches", "smarter_waffle_switches"]