• 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.values
  • 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.values¶

    Base support and standard value field wrappers for conditions.

    class BaseConditionValueField[source]¶

    Bases: object

    Base class for a field for editing and representing condition values.

    This is used to provide a field in the UI that can be used for editing a condition value. It’s responsible for rendering the field, preparing data for the field, retrieving the data from the HTML form data, and handling JSON-safe serialization/deserialization of values.

    Subclasses can specify custom logic for all these operations, and can specify the JavaScript counterparts for the class used to edit the values.

    js_model_class = 'Djblets.Forms.ConditionValueField'[source]¶

    The JavaScript model class for representing field state.

    This is instantiated on the web UI and is used to store any model data provided by get_js_model_data().

    The default is a simple model that just stores the model data as attributes.

    js_view_class = None[source]¶

    The JavaScript view class for editing fields.

    This is instantiated on the web UI and is used to provide an editor for the condition’s value.

    It’s passed any options that are returned from get_js_model_data().

    serialize_value(value)[source]¶

    Serialize a Python object into a JSON-compatible serialized form.

    This is responsible for taking a Python value/object of some sort (string, list, or anything more complex) and returning a JSON-compatible form for serialization.

    By default, this returns the value as-is.

    Parameters:

    value (object) – The value to serialize.

    Returns:

    The JSON-compatible serialized value.

    Return type:

    object

    deserialize_value(serialized_value)[source]¶

    Deserialize a value back into a Python object.

    This is responsible for taking a value serialized by serialize_value() and returning a suitable Python object/value.

    By default, this returns the value as-is.

    Parameters:

    serialized_value (object) – The serialized value to deserialize.

    Returns:

    The deserialized value.

    Return type:

    object

    Raises:

    djblets.conditions.errors.InvalidConditionValueError – Error deserializing or validating the data.

    get_from_form_data(data, files, name)[source]¶

    Return a value from a form data dictionary.

    This attempts to return the value for a condition from Django form data. It’s passed a dictionary of data, uploaded files, and the name of the appropriate value field.

    Subclasses can override this to normalize the value before returning.

    Parameters:
    • data (django.http.request.QueryDict) – The dictionary containing form data.

    • files (django.http.request.QueryDict) – The dictionary containing uploaded files.

    • name (unicode) – The field name for the value to load.

    Returns:

    The value from the form data.

    Return type:

    object

    prepare_value_for_widget(value)[source]¶

    Return a value suitable for use in the widget.

    The value will be passed to the widget’s JavaScript UI. It can be used in special cases where a Python object needs to be converted to another form in order to work properly client-side.

    By default, the value is returned as-is.

    Parameters:

    value (object) – The value to prepare for the widget.

    Returns:

    The value prepared for the widget.

    Return type:

    object

    get_js_model_data()[source]¶

    Return data for the JavaScript model for this field.

    The returned data will be set as attributes on the Backbone model pointed to by js_model_class.

    By default, this includes the rendered HTML as fieldHTML, which should generally be provided (but is not required, depending on the field).

    Returns:

    The model data. This must be serializable as JSON.

    Return type:

    dict

    get_js_view_data()[source]¶

    Return data for the JavaScript view for this field.

    The returned data will be set as options on the Backbone view pointed to by js_view_class.

    This is empty by default.

    Returns:

    The view data. This must be serializable as JSON.

    Return type:

    dict

    render_html()[source]¶

    Return rendered HTML for the field.

    The rendered HTML will be inserted dynamically by the JavaScript UI.

    This must be implemented by subclasses.

    Returns:

    The rendered HTML for the field. This does not need to be marked as safe (but can be), as it will be passed in as an escaped JavaScript string.

    Return type:

    unicode

    class ConditionValueFormField(field)[source]¶

    Bases: BaseConditionValueField

    Condition value wrapper for HTML form fields.

    This allows the usage of standard HTML form fields (through Django’s django.forms module) for rendering and accepting condition values.

    Callers simply need to instantiate the class along with a form field.

    The rendered field must support setting and getting a value attribute on the DOM element, like a standard HTML form field.

    Example

    value_field = ConditionValueFormField(

    forms.ModelMultipleChoiceField(queryset=MyModel.objects.all()))

    js_model_class = 'Djblets.Forms.ConditionValueField'[source]¶

    The JavaScript model class for representing field state.

    This is instantiated on the web UI and is used to store any model data provided by get_js_model_data().

    The default is a simple model that just stores the model data as attributes.

    js_view_class = 'Djblets.Forms.ConditionValueFormFieldView'[source]¶

    The JavaScript view class for editing fields.

    This is instantiated on the web UI and is used to provide an editor for the condition’s value.

    It’s passed any options that are returned from get_js_model_data().

    __init__(field)[source]¶

    Initialize the value field.

    Parameters:

    field (django.forms.fields.Field) – The Django form field instance for the value. This may also be a callable that returns a field.

    property field[source]¶

    The form field to use for the value.

    This will always return a Field, but can be given a callable that returns a field when set.

    serialize_value(value)[source]¶

    Serialize a Python object into a JSON-compatible serialized form.

    This is responsible for taking a Python value/object of some sort (string, list, or anything more complex) and returning a JSON-compatible form for serialization. It will use the form field to do this (through Field.prepare_value()).

    Parameters:

    value (object) – The value to serialize.

    Returns:

    The JSON-compatible serialized value.

    Return type:

    object

    deserialize_value(value_data)[source]¶

    Deserialize a value back into a Python object.

    This is responsible for taking a value serialized by serialize_value() and returning a suitable Python object/value. It will use the form field to do this (through Field.clean()).

    By default, this returns the value as-is.

    Parameters:

    serialized_value (object) – The serialized value to deserialize.

    Returns:

    The deserialized value.

    Return type:

    object

    Raises:

    djblets.conditions.errors.InvalidConditionValueError – Error deserializing or validating the data.

    get_from_form_data(data, files, name)[source]¶

    Return a value from a form data dictionary.

    This attempts to return the value for a condition from Django form data. It’s passed a dictionary of data, uploaded files, and the name of the appropriate value field. It will use the form field’s widget to do this (through Widget.value_from_datadict).

    Parameters:
    • data (django.http.request.QueryDict) – The dictionary containing form data.

    • files (django.http.request.QueryDict) – The dictionary containing uploaded files.

    • name (unicode) – The field name for the value to load.

    Returns:

    The value from the form data.

    Return type:

    object

    render_html()[source]¶

    Return rendered HTML for the field.

    The rendered HTML will be generated by the widget for the field, and will be dynamically inserted by the JavaScript UI.

    Returns:

    The rendered HTML for the field.

    Return type:

    unicode

    __annotations__ = {}¶
    class ConditionValueBooleanField(**field_kwargs)[source]¶

    Bases: ConditionValueFormField

    Condition value wrapper for boolean form fields.

    This is a convenience for condition values that want to use a BooleanField. It accepts the same keyword arguments in the constructor that the field itself accepts.

    It also specially serializes the value to a string for use in the JavaScript widget.

    Example

    value_field = ConditionValueBooleanField(initial=True)

    __init__(**field_kwargs)[source]¶

    Initialize the value field.

    Parameters:

    **field_kwargs (dict) – Keyword arguments to pass to the BooleanField constructor.

    prepare_value_for_widget(value)[source]¶

    Return a value suitable for use in the widget.

    This will convert a boolean value to a string, so that it can be properly matched against the string choices for the select box.

    Parameters:

    value (bool) – The value to prepare for the widget.

    Returns:

    The string value for the widget.

    Return type:

    unicode

    __annotations__ = {}¶
    class ConditionValueCharField(**field_kwargs)[source]¶

    Bases: ConditionValueFormField

    Condition value wrapper for single-line text form fields.

    This is a convenience for condition values that want to use a CharField. It accepts the same keyword arguments in the constructor that the field itself accepts.

    Example

    value_field = ConditionValueCharField(max_length=100)

    __init__(**field_kwargs)[source]¶

    Initialize the value field.

    Parameters:

    **field_kwargs (dict) – Keyword arguments to pass to the CharField constructor.

    __annotations__ = {}¶
    class ConditionValueIntegerField(**field_kwargs)[source]¶

    Bases: ConditionValueFormField

    Condition value wrapper for integer form fields.

    This is a convenience for condition values that want to use a IntegerField. It accepts the same keyword arguments in the constructor that the field itself accepts.

    Example

    value_field = ConditionValueIntegerField(min_value=0, max_value=100)

    __init__(**field_kwargs)[source]¶

    Initialize the value field.

    Parameters:

    **field_kwargs (dict) – Keyword arguments to pass to the IntegerField constructor.

    __annotations__ = {}¶
    class ConditionValueMultipleChoiceField(**field_kwargs)[source]¶

    Bases: ConditionValueFormField

    Condition value wrapper for multiple choice fields.

    This is a convenience for condition values that want to use a MultipleChoiceField. It accepts the same keyword arguments in the constructor that the field itself accepts.

    New in version 3.0.

    Example

    value_field = ConditionValueMultipleChoiceField(
        choices=[
            ('value1', 'Value 1'),
            ('value2', 'Value 2'),
        ])
    
    __init__(**field_kwargs)[source]¶

    Initialize the value field.

    Parameters:

    **field_kwargs (dict) – Keyword arguments to pass to the MultipleChoiceField constructor.

    __annotations__ = {}¶
    class ConditionValueModelField(queryset, **field_kwargs)[source]¶

    Bases: ConditionValueFormField

    Condition value wrapper for single model form fields.

    This is a convenience for condition values that want to use a ModelChoiceField. It accepts the same keyword arguments in the constructor that the field itself accepts.

    Unlike the standard field, the provided queryset can be a callable that returns a queryset.

    Example

    value_field = ConditionValueModelField(queryset=MyObject.objects.all())

    __init__(queryset, **field_kwargs)[source]¶

    Initialize the value field.

    Parameters:
    • queryset (django.db.models.query.QuerySet) – The queryset used for the field. This may also be a callable that returns a queryset.

    • **field_kwargs (dict) – Keyword arguments to pass to the ModelChoiceField constructor.

    __annotations__ = {}¶
    class ConditionValueMultipleModelField(queryset, **field_kwargs)[source]¶

    Bases: ConditionValueFormField

    Condition value wrapper for multiple model form fields.

    This is a convenience for condition values that want to use a ModelMutipleChoiceField. It accepts the same keyword arguments in the constructor that the field itself accepts.

    Unlike the standard field, the provided queryset can be a callable that returns a queryset.

    Example

    value_field = ConditionValueMultipleModelField(

    queryset=MyObject.objects.all())

    __init__(queryset, **field_kwargs)[source]¶

    Initialize the value field.

    Parameters:
    • queryset (django.db.models.query.QuerySet) – The queryset used for the field. This may also be a callable that returns a queryset.

    • **field_kwargs (dict) – Keyword arguments to pass to the ModelChoiceField constructor.

    __annotations__ = {}¶
    class ConditionValueRegexField(**field_kwargs)[source]¶

    Bases: ConditionValueCharField

    Condition value for fields that accept regexes.

    This value accepts and validates regex patterns entered into the field.

    Example

    value_field = ConditionValueRegexField()

    __annotations__ = {}¶
    serialize_value(value)[source]¶

    Serialize a compiled regex into a string.

    Parameters:

    value (object) – The value to serialize.

    Returns:

    The JSON-compatible serialized value.

    Return type:

    object

    deserialize_value(value_data)[source]¶

    Deserialize a regex pattern string into a compiled regex.

    Parameters:

    value_data (unicode) – The serialized regex pattern to compile.

    Returns:

    The deserialized value.

    Return type:

    object

    Raises:

    djblets.conditions.errors.InvalidConditionValueError – The regex could not be compiled.

    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]
    • BaseConditionValueField
      • BaseConditionValueField.js_model_class
      • BaseConditionValueField.js_view_class
      • BaseConditionValueField.serialize_value()
      • BaseConditionValueField.deserialize_value()
      • BaseConditionValueField.get_from_form_data()
      • BaseConditionValueField.prepare_value_for_widget()
      • BaseConditionValueField.get_js_model_data()
      • BaseConditionValueField.get_js_view_data()
      • BaseConditionValueField.render_html()
    • ConditionValueFormField
      • ConditionValueFormField.js_model_class
      • ConditionValueFormField.js_view_class
      • ConditionValueFormField.__init__()
      • ConditionValueFormField.field
      • ConditionValueFormField.serialize_value()
      • ConditionValueFormField.deserialize_value()
      • ConditionValueFormField.get_from_form_data()
      • ConditionValueFormField.render_html()
      • ConditionValueFormField.__annotations__
    • ConditionValueBooleanField
      • ConditionValueBooleanField.__init__()
      • ConditionValueBooleanField.prepare_value_for_widget()
      • ConditionValueBooleanField.__annotations__
    • ConditionValueCharField
      • ConditionValueCharField.__init__()
      • ConditionValueCharField.__annotations__
    • ConditionValueIntegerField
      • ConditionValueIntegerField.__init__()
      • ConditionValueIntegerField.__annotations__
    • ConditionValueMultipleChoiceField
      • ConditionValueMultipleChoiceField.__init__()
      • ConditionValueMultipleChoiceField.__annotations__
    • ConditionValueModelField
      • ConditionValueModelField.__init__()
      • ConditionValueModelField.__annotations__
    • ConditionValueMultipleModelField
      • ConditionValueMultipleModelField.__init__()
      • ConditionValueMultipleModelField.__annotations__
    • ConditionValueRegexField
      • ConditionValueRegexField.__annotations__
      • ConditionValueRegexField.serialize_value()
      • ConditionValueRegexField.deserialize_value()