Skip to main content

Wagtail image plugin for Mediaflow

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mediaflowimage-1.0.2.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mediaflowimage-1.0.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file mediaflowimage-1.0.2.tar.gz.

File metadata

  • Download URL: mediaflowimage-1.0.2.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.2

File hashes

Hashes for mediaflowimage-1.0.2.tar.gz
Algorithm Hash digest
SHA256 3f456f7915e282b0c31f2c71603314071f58a15763b6d28e6f3625ea3a8f3fc9
MD5 b8c6dd3ab32f8a9622a791a6ad6170f2
BLAKE2b-256 2cc4d0ccdd32a18a1c5fa29165d2fff518fc6d2bfaca0cee565376edbd9dec9d

See more details on using hashes here.

File details

Details for the file mediaflowimage-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: mediaflowimage-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.2

File hashes

Hashes for mediaflowimage-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 10ae15c03db56fb2e4cb145f5a45587ce3fff22077c44d3c26b91e809bd6889a
MD5 a3058273d901522063779603d92930e7
BLAKE2b-256 16fce1b7598ab44d6273768b7df74ff1ec6ecb80f948e97b89f4c810b72ec8c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page