跳转到主要内容

一个用于创建带有注释元数据的图片字段的Wagtail模块

项目描述

允许用户将自定义注释数据与Wagtail图片结合。通过在图像上点击点来输入注释,然后注释数据将与相对的x,y坐标和可选的额外表单数据一起存储。

https://giant.gfycat.com/SpeedyHospitableHornet.gif

要求

  • Wagtail >= 2.7

  • Django >= 2.0

安装

使用pypi安装

pip install wagtailannotatedimage

使用

扩展BaseAnnotationForm以定义应该与注释一起存储哪些数据。AnnotationsField将注释数据存储为json,在检索时转换为字典。

from django import forms
from django.db import models
from wagtail.wagtailcore.models import Page
from wagtailannotatedimage.edit_handlers import AnnotatedImagePanel
from wagtailannotatedimage.fields import AnnotationsField
from wagtailannotatedimage.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;
}

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

wagtailannotatedimage-2.7.0.tar.gz (10.8 kB 查看哈希值)

上传时间:

构建分布

wagtailannotatedimage-2.7.0-py2.py3-none-any.whl (16.0 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面