• 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 4.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.privacy.consent.forms
  • 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.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.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.feedview.views
  • djblets.feedview.templatetags.feedtags
  • 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
  • This documentation covers Djblets 4.x. You can select a version above or view the latest documentation.

    djblets.privacy.consent.forms¶

    Forms, fields, and widgets for gathering and displaying consent.

    class ConsentRequirementWidget(consent_requirement=None, attrs=None)[source]¶

    Bases: Widget

    A widget for displaying and gathering consent information.

    This presents the consent requirement in an easy-to-digest form, and makes it easy for users to choose to allow or block the thing requiring consent.

    This is meant to be used with ConsentRequirementField.

    __init__(consent_requirement=None, attrs=None)[source]¶

    Initialize the widget.

    Parameters:
    • consent_requirement (djblets.privacy.consent.base.ConsentRequirement, optional) – The consent requirement information. If not provided, this must be directly set on the instance before rendering the widget.

    • attrs (dict, optional) – HTML attributes for the widget. This is used only to set an id attribute for the field.

    render(name, value, attrs=None, renderer=None)[source]¶

    Render the widget.

    Parameters:
    • name (unicode) – The base name used for the <input> elements. Specific names will be composed from this.

    • value (unicode) – The current value for the field.

    • attrs (dict, optional) – HTML attributes for the widget. This is used only to set an id attribute for the field.

    • renderer (django.forms.renderers.BaseRenderer, optional) – The form renderer.

    Returns:

    The rendered HTML for the widget.

    Return type:

    django.utils.safestring.SafeText

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

    Return the field value from the submitted form data.

    Parameters:
    • data (dict) – The submitted form data.

    • files (dict, unused) – The submitted files data.

    • name (unicode) – The base name for the form fields.

    Returns:

    A value for the fields. This will be one of ConsentRequirementField.ALLOW, ConsentRequirementField.BLOCK, or None.

    Return type:

    unicode

    __annotations__ = {}¶
    class MultiConsentRequirementsWidget(consent_requirements, attrs=None)[source]¶

    Bases: MultiWidget

    A widget for displaying and gathering multiple consent information.

    This adds a ConsentRequirementWidget for each consent requirement provided to the widget.

    This is meant to be used with MultiConsentRequirementsField.

    __init__(consent_requirements, attrs=None)[source]¶

    Initialize the widget.

    Parameters:
    • consent_requirements (list of djblets.privacy.consent.base.ConsentRequirement) – The list of consent requirements.

    • attrs (dict, optional) – HTML attributes for the widget. This is used only to set an id attribute for the field.

    render(name, value, attrs=None, renderer=None)[source]¶

    Render the widget.

    Parameters:
    • name (unicode) – The base name used for the <input> elements. Specific names will be composed from this.

    • value (list of unicode) – The current values for the fields.

    • attrs (dict, optional) – HTML attributes for the widget. This is used only to set a base id attribute for the fields.

    • renderer (django.forms.renderers.BaseRenderer, optional) – The form renderer.

    Returns:

    The rendered HTML for the widget.

    Return type:

    django.utils.safestring.SafeText

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

    Return the field values from the submitted form data.

    Parameters:
    • data (dict) – The submitted form data.

    • files (dict, unused) – The submitted files data.

    • name (unicode) – The base name for the form fields.

    Returns:

    A list of values for all the fields, in the order of the list of consent requirements provided to the widget. Each item will be one of ConsentRequirementField.ALLOW, ConsentRequirementField.BLOCK, or None.

    Return type:

    list of unicode

    decompress(value)[source]¶

    Decompress a list of values for the widget.

    This is required by the parent class, and is responsible for taking the provided data and returning a list of values that can be used for the sub-widgets.

    Parameters:

    value (list) – The list of values (or None) to normalize and return.

    Returns:

    The resulting list of values. This may be empty.

    Return type:

    list of unicode

    __annotations__ = {}¶
    class ConsentRequirementField(consent_requirement, user=None, consent_source=None, extra_consent_data=None, **kwargs)[source]¶

    Bases: ChoiceField

    A form field for displaying and gathering consent information.

    This presents the consent requirement in an easy-to-digest form, and makes it easy for users to choose to allow or block the thing requiring consent.

    The cleaned result from this field is a ConsentData instance, which can be recorded directly in the tracker.

    ALLOW = 'allow'[source]¶
    BLOCK = 'block'[source]¶
    CHOICES = (('allow', 'Allow'), ('block', 'Block'))[source]¶
    widget[source]¶

    alias of ConsentRequirementWidget

    default_error_messages = {'required': 'You must choose Allow or Block to continue.'}[source]¶
    __init__(consent_requirement, user=None, consent_source=None, extra_consent_data=None, **kwargs)[source]¶

    Initialize the field.

    Parameters:
    • consent_requirement (djblets.privacy.consent.base.ConsentRequirement) – The consent requirement information.

    • user (django.contrib.auth.models.User, optional) – The user viewing the form. If provided, the default value for the field will be based on the choice already made by the user, if any.

    • consent_source (unicode, optional) – The source to record in the consent audit trail for the consent choice saved in this field.

    • extra_consent_data (dict, optional) – Extra information to record in the consent audit trail for the consent choice saved in this field.

    • **kwargs (dict) – Additional keyword arguments to pass to the parent class.

    set_initial_from_user(user)[source]¶

    Set the initial state of the field based on a user’s prior consent.

    This is called automatically if passing a user to the constructor. Otherwise, it should be called manually when setting up a form.

    Parameters:

    user (django.contrib.auth.models.User) – The user viewing the form.

    prepare_value(value)[source]¶

    Prepare a value for use in the field.

    This will convert a Consent value to a value suitable for use in the field.

    Parameters:

    value (djblets.privacy.consent.base.Consent) – The value to convert.

    Returns:

    A valid value for use in the field.

    Return type:

    unicode

    clean(value)[source]¶

    Clean and return a value from submitted form data.

    Parameters:

    value (unicode) – A value submitted by the client.

    Returns:

    The cleaned consent data value, or None if a suitable value was not provided.

    Return type:

    djblets.privacy.consent.base.ConsentData

    __annotations__ = {}¶
    class MultiConsentRequirementsField(consent_requirements=None, user=None, consent_source=None, extra_consent_data=None, *args, **kwargs)[source]¶

    Bases: MultiValueField

    A form field for displaying and gathering mulltiple consent information.

    This provides a ConsentRequirementField for each consent requirement provided to the field (or all registered ones if an explicit list was not provided). It’s handy for forms that offer all consent choices to the user.

    The cleaned result from this field is a list of ConsentData instances, which can be recorded directly in the tracker.

    default_error_messages = {'required': 'You must choose Allow or Block for all options to continue.'}[source]¶
    widget[source]¶

    alias of MultiConsentRequirementsWidget

    __init__(consent_requirements=None, user=None, consent_source=None, extra_consent_data=None, *args, **kwargs)[source]¶

    Initialize the field.

    Parameters:
    • consent_requirements (list of djblets.privacy.consent.base.ConsentRequirement, optional) – The list of consent requirements to display. If not provided, all registered consent requirements will be used.

    • user (django.contrib.auth.models.User, optional) – The user viewing the form. If provided, the default options for each field will be based on the choices already made by the user.

    • consent_source (unicode, optional) – The source to record in the consent audit trail for anything saved in this field.

    • extra_consent_data (dict, optional) – Extra information to record in the consent audit trail for anything saved in this field.

    • *args (tuple) – Additional positional arguments to pass to the parent class.

    • **kwargs (dict) – Additional keyword arguments to pass to the parent class.

    set_initial_from_user(user)[source]¶

    Set the initial state of the field based on a user’s prior consent.

    This is called automatically if passing a user to the constructor. Otherwise, it should be called manually when setting up a form.

    Parameters:

    user (django.contrib.auth.models.User) – The user viewing the form.

    prepare_value(value)[source]¶

    Prepare a value for use in the field.

    This will convert a list of Consent values given in the order of the field’s list of requirements to values suitable for use in the field.

    Parameters:

    value (list of list djblets.privacy.consent.base.Consent) – The list of values to convert.

    Returns:

    A list of values suitable for use in the field.

    Return type:

    list of unicode

    clean(value)[source]¶

    Clean and return values from submitted form data.

    Parameters:

    value (list of unicode) – A list of values submitted by the client.

    Returns:

    The list of cleaned consent data values.

    Return type:

    list of djblets.privacy.consent.base.ConsentData

    compress(data_list)[source]¶

    Compress cleaned values for the field.

    This is required by the parent class, and is responsible for taking a list of cleaned values and returning something that can be validated and returned. This implementation returns the data as-is.

    Parameters:

    data_list (list of djblets.privacy.consent.base.ConsentData) – The list of cleaned data.

    Returns:

    The list of data.

    Return type:

    list of djblets.privacy.consent.base.ConsentData

    __annotations__ = {}¶
    class ConsentFormMixin(*args, **kwargs)[source]¶

    Bases: object

    A mixin for forms that present registered consent requirements.

    This can be mixed into a form to provide consent field initialization and saving.

    consent_field_name = 'consent'[source]¶

    The name of the consent field.

    __init__(*args, **kwargs)[source]¶

    Initialize the form.

    Parameters:
    • *args (tuple) – Positional arguments passed to the form.

    • **kwargs (dict) – Keyword arguments passed to the form.

    get_consent_user()[source]¶

    Return the user deciding on consent.

    This must be implemented by subclasses.

    Returns:

    The user deciding on consent.

    Return type:

    django.contrib.auth.models.User

    get_consent_source()[source]¶

    Return a source to record in the consent audit trail.

    This must be implemented by subclasses.

    Returns:

    The source to record for each consent entry.

    Return type:

    unicode

    get_extra_consent_data()[source]¶

    Return extra data to record in the consent audit trail.

    By default, this just returns an empty dictionary.

    Returns:

    Extra data to record for each consent entry.

    Return type:

    dict

    save_consent(user)[source]¶

    Save the consent information recorded in the form.

    Parameters:

    user (django.contrib.auth.models.User) – The user who made the consent decisions.

    class ConsentConfigPageFormMixin(*args, **kwargs)[source]¶

    Bases: ConsentFormMixin

    A mixin for config forms that present registered consent requirements.

    This can be mixed into a config form to provide consent field initialization and saving. It would be used instead of ConsentFormMixin.

    form_id = 'privacy_consent'[source]¶
    form_title = 'Privacy Consent'[source]¶
    save()[source]¶

    Save the form.

    This will save the consent information from the field.

    get_consent_user()[source]¶

    Return the user deciding on consent.

    Returns:

    The user deciding on consent.

    Return type:

    django.contrib.auth.models.User

    get_consent_source()[source]¶

    Return a source to record in the consent audit trail.

    By default, this returns the absolute URL for the page.

    Returns:

    The source to record for each consent entry.

    Return type:

    unicode

    __annotations__ = {}¶

    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]
    • ConsentRequirementWidget
      • ConsentRequirementWidget.__init__()
      • ConsentRequirementWidget.render()
      • ConsentRequirementWidget.value_from_datadict()
      • ConsentRequirementWidget.__annotations__
    • MultiConsentRequirementsWidget
      • MultiConsentRequirementsWidget.__init__()
      • MultiConsentRequirementsWidget.render()
      • MultiConsentRequirementsWidget.value_from_datadict()
      • MultiConsentRequirementsWidget.decompress()
      • MultiConsentRequirementsWidget.__annotations__
    • ConsentRequirementField
      • ConsentRequirementField.ALLOW
      • ConsentRequirementField.BLOCK
      • ConsentRequirementField.CHOICES
      • ConsentRequirementField.widget
      • ConsentRequirementField.default_error_messages
      • ConsentRequirementField.__init__()
      • ConsentRequirementField.set_initial_from_user()
      • ConsentRequirementField.prepare_value()
      • ConsentRequirementField.clean()
      • ConsentRequirementField.__annotations__
    • MultiConsentRequirementsField
      • MultiConsentRequirementsField.default_error_messages
      • MultiConsentRequirementsField.widget
      • MultiConsentRequirementsField.__init__()
      • MultiConsentRequirementsField.set_initial_from_user()
      • MultiConsentRequirementsField.prepare_value()
      • MultiConsentRequirementsField.clean()
      • MultiConsentRequirementsField.compress()
      • MultiConsentRequirementsField.__annotations__
    • ConsentFormMixin
      • ConsentFormMixin.consent_field_name
      • ConsentFormMixin.__init__()
      • ConsentFormMixin.get_consent_user()
      • ConsentFormMixin.get_consent_source()
      • ConsentFormMixin.get_extra_consent_data()
      • ConsentFormMixin.save_consent()
    • ConsentConfigPageFormMixin
      • ConsentConfigPageFormMixin.form_id
      • ConsentConfigPageFormMixin.form_title
      • ConsentConfigPageFormMixin.save()
      • ConsentConfigPageFormMixin.get_consent_user()
      • ConsentConfigPageFormMixin.get_consent_source()
      • ConsentConfigPageFormMixin.__annotations__