• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. Djblets 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.x
    6. Version 2.0
    7. Version 1.0
    8. Version 0.9
    9. Djblets Documentation
    10. Module and Class References
    11. djblets.conditions
  • Home
  • Guides
  • Avatar Services Guides
  • Writing Avatar Services
  • Extension Guides
  • Writing Extensions
  • Testing Extensions
  • Feature Checks Guides
  • Introduction to Feature Checks
  • Writing Features
  • Writing Feature Checkers
  • Testing with Feature Checks
  • Integration Guides
  • Supporting Integrations
  • Writing Integrations
  • Privacy Compliance Guides
  • Getting and Checking Consent
  • Working with Personally Identifiable Information
  • Service Integrations
  • reCAPTCHA Guides
  • Using reCAPTCHA
  • Registries Guides
  • Writing Registries
  • Web API Guides
  • Writing Web API Resources
  • Adding OAuth2 Support
  • Module and Class References
  • djblets
  • djblets.deprecation
  • djblets.auth.forms
  • djblets.auth.ratelimit
  • djblets.auth.signals
  • djblets.auth.util
  • djblets.auth.views
  • djblets.avatars.errors
  • djblets.avatars.forms
  • djblets.avatars.registry
  • djblets.avatars.services
  • djblets.avatars.services.base
  • djblets.avatars.services.fallback
  • djblets.avatars.services.file_upload
  • djblets.avatars.services.gravatar
  • djblets.avatars.services.url
  • djblets.avatars.settings
  • djblets.cache.backend
  • djblets.cache.backend_compat
  • djblets.cache.context_processors
  • djblets.cache.errors
  • djblets.cache.forwarding_backend
  • djblets.cache.serials
  • djblets.cache.synchronizer
  • djblets.conditions
  • djblets.conditions.choices
  • djblets.conditions.conditions
  • djblets.conditions.errors
  • djblets.conditions.operators
  • djblets.conditions.values
  • djblets.configforms.forms
  • djblets.configforms.mixins
  • djblets.configforms.pages
  • djblets.configforms.registry
  • djblets.configforms.views
  • djblets.datagrid.grids
  • djblets.db.backends.mysql.base
  • djblets.db.fields
  • djblets.db.fields.base64_field
  • djblets.db.fields.comma_separated_values_field
  • djblets.db.fields.counter_field
  • djblets.db.fields.json_field
  • djblets.db.fields.modification_timestamp_field
  • djblets.db.fields.relation_counter_field
  • djblets.db.managers
  • djblets.db.query
  • djblets.db.query_catcher
  • djblets.db.query_comparator
  • djblets.db.validators
  • djblets.extensions.admin
  • djblets.extensions.errors
  • djblets.extensions.extension
  • djblets.extensions.forms
  • djblets.extensions.hooks
  • djblets.extensions.loaders
  • djblets.extensions.manager
  • djblets.extensions.middleware
  • djblets.extensions.models
  • djblets.extensions.packaging
  • djblets.extensions.resources
  • djblets.extensions.settings
  • djblets.extensions.signals
  • djblets.extensions.staticfiles
  • djblets.extensions.testing
  • djblets.extensions.testing.testcases
  • djblets.extensions.urls
  • djblets.extensions.views
  • djblets.extensions.templatetags.djblets_extensions
  • djblets.features
  • djblets.features.checkers
  • djblets.features.decorators
  • djblets.features.errors
  • djblets.features.feature
  • djblets.features.level
  • djblets.features.registry
  • djblets.features.testing
  • djblets.features.templatetags.features
  • djblets.forms.fields
  • djblets.forms.fieldsets
  • djblets.forms.forms
  • djblets.forms.forms.key_value_form
  • djblets.forms.widgets
  • djblets.gravatars
  • djblets.gravatars.templatetags.gravatars
  • djblets.http.middleware
  • djblets.http.responses
  • djblets.integrations.errors
  • djblets.integrations.forms
  • djblets.integrations.hooks
  • djblets.integrations.integration
  • djblets.integrations.manager
  • djblets.integrations.mixins
  • djblets.integrations.models
  • djblets.integrations.urls
  • djblets.integrations.views
  • djblets.log
  • djblets.log.middleware
  • djblets.log.siteconfig
  • djblets.log.urls
  • djblets.log.views
  • djblets.mail.dmarc
  • djblets.mail.message
  • djblets.mail.testing
  • djblets.mail.utils
  • djblets.markdown
  • djblets.markdown.extensions.escape_html
  • djblets.markdown.extensions.wysiwyg
  • djblets.markdown.extensions.wysiwyg_email
  • djblets.pipeline.compilers.es6
  • djblets.pipeline.compilers.less
  • djblets.pipeline.compilers.mixins
  • djblets.pipeline.compilers.rollup
  • djblets.pipeline.compilers.typescript
  • djblets.pipeline.settings
  • djblets.privacy.consent
  • djblets.privacy.consent.base
  • djblets.privacy.consent.common
  • djblets.privacy.consent.errors
  • djblets.privacy.consent.forms
  • djblets.privacy.consent.hooks
  • djblets.privacy.consent.registry
  • djblets.privacy.consent.tracker
  • djblets.privacy.models
  • djblets.privacy.pii
  • djblets.privacy.templatetags.djblets_privacy
  • djblets.recaptcha.mixins
  • djblets.recaptcha.siteconfig
  • djblets.recaptcha.templatetags.djblets_recaptcha
  • djblets.recaptcha.widgets
  • djblets.registries
  • djblets.registries.errors
  • djblets.registries.importer
  • djblets.registries.mixins
  • djblets.registries.registry
  • djblets.registries.signals
  • djblets.secrets
  • djblets.secrets.crypto
  • djblets.secrets.token_generators
  • djblets.secrets.token_generators.base
  • djblets.secrets.token_generators.legacy_sha1
  • djblets.secrets.token_generators.registry
  • djblets.secrets.token_generators.vendor_checksum
  • djblets.siteconfig
  • djblets.siteconfig.admin
  • djblets.siteconfig.context_processors
  • djblets.siteconfig.django_settings
  • djblets.siteconfig.forms
  • djblets.siteconfig.managers
  • djblets.siteconfig.middleware
  • djblets.siteconfig.models
  • djblets.siteconfig.signals
  • djblets.siteconfig.views
  • djblets.template.caches
  • djblets.template.context
  • djblets.template.loaders.conditional_cached
  • djblets.template.loaders.namespaced_app_dirs
  • djblets.testing.decorators
  • djblets.testing.testcases
  • djblets.testing.testrunners
  • djblets.urls.context_processors
  • djblets.urls.decorators
  • djblets.urls.patterns
  • djblets.urls.resolvers
  • djblets.urls.root
  • djblets.urls.staticfiles
  • djblets.util.compat.django.core.cache
  • djblets.util.compat.python.past
  • djblets.util.contextmanagers
  • djblets.util.dates
  • djblets.util.decorators
  • djblets.util.filesystem
  • djblets.util.functional
  • djblets.util.html
  • djblets.util.http
  • djblets.util.humanize
  • djblets.util.json_utils
  • djblets.util.properties
  • djblets.util.serializers
  • djblets.util.symbols
  • djblets.util.templatetags.djblets_deco
  • djblets.util.templatetags.djblets_email
  • djblets.util.templatetags.djblets_forms
  • djblets.util.templatetags.djblets_images
  • djblets.util.templatetags.djblets_js
  • djblets.util.templatetags.djblets_utils
  • djblets.util.typing
  • djblets.util.views
  • djblets.views.generic.base
  • djblets.views.generic.etag
  • djblets.webapi.auth
  • djblets.webapi.auth.backends
  • djblets.webapi.auth.backends.api_tokens
  • djblets.webapi.auth.backends.base
  • djblets.webapi.auth.backends.basic
  • djblets.webapi.auth.backends.oauth2_tokens
  • djblets.webapi.auth.views
  • djblets.webapi.decorators
  • djblets.webapi.encoders
  • djblets.webapi.errors
  • djblets.webapi.fields
  • djblets.webapi.managers
  • djblets.webapi.models
  • djblets.webapi.oauth2_scopes
  • djblets.webapi.resources
  • djblets.webapi.resources.base
  • djblets.webapi.resources.group
  • djblets.webapi.resources.registry
  • djblets.webapi.resources.root
  • djblets.webapi.resources.user
  • djblets.webapi.resources.mixins.api_tokens
  • djblets.webapi.resources.mixins.forms
  • djblets.webapi.resources.mixins.oauth2_tokens
  • djblets.webapi.resources.mixins.queries
  • djblets.webapi.responses
  • djblets.webapi.signals
  • djblets.webapi.testing
  • djblets.webapi.testing.decorators
  • djblets.webapi.testing.testcases
  • General Index
  • Python Module Index
  • Release Notes
  • djblets.conditions¶

    Condition rule support for applications.

    This module contains convenience imports for:

    • Condition

    • ConditionSet

    class Condition(choice, operator, value=None, raw_value=None)¶

    Bases: object

    A condition used to match state to a choice, operator, and value.

    Conditions store a choice, operator, and value (depending on the operator). Callers can query whether a value fulfills a given condition, making it easy for users to compose sets of rules safely for controlling behavior in an application without having to write any code.

    Generally, queries will be made against a ConditionSet, instead of an individual Condition.

    choice¶

    The choice stored for this condition.

    Type:

    djblets.conditions.choices.BaseConditionChoice

    operator¶

    The operator stored for this condition.

    Type:

    djblets.conditions.operators.BaseConditionOperator

    value¶

    The value stored for this condition.

    Type:

    object

    raw_value¶

    The raw (serialized) value for this condition. This is used internally, and won’t usually be needed by a caller.

    Type:

    object

    classmethod deserialize(choices, data, condition_index=None, choice_kwargs={})¶

    Deserialize a condition from serialized data.

    This expects data serialized by serialize().

    Parameters:
    • choices (djblets.conditions.choices.ConditionChoices) – Possible choices for the condition.

    • data (dict) – Serialized data representing this condition.

    • condition_index (int, optional) – The index of the condition within the set of conditions. This is used for exceptions to help identify which condition failed during deserialization.

    Returns:

    The deserialized condition.

    Return type:

    djblets.conditions.conditions.Condition

    Raises:
    • djblets.conditions.errors.ConditionChoiceNotFoundError – The choice ID referenced in the data was missing or did not match a valid choice.

    • djblets.conditions.errors.ConditionOperatorNotFoundError – The operator ID referenced in the data was missing or did not match a valid operator for the choice.

    • djblets.conditions.errors.InvalidConditionValueError – The value was missing from the payload data or was not valid for the choice and operator.

    __init__(choice, operator, value=None, raw_value=None)¶

    Initialize the condition.

    Parameters:
    • choice (djblets.conditions.choices.BaseConditionChoice) – The choice for this condition.

    • operator (djblets.conditions.operators.BaseConditionOperator) – The operator for this condition.

    • value (object, optional) – The value for this condition.

    • raw_value (object, optional) – The raw (serialized) value for this condition.

    matches(value, value_state_cache=None)¶

    Return whether a value matches the condition.

    Parameters:
    • value (object) – The value to match against.

    • value_state_cache (dict) – An optional dictionary used to cache common computable data that might be shared across instances of one or more conditions.

    Returns:

    True if the value fulfills the condition. False if it does not.

    Return type:

    bool

    serialize()¶

    Serialize the condition to a JSON-serializable dictionary.

    Returns:

    A dictionary representing the condition. It can be safely serialized to JSON.

    Return type:

    dict

    to_json()¶

    Serialize the condition to a JSON-serializable dictionary.

    Returns:

    A dictionary representing the condition. It can be safely serialized to JSON.

    Return type:

    dict

    class ConditionSet(mode='all', conditions=[])¶

    Bases: object

    A set of conditions used to match state and define rules.

    Condition sets own multiple conditions, and are given a mode indicating how to query state against those conditions. They’re also responsible for serializing and deserializing all data around a set of conditions to a JSON-serializable format.

    If using MODE_ALL, then all conditions must be satisfied for a condition set to pass. If using MODE_ANY, then only one condition must be satisfied.

    mode¶

    The matching mode for the condition set. This is one of MODE_ALL or MODE_ANY.

    Type:

    unicode

    conditions¶

    The list of conditions that comprise this set.

    Type:

    list of Condition

    MODE_ALWAYS = 'always'¶

    Always match without conditions.

    MODE_ALL = 'all'¶

    All conditions must match a value to satisfy the condition set.

    MODE_ANY = 'any'¶

    Any condition may match a value to satisfy the condition set.

    CONDITIONS = ('always', 'all', 'any')¶

    A set of all the valid modes.

    DEFAULT_MODE = 'all'¶

    The default mode.

    classmethod deserialize(choices, data, choice_kwargs={})¶

    Deserialize a set of conditions from serialized data.

    This expects data serialized by deserialize().

    Parameters:
    • choices (djblets.conditions.choices.ConditionChoices) – Possible choices for the condition set.

    • data (dict) – Serialized data representing this condition set.

    Returns:

    The deserialized condition set.

    Return type:

    djblets.conditions.conditions.ConditionSet

    Raises:
    • djblets.conditions.errors.ConditionChoiceNotFoundError – The choice ID referenced in the data was missing or did not match a valid choice in a condition.

    • djblets.conditions.errors.ConditionOperatorNotFoundError – The operator ID referenced in the data was missing or did not match a valid operator for the choice in a condition.

    • djblets.conditions.errors.InvalidConditionValueError – The value was missing from the payload data or was not valid for the choice and operator in a condition.

    • djblets.conditions.errors.InvalidConditionModeError – The stored match mode was missing or was not a valid mode.

    __init__(mode='all', conditions=[])¶

    Initialize the condition set.

    Parameters:
    • mode (unicode, optional) – The match mode. This defaults to MODE_ALL.

    • conditions (list, optional) – The conditions that make up this set. This defaults to an empty list.

    Raises:

    djblets.conditions.errors.InvalidConditionModeError – The match mode is not a valid mode.

    matches(**values)¶

    Check if a value matches the condition set.

    Depending on the mode of the condition set, this will either require all conditions to match, or only one.

    Parameters:

    **values (dict) – Values to match against. By default, condition choices will match against a single value keyword argument, but more specialized uses might take into account one or more other keyword arguments.

    Returns:

    True if the value fulfills the condition set. False if it does not.

    Return type:

    bool

    serialize()¶

    Serialize the condition set to a JSON-serializable dictionary.

    Returns:

    A dictionary representing the condition set. It can be safely serialized to JSON.

    Return type:

    dict

    to_json()¶

    Serialize the condition set to a JSON-serializable dictionary.

    Returns:

    A dictionary representing the condition set. It can be safely serialized to JSON.

    Return type:

    dict

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • Condition
      • Condition.choice
      • Condition.operator
      • Condition.value
      • Condition.raw_value
      • Condition.deserialize()
      • Condition.__init__()
      • Condition.matches()
      • Condition.serialize()
      • Condition.to_json()
    • ConditionSet
      • ConditionSet.mode
      • ConditionSet.conditions
      • ConditionSet.MODE_ALWAYS
      • ConditionSet.MODE_ALL
      • ConditionSet.MODE_ANY
      • ConditionSet.CONDITIONS
      • ConditionSet.DEFAULT_MODE
      • ConditionSet.deserialize()
      • ConditionSet.__init__()
      • ConditionSet.matches()
      • ConditionSet.serialize()
      • ConditionSet.to_json()