/wagtail-annotations

A wagtail module for creating an image field with annotation metadata

Primary LanguagePythonBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Wagtail Annotatations

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.

image

Requirements

  • Wagtail >= 2.7
  • Django >= 2.0

Installing

Install using pypi and add wagtail-annotations to your INSTALLED_APPS

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.

<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>

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