wagtail-snippet-image
Package for creating a snippet images for sharing in social networks and etc. Based on django-snippet-image and snippet-image. But for storage of images used Wagtail Images.
Installation
pip3 install wagtail-snippet-image
How use it
from django.db.models import (
CharField,
ForeignKey,
SET_NULL,
CASCADE,
)
from wagtail_snippet_image import SnippetImageField
from wagtail.core.models import Page
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.images.edit_handlers import ImageChooserPanel
from modelcluster.fields import ParentalKey
from modelcluster.contrib.taggit import ClusterTaggableManager
from taggit.models import TaggedItemBase
class PageTag(TaggedItemBase):
content_object = ParentalKey(
'home.HomePage',
on_delete=CASCADE,
related_name='tagged_items',
)
class Statuses:
DRAFT = 'draft'
PUBLISH = 'publish'
CHOICES = (
(DRAFT, 'Draft'),
(PUBLISH, 'Publish'),
)
class HomePage(Page):
background = ForeignKey(
'wagtailimages.Image',
verbose_name='Изображение для обложки',
related_name='cover_images',
on_delete=SET_NULL,
blank=True,
null=True,
)
snippet_image_field = SnippetImageField(
verbose_name='Example snippet image field',
null=True,
)
status = CharField(
max_length=20,
choices=Statuses.CHOICES,
default=Statuses.DRAFT,
)
tags = ClusterTaggableManager(through=PageTag, blank=True)
content_panels = Page.content_panels + [
ImageChooserPanel('background'),
ImageChooserPanel('snippet_image_field'),
FieldPanel('status'),
FieldPanel('tags'),
]
def get_snippet_image_background(self, snippet_type):
return self.background and self.background.file and self.background.file.path \
if snippet_type == 'default' else None
def get_snippet_image_center(self, snippet_type):
return (self.background.focal_point_x, self.background.focal_point_y) \
if snippet_type == 'default' and self.background \
and self.background.focal_point_x and self.background.focal_point_y \
else None
def get_snippet_image_text(self, snippet_type):
return self.title if snippet_type == 'default' else None
def snippet_image_should_be_created(self):
return self.status == Statuses.PUBLISH
# Wagtail custom methods for create wagtail images for sharing snippet image
def get_snippet_image_title(self, snippet_type):
return self.title if snippet_type == 'default' else None
def get_snippet_image_tags(self, snippet_type):
return self.tags.names() if snippet_type == 'default' else None
And use it in template:
<meta property="og:image" content="{{ image(page.snippet_image_field, 'original') }}" />
Read more in home.
Metadata
Release files for wagtail-snippet-image 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| wagtail-snippet-image-0.1.4.tar.gz | 4.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wagtail_snippet_image-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.0 kB
Release files / wagtail-snippet-image-0.1.4.tar.gz
| Download URL | wagtail-snippet-image-0.1.4.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1f9b9f32094fd910b7e49ee81ac817f0baf46a722ad140fd87dc8ccfb144d72
|
|
BLAKE2b-256 checksum How to use checksums |
384cc721894b623c70cfc04440df7e63a89d7a09274ba5a167c1d0f4c0d10b48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.15 CPython/3.7.3 Linux/5.0.0-15-generic
|
Release files / wagtail_snippet_image-0.1.4-py3-none-any.whl
| Download URL | wagtail_snippet_image-0.1.4-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
738115c73528bfbddb83150b601d6efb7df0851baa7b3cc7296c4e66d802bcdd
|
|
BLAKE2b-256 checksum How to use checksums |
3060468e85b16335db98195994418fed3f3d3c76e79e1c73f3533a1adc9f0981
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/0.12.15 CPython/3.7.3 Linux/5.0.0-15-generic
|
Security for wagtail-snippet-image 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.