Skip to main content

Allows users to combine a Wagtail images with custom annotation data. Annotations are entered in the admin by clicking points on an image, annotation data is then stored with relative x,y coordinates and optional extra form data.

annotation-demo.gif

Requirements

  • Wagtail >= 2.7

  • Django >= 2.0

Installing

Install using pypi and add wagtail-annotations to your INSTALLED_APPS

pip install wagtail-annotations

Using

Extend the BaseAnnotationForm to define what data should be stored with annotations. AnnotationsField stores the annotations data as json, converting to a dict on retrieval.

from django import forms
from django.db import models
from wagtail.wagtailcore.models import Page
from wagtail_annotations.edit_handlers import AnnotatedImagePanel
from wagtail_annotations.fields import AnnotationsField
from wagtail_annotations.forms import BaseAnnotationForm

class AnnotationForm(BaseAnnotationForm):
    title = forms.CharField()
    about = forms.TextField()

class TestPage(Page):
    image = models.ForeignKey('wagtailimages.Image', blank=True, null=True,
                              on_delete=models.SET_NULL, related_name="+")
    annotations = AnnotationsField(blank=True)

    content_panels = Page.content_panels + [
        # First parameter - name of the image field
        # Second parameter - name of the annotation field
        # annotation_form - optional, the form used for annotations if you need to store data for each point
        AnnotatedImagePanel(
            'image', 'annotations',
            annotation_form=AnnotationForm(), heading='Annotated Image'
        )
    ]
<div class='image-container'>
    {% image page.image('width-500') %}

    {% for annotation in page.annotations %}
    <div
        class='annotation'
        style="left: {{ annotation.x * 100 }}%; top: {{ annotation.y * 100 }}%;"
    >
        <h3>{{ annotation.fields.title }}</h3>
        <p>{{ annotation.fields.about }}</p>
    </div>
    {% endfor %}
</div>
.image-container {
    position: relative;
}

.image-container > img {
    width: 100%;
    height: auto;
}

.annotation {
    position: absolute;
}

Developing

You can use the included test app to develop:

> npm install && npm run build
> pip install -e .
> export DJANGO_SETTINGS_MODULE=settings
> django-admin migrate
> django-admin createsuperuser
...
> django-admin runserver

There’s an Dockerfile that includes chromerdriver for the tests, you can build and run it locally if you don’t have chromedriver installed:

> docker build -f Dockerfile.test -t annotation-test .
> docker run annotation-test
> docker run -e WAGTAIL_VERSION=27 -e DJANGO_VERSIONS='30,31' annotation-test

Release files for wagtail-annotations 3.0.0

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

Source distribution (sdist)

Source distribution for wagtail-annotations 3.0.0
File Size Uploaded
wagtail-annotations-3.0.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-annotations 3.0.0
File Interpreter ABI Platform
wagtail_annotations-3.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 37.2 kB

Release files / wagtail-annotations-3.0.0.tar.gz

Download URL wagtail-annotations-3.0.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c67324bce83c33d6b0f118bd9c63f261ae460854d465393a25681feb4212e6b8
BLAKE2b-256 checksum
How to use checksums
fb14f2e74446a2d2570bbd0766d981e90bf8832a6c027593bc1d13444d7a4582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6

Release files / wagtail_annotations-3.0.0-py2.py3-none-any.whl

Download URL wagtail_annotations-3.0.0-py2.py3-none-any.whl
Size 23.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e553262bd0fea27f4cf948988c08417de5dd3a71554bc90e63f4a58153b7c761
BLAKE2b-256 checksum
How to use checksums
e5494ce57b036900f2f6a57a8fae0760b2f91328df013dd15a4a7c3dfb628ff5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.8.6

Release history Release notifications | RSS feed

This release

3.0.0 This release

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