Jump to >

djblets.features.checkers

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]

Decorator that converts a method with a single self argument into a property cached on the instance.

is_feature_enabled(feature_id, **kwargs)[source]

Return whether a feature is enabled for a given ID.

Subclasses must override this to provide a suitable implementation for that type of feature checker.

Parameters:
  • feature_id (unicode) – The ID corresponding to a Feature class to check.
  • **kwargs (dict) – Additional keyword arguments relevant for this particular feature check.
Returns:

A boolean value indicating if the feature is enabled.

Return type:

bool

class SettingsFeatureChecker[source]

Bases: djblets.features.checkers.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 modifying settings_key.

settings_key = u'ENABLED_FEATURES'[source]

The key in settings used for the enabled features.

is_feature_enabled(feature_id, **kwargs)[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 a settings.ENABLED_FEATURES dictionary.

Parameters:
  • feature_id (unicode) – The ID corresponding to a Feature class to check.
  • **kwargs (dict) – Additional keyword arguments relevant for this particular feature check. These are unused for this checker.
Returns:

A boolean value indicating if the feature is enabled.

Return type:

bool

class SiteConfigFeatureChecker[source]

Bases: djblets.features.checkers.SettingsFeatureChecker

Feature checker that checks against a SiteConfiguration.

This feature checker will check two places to see if a feature is enabled:

  1. The enabled_features dictionary in a SiteConfiguration settings.
  2. The settings.ENABLED_FEATURES dictionary.

These keys can be changed by subclassing and modifying siteconfig_key and settings_key.

siteconfig_key = u'enabled_features'[source]

The key in siteconfig used for the enabled features.

is_feature_enabled(feature_id, **kwargs)[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 the enabled_features key in a SiteConfiguration or in a settings.ENABLED_FEATURES dictionary.

Parameters:
  • feature_id (unicode) – The ID corresponding to a Feature class to check.
  • **kwargs (dict) – Additional keyword arguments relevant for this particular feature check. These are unused for this checker.
Returns:

A boolean value indicating if the feature is enabled.

Return type:

bool

set_feature_checker(feature_checker)[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, or None to unset.
get_feature_checker()[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:BaseFeatureChecker
Raises:django.core.exceptions.ImproperlyConfigured – There was an error either in the settings.FEATURE_CHECKER value or in instantiating the feature checker.