Creating a snippet images on Wagtail for sharing for social media.
Project description
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.
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
Built Distribution
File details
Details for the file wagtail-snippet-image-0.1.4.tar.gz
.
File metadata
- Download URL: wagtail-snippet-image-0.1.4.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.0.0-15-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1f9b9f32094fd910b7e49ee81ac817f0baf46a722ad140fd87dc8ccfb144d72 |
|
MD5 | 1efc2fee6760a7697e38e3977cccfd7f |
|
BLAKE2b-256 | 384cc721894b623c70cfc04440df7e63a89d7a09274ba5a167c1d0f4c0d10b48 |
File details
Details for the file wagtail_snippet_image-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: wagtail_snippet_image-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/0.12.15 CPython/3.7.3 Linux/5.0.0-15-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 738115c73528bfbddb83150b601d6efb7df0851baa7b3cc7296c4e66d802bcdd |
|
MD5 | d6894e110cf71a43a07fa594460dda33 |
|
BLAKE2b-256 | 3060468e85b16335db98195994418fed3f3d3c76e79e1c73f3533a1adc9f0981 |