Skip to main content

Mediaflow image plugin for Wagtail

Installation

  pip install mediaflowimage

Edit your site settings file

  • Add "mediaflowimage" to the array INSTALLED_APPS

  • Tell Wagtail to use a custom image form

    WAGTAILIMAGES_IMAGE_FORM_BASE = 'mediaflowimage.forms.MediaflowImageForm'
    
  • Add the API keys for the plugin (consult Mediaflow Support to get API keys)

    MEDIAFLOW_CLIENT_ID = <YOUR SERVER ID>
    MEDIAFLOW_CLIENT_SECRET = <YOUR CLIENT SECRET>
    MEDIAFLOW_SERVER_KEY = <YOUR SERVER KEY>
    

Using the plugin

The plugin adds a new tab to the Image Creation Form. This works for inserting images in the Draftail editor as well as from an ImageChooserBlock. The tab lists all Mediaflow files that are shared to the integration. To insert an image, simply select it from the file selector. This will download the image from Mediaflow and store it to your configured Media location.

Custom Image models

The image plugin works out of the box with the default wagtail image model, but if you want to map Mediaflow image metadata properties to wagtail images you need to use a custom image model. A custom image model is also required if you want to log image file usages in Mediaflow.

The fields of your image model can be mapped so that they are automatically populated when you insert (upload) an image from mediaflow. This is done by defining a mapping in your settings file like this:

MEDIAFLOW_META_MAPPING  = {   
    "photographer": "mf_photographer",    
    "description": "mf_description",    
    "id" : "mf_mediaflow_id"
}

The keys of the object in this example refer to the Mediaflow fields and each corresponding value refers to a field name in your image model. In the example above, the Mediaflow field photographer is mapped the the field mf_photographer of your image model.

If you need image usage reporting, the MEDIAFLOW_META_MAPPING must have a key id that is mapped to a field in your image model ("mf_mediaflow_id" in the example) . Furthermore, your image model must have a custom rendition model that adds the data-mf-image-id attribute on all rendered images.

An example custom image class that has a Mediaflow Id field and a custom rendition is provided below. The image model field names correspond to the field names given in the setting MEDIAFLOW_META_MAPPING above:

from django.conf import settings
from django.db import models
from django.utils.functional import cached_property
from wagtail.images.models import AbstractImage, AbstractRendition, Image  

class MyImage(AbstractImage):
    # Add any extra fields to image here    
    # To add a caption field:
    photographer = models.CharField(max_length=255, blank=True)
    description = models.CharField(max_length=255, blank=True)
    mediaflow_id = models.IntegerField(blank=True, default=0)
    admin_form_fields = Image.admin_form_fields + (
        # Then add the field names here to make them appear in the form:
        "description",
        "photographer",
        "mediaflow_id",
    )
        
class CustomRendition(AbstractRendition):
    image = models.ForeignKey(
        MyImage, on_delete=models.CASCADE, related_name="renditions"
    )

    @cached_property
    def getIdField(self):
        meta_mapping = getattr(settings, "MEDIAFLOW_META_MAPPING", "")
        for key in meta_mapping:
            if key == "id":                
                return getattr(self.image, meta_mapping[key])
        return 0
    
    
    @property
    def attrs_dict(self):
        attrs = super().attrs_dict
        idField = self.getIdField
        
        if idField > 0:
            attrs["data-mf-image-id"] = idField        
        return attrs

    class Meta:
        unique_together = (("image", "filter_spec", "focal_point_key"),)

Useful references

Metadata

Release files for mediaflowimage 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mediaflowimage 1.0.6
File Size Uploaded
mediaflowimage-1.0.6.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mediaflowimage 1.0.6
File Interpreter ABI Platform
mediaflowimage-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / mediaflowimage-1.0.6.tar.gz

Download URL mediaflowimage-1.0.6.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a5a36c67ad4b4ede156c4d1ab03d41b2a863d96df7bb2d9a9a2645bbe588c25f
BLAKE2b-256 checksum
How to use checksums
1f323a8f31cd80e403763d90621aa8844e99abc43764b48c274c65ea886cc4b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.2

Release files / mediaflowimage-1.0.6-py3-none-any.whl

Download URL mediaflowimage-1.0.6-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a4873e3c7b4ad6ededf9bbab3dd6f42da68366f832a35f37a6f40eb959fb987
BLAKE2b-256 checksum
How to use checksums
908650aece14038b518a4e5450f6d1da27ccb464f43645532229cd0023f7b2d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.2

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page