django_program.features

Feature toggle utilities for django-program.

Provides functions to check whether specific features are enabled in the current configuration, and a mixin for views that require specific features.

Features can be configured at two levels:

  1. Settings defaultsDJANGO_PROGRAM["features"] in Django settings. These require a server restart to change.

  2. Per-conference DB overrides – The FeatureFlags model stores nullable booleans. When a value is not None it takes precedence over the settings default.

Functions

is_feature_enabled(feature[, conference])

Check if a feature is enabled, with optional per-conference DB override.

require_feature(feature[, conference])

Raise Http404 if a feature is disabled.

Classes

FeatureRequiredMixin

View mixin that returns 404 when a required feature is disabled.

django_program.features.is_feature_enabled(feature, conference=None)[source]

Check if a feature is enabled, with optional per-conference DB override.

Resolution order:

  1. If a conference is provided and has a FeatureFlags row with an explicit value for the feature, that value wins.

  2. Otherwise the default from DJANGO_PROGRAM["features"] is used.

  3. The all_ui_enabled master switch is checked first for UI features (public_ui, manage_ui).

Parameters:
  • feature (str) – Feature name (e.g., "registration", "sponsors", "public_ui").

  • conference (object | None) – Optional conference instance. When provided the database FeatureFlags row is consulted for overrides.

Return type:

bool

Returns:

True if the feature is enabled, False otherwise.

Raises:

ValueError – If the feature name is not recognized.

django_program.features.require_feature(feature, conference=None)[source]

Raise Http404 if a feature is disabled.

Parameters:
  • feature (str) – Feature name to check.

  • conference (object | None) – Optional conference for per-conference DB override.

Raises:

Http404 – If the feature is disabled.

Return type:

None

class django_program.features.FeatureRequiredMixin[source]

Bases: object

View mixin that returns 404 when a required feature is disabled.

Set required_feature on the view class to the feature name or a tuple of feature names (all must be enabled). When used alongside ConferenceMixin (placed before this mixin in the MRO), the already-resolved self.conference is picked up automatically for per-conference DB overrides.

Example:

class TicketListView(ConferenceMixin, FeatureRequiredMixin, ListView):
    required_feature = ("registration", "public_ui")
required_feature: str | tuple[str, ...] = ''
get_conference()[source]

Return the conference for per-conference feature lookups.

When ConferenceMixin runs before this mixin it sets self.conference; the default implementation returns that attribute if present, falling back to None.

Return type:

object | None

dispatch(request, *args, **kwargs)[source]

Check the feature toggle(s) before dispatching the view.

Parameters:
Return type:

HttpResponse