Package: wagtail-bynder
Bynder integration for WagtailLinksDocumentationChangelogContributingDiscussionsSecurityBynderis a Digital Asset Management System (DAMS) and platform that allows organisations
to manage their digital assets, which includes the images and documents used in Wagtail content.The data flow is one way: Bynder assets are always treated as the source of truth, and Wagtail uses read-only API access
to create copies of assets and keep them up-to-date.How it worksThe main points of integration are Wagtail's image and document chooser views, which are patched by this app to show an
asset selection UI for Bynder instead of a list of Wagtail images or documents.When an asset is selected, Wagtail silently downloads the file and related metadata, and saves it as anImageorDocumentobject, allowing it to be used in a typical way. The ID of the selected asset (as well as a few other bits of data)
are saved on the object when this happens, helping Wagtail to recognise when it already has a copy of an asset,
and to help keep them up-to-date with changes made in Bynder.Currently, changes are synced from Bynder back to Wagtail via a few well-optimised management commands,
intended to be run regularly (via a cron job):python manage.py update_stale_imagespython manage.py update_stale_documentspython manage.py update_stale_videosBy default, these commands only fetch data for assets updated within the last 24 hours. However, you can use theminutes,hoursordaysoptions to narrow or widen this timespan. For example:To sync images updated within the last 30 minutes only:$pythonmanage.pyupdate_stale_images--minutes=30To sync images updated within the last three hours only:$pythonmanage.pyupdate_stale_images--hours=3To sync images updated within the last three days:$pythonmanage.pyupdate_stale_images--days=3InstallationIn your project's Django settings, add the app yourINSTALLED_APPSlist (at the end is fine):INSTALLED_APPS=[# ..."wagtail_bynder",]Then add the following to theMIDDLEWARElist (at the end is fine):MIDDLEWARE=[#..."wagtail_bynder.middleware.PatchWagtailURLsMiddleware",]Import the abstractBynderSyncedImagemodel and have your project's custom image model definition subclass it instead
ofwagtail.images.models.AbstractImage. For example# yourproject/images/models.pyfromwagtail_bynder.modelsimportBynderSyncedImageclassCustomImage(BynderSyncedImage):passImport the abstractBynderSyncedDocumentmodel and have your project's custom document model definition subclass it instead ofwagtail.documents.models.AbstractDocument. For example:# yourproject/documents/models.pyfromwagtail_bynder.modelsimportBynderSyncedDocumentclassCustomDocument(BynderSyncedDocument):passFinally, run Django'smakemigrationsandmigratecommands to apply any model field changes to your project$pythonmanage.pymakemigrations
$pythonmanage.pymigrateOptional: To use videos from BynderTo use videos from Bynder in content across the site, this app includes a specialised model to help store relevant data for videos,
plus blocks and chooser widgets to help use them in your project. However, because not all projects use video,
and project-specific requirements around video usage can be a little more custom,
the model isabstract- you need to subclass it in order to use the functionality.First, ensure you havewagtail.snippetsin your project'sINSTALLED_APPS:INSTALLED_APPS = [
  # ...
  "wagtail.users",
  "wagtail.admin",
  "wagtail.documents",
  "wagtail.images",
  "wagtail.snippets",
  "wagtail",
   # ...
]Next, import the abstractBynderSyncedVideomodel and subclass it within your project to create a concrete model.
For example:# yourproject/videos/models.pyfromwagtail_bynder.modelsimportBynderSyncedVideoclassVideo(BynderSyncedVideo):passThen, in your project's Django settings, add aBYNDER_VIDEO_MODELitem to establish your custom model as the 'official'
video model. The value should be a string in the format"app_label.Model". For example:BYNDER_VIDEO_MODEL="videos.Video"Finally, run Django'smakemigrationsandmigratecommands to create and apply the model changes in your project.$pythonmanage.pymakemigrations
$pythonmanage.pymigrateConfigurationYou can use the following settings to configure the integration:BYNDER_DOMAINExample:"your-org.bynder.com"Default:NoneThe Bynder instance you want the environment to use.BYNDER_API_TOKENExample:"60ae04f68460cfed1b289c4c1db4c9b273b238dx2030c51298dcad245b5ff1f8"Default:NoneAn API token for the back end to use when talking to the Bynder API.
NOTE: This could be more permissive thanBYNDER_COMPACTVIEW_API_TOKEN, so should be kept separate to avoid surfacing to Wagtail users.BYNDER_COMPACTVIEW_API_TOKENExample:"64ae04f71460cfed1b289c4c1db4c9b273b238dx2030c51298dcad245b5ff1f8"Default:NoneAn API token for Bynder's JavaScript 'compact view' to use. The value is injected into theadmin_base.htmltemplate for Wagtail
for the JavaScript to pick up, exposing it to Wagtail users. Because of this, it should be different toBYNDER_API_TOKENand only needs to have basic read permissions.BYNDER_IMAGE_SOURCE_THUMBNAIL_NAMEExample:"WagtailSource"Default:"webimage"The name of the automatically generated derivative that should be downloaded and used as thefilevalue for the
representative Wagtail image (as it appears inthumbnailsin the API representation).WARNING: It's important to get this right, because if the specified derivative is NOT present in the response for an
image for any reason, the ORIGINAL will be downloaded - which will lead to slow chooser response times and higher memory
usage when generating renditions.BYNDER_VIDEO_MODELExample:"video.Video"Default:NoneBYNDER_VIDEO_PRIMARY_DERIVATIVE_NAMEDefault:"Web-Primary"BYNDER_VIDEO_FALLBACK_DERIVATIVE_NAMEDefault:"Web-Fallback"BYNDER_VIDEO_POSTER_IMAGE_DERIVATIVE_NAMEDefault:"webimage"BYNDER_SYNC_EXISTING_IMAGES_ON_CHOOSEExample:TrueDefault:FalseWhenTrue, local copies of images will be refreshed from the Bynder API representation whenever they are selected in
the chooser interface. This slows down the chooser experience slightly, but can be useful for seeing up-to-date data in
environments that might not be using the management commands or other means to keep images up-to-date with their Bynder counterparts.BYNDER_SYNC_EXISTING_DOCUMENTS_ON_CHOOSEExample:TrueDefault:FalseAsBYNDER_SYNC_EXISTING_IMAGES_ON_CHOOSE, but for documents.BYNDER_SYNC_EXISTING_VIDEOS_ON_CHOOSEExample:TrueDefault:FalseAsBYNDER_SYNC_EXISTING_IMAGES_ON_CHOOSE, but for videos.BYNDER_DISABLE_WAGTAIL_EDITING_FOR_ASSETSExample:TrueDefault:FalseWhenTrue, hitting Wagtail's built-in edit view for an image or document will result in a redirect to the asset
detail view in the Bynder interface.The default is value isFalse, because it can be useful to use the Wagtail representation to check that file, metadata
and focal points are being accurately reflected.ContributingAll contributions are welcome! SeeCONTRIBUTING.mdSupported versions:Python 3.11, 3.12Django 3.2, 4.2, 5.0Wagtail 4.1 (LTS), 5.1, 5.2 (LTS)