• 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. Guides
    11. Integration Guides
    12. Supporting Integrations
  • 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
  • Supporting Integrations¶

    Overview¶

    Integrations provide a friendly way for an application to allow users to link up with multiple services. An application can provide support for any number of integrations, and give users a way to manage them. Much of this is provided out of the box for you, including administration pages, but there are a few things the application must do in order to support integrations.

    This guide will cover everything you need to integrate with the Djblets Integrations framework.

    Architecture¶

    To start with, let’s discuss the architecture.

    Integrations are subclasses of Integration. There’s only ever one instance per class. Each instance may have zero or more configurations, defined as an application-provided subclass of BaseIntegrationConfig.

    Integrations and configurations are managed by an instance of IntegrationManager.

    Many classes need to know about the manager instance, which can’t be determined automatically (and, theoretically, there may be multiple managers in a single application). These classes will inherit from NeedsIntegrationManagerMixin. It’s the application’s responsibility to subclass these classes and provide the necessary method for returning the integration, which we’ll get to later.

    IntegrationConfigForm provides UI and logic for creating or editing integration configurations.

    BaseIntegrationHook provides base support for an extension hook, which is useful if you’re supporting extensions in your application.

    There are views for listing and configuring integrations. These must be subclassed, which we’ll cover in more detail.

    Getting Started¶

    Updating Settings¶

    First, you’ll need to update your Django settings in order to use the integrations framework.

    We’re going to assume in these examples that you’re creating a new myproject.integrations app. Put that and djblets.integrations in your settings.INSTALLED_APPS, like so:

    INSTALLED_APPS = [
        ...
        'djblets.integrations',
        'myproject.integrations',
        ...
    ]
    

    Now add the middleware:

    MIDDLEWARE = [
        ...
        'djblets.integrations.middleware.IntegrationsMiddleware',
        ...
    ]
    

    If you’re also using djblets.extensions, make sure to include this after the extensions middleware:

    MIDDLEWARE = [
        ...
        'djblets.extensions.middleware.ExtensionsMiddleware',
        'djblets.integrations.middleware.IntegrationsMiddleware',
        ...
    ]
    

    Setting up IntegrationManager¶

    Your application will need an instance of IntegrationManager. This should only be created once per process, and every request for this manager must receive the same instance.

    When constructing the manager, a subclass of BaseIntegrationConfig will need to be provided. We’ll go into what’s needed here, but keep this in mind for now.

    Let’s put this in myproject/integrations/base.py. You’ll want something like:

    from djblets.integrations.manager import IntegrationManager
    
    
    _integration_manager = None
    
    
    def get_integration_manager():
        global _integration_manager
    
        if not _integration_manager:
            _integration_manager = IntegrationManager(MyIntegrationConfig)
    
        return _integration_manager
    

    You now have a handy function for getting the same instance, and for using your MyIntegrationConfig (which you’ll create soon).

    You’re also going to want a mixin that provides this integration manager to various classes. Add:

    class GetIntegrationManagerMixin(object):
        @classmethod
        def get_integration_manager(self):
            return get_integration_manager()
    

    Congrats, you’re one step closer to supporting integrations!

    Creating an IntegrationConfig¶

    BaseIntegrationConfig is the base class for an integration configuration database model. This stores identifying information used to associate the configuration with a given integration, a description of the configuration, the enabled state, settings, and more.

    Applications must have a subclass of this in a myproject/integrations/models.py, providing it to the IntegrationManager as shown above. You’ll want to mix in your GetIntegrationManagerMixin, like so:

    from djblets.integrations.models import BaseIntegrationConfig
    
    from myproject.integrations.base import GetIntegrationManagerMixin
    
    
    class IntegrationConfig(GetIntegrationManagerMixin, BaseIntegrationConfig):
        pass
    

    That’s all you need to do to get started. If you want to add some additional fields (for example, to associate one of these with a specific user, organization, etc.), then you can add fields here. For example:

    Setting Up Views¶

    Now that you have the base foundation for integrations and their configuration and management, you’ll need to get some views going.

    Djblets ships with base views for listing integrations and creating/editing configurations. These are BaseIntegrationListView and BaseIntegrationConfigFormView.

    It also ships with versions intended for use in the administration UI: BaseAdminIntegrationListView and BaseAdminIntegrationConfigFormView.

    In these examples, we’re going to assume you’re using views for the administration UI.

    Whichever views you choose to use will need to be subclassed, using your GetIntegrationManagerMixin above. This is as simple as placing the following in a myproject/integrations/views.py:

    from djblets.integrations.views import (BaseAdminIntegrationConfigFormView,
                                            BaseAdminIntegrationListView)
    
    from myproject.integrations.base import GetIntegrationManagerMixin
    
    
    class AdminIntegrationConfigFormView(GetIntegrationManagerMixin,
                                         BaseAdminIntegrationConfigFormView):
        pass
    
    
    class AdminIntegrationListView(GetIntegrationManagerMixin,
                                   BaseAdminIntegrationListView):
        pass
    

    You can customize some other behavior of these views as well. See their documentation for more information.

    Setting up URLs¶

    Now that you have your views, you’ll need to build URLs for them. In this example, we’ll place them in your myproject/urls.py:

    from django.conf.urls import include, patterns, url
    from djblets.integrations.urls import build_integration_urlpatterns
    
    from myproject.integrations.views import (AdminIntegrationConfigFormView,
                                              AdminIntegrationListView)
    
    
    urlpatterns = patterns(
        '',
    
        url('^admin/integrations/', include(build_integration_urlpatterns(
            list_view_cls=AdminIntegrationListView,
            config_form_view_cls=AdminIntegrationConfigFormView))),
    
        ...
    )
    

    You should now be set! If you go to http://yourserver/admin/integrations/, you should see a list of all your integrations (none, at this moment), and will have UI for configuring them.

    You can now start writing integrations.

    Advanced Usage¶

    Adding Fields to IntegrationConfig¶

    You may want to add some special fields to your configuration model. For instance, you may want to associate it with a user, or an organization model, or maybe you want to store something else entirely.

    To do this, you’ll first need to add the fields to your configuration model. We’ll show this off with a User association:

    from django.contrib.auth.models import User
    from djblets.integrations.models import BaseIntegrationConfig
    
    from myproject.integrations.base import GetIntegrationManagerMixin
    
    
    class IntegrationConfig(GetIntegrationManagerMixin, BaseIntegrationConfig):
        user = models.ForeignKey(User, related_name='integration_configs')
    

    This will give us an association between users and their integration configurations.

    Next, you may want a special subclass of IntegrationConfigForm that can work with this new field:

    from django import forms
    from django.contrib.auth.models import User
    from djblets.integrations.forms import (IntegrationConfigForm as
                                            BaseIntegrationConfigForm)
    
    
    class IntegrationConfigForm(BaseIntegrationConfigForm):
        model_fields = (
            BaseIntegrationConfigForm.model_fields +
            ('user',)
        )
    
        user = forms.ModelChoiceField(
            label='User',
            queryset=User.objects.all(),
            required=True)
    

    This gives you a form that will contain these extra fields. Note that these fields will, in the default template, be presented to the user. This may not be what you want, depending on your use case!

    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]
    • Overview
      • Architecture
    • Getting Started
      • Updating Settings
      • Setting up IntegrationManager
      • Creating an IntegrationConfig
      • Setting Up Views
      • Setting up URLs
    • Advanced Usage
      • Adding Fields to IntegrationConfig