djblets.features.checkers¶
Classes for checking whether features are enabled for different criteria.
- class BaseFeatureChecker[source]¶
Bases:
object
Base class for a feature checker.
Subclasses are responsible for overriding
is_feature_enabled()
and returning a suitable result for any given feature.- min_enabled_level[source]¶
The minimum feature level to enable by default.
If
settings.MIN_ENABLED_FEATURE_LEVEL
is set, that value will be used.If
settings.DEBUG
isTrue
, then anythingBETA
or higher will be enabled by default.If
settings.DEBUG
isFalse
, then anythingSTABLE
or higher will be enabled by default.Subclasses can override this to provide custom logic.
- class SettingsFeatureChecker[source]¶
Bases:
BaseFeatureChecker
Feature checker that checks against a SiteConfiguration.
This feature checker will check if a feature is enabled by checking the the
settings.ENABLED_FEATURES
dictionary. This key can be changed by subclassing and modifyingsettings_key
.- is_feature_enabled(feature_id: str, **kwargs) bool [source]¶
Return whether a feature is enabled for a given ID.
The feature will be enabled if its feature ID is set to
True
in asettings.ENABLED_FEATURES
dictionary.
- __annotations__ = {'settings_key': 'str'}¶
- class SiteConfigFeatureChecker[source]¶
Bases:
SettingsFeatureChecker
Feature checker that checks against a SiteConfiguration.
This feature checker will check two places to see if a feature is enabled:
The
enabled_features
dictionary in aSiteConfiguration
settings.The
settings.ENABLED_FEATURES
dictionary.
These keys can be changed by subclassing and modifying
siteconfig_key
andsettings_key
.- is_feature_enabled(feature_id: str, **kwargs) bool [source]¶
Return whether a feature is enabled for a given ID.
The feature will be enabled if its feature ID is set to
True
in either theenabled_features
key in aSiteConfiguration
or in asettings.ENABLED_FEATURES
dictionary.
- __annotations__ = {'settings_key': 'str', 'siteconfig_key': 'str'}¶
- set_feature_checker(feature_checker: Optional[BaseFeatureChecker]) None [source]¶
Set the feature checker to use for all features.
This can be called to manually configure a feature checker, or to unset the feature checker in order to recompute it.
- Parameters:
feature_checker (
BaseFeatureChecker
) – The new feature checker to set, orNone
to unset.
- get_feature_checker() BaseFeatureChecker [source]¶
Return the configured feature checker instance.
The class to use is configured through the
settings.FEATURE_CHECKER
setting, which must be a full module and class path. If not specified,SettingsFeatureChecker
will be used.The same feature checker instance will be returned each time this is called.
- Returns:
A feature checker instance.
- Return type:
- Raises:
django.core.exceptions.ImproperlyConfigured – There was an error either in the
settings.FEATURE_CHECKER
value or in instantiating the feature checker.