def og_image(post): if not settings.OG_IMAGE_GENERATOR_URL: return any_image(post) params = urlencode({ **settings.OG_IMAGE_GENERATOR_DEFAULTS, "title": f"{post.prefix} {post.title}" if post.prefix else post.title, "author": post.author.slug, "ava": post.author.get_avatar(), "bg": extract_any_image(post) or "#FFFFFF" }) return f"{settings.OG_IMAGE_GENERATOR_URL}?{params}"
def announce_post(request, post_slug): post = get_object_or_404(Post, slug=post_slug) initial = { "text": render_html_message("channel_post_announce.html", post=post), "image": extract_any_image(post), } if request.method == "POST": form = PostAnnounceForm(request.POST, initial=initial) if form.is_valid(): announce_in_club_channel(post=post, announce_text=form.cleaned_data["text"], image=form.cleaned_data["image"] if form.cleaned_data["with_image"] else None) return render(request, "message.html", {"title": "Запощено ✅"}) else: form = PostAnnounceForm(initial=initial) return render(request, "admin/simple_form.html", { "title": "Анонсировать пост на канале", "post": post, "form": form })
def any_image(post): return extract_any_image(post) or settings.OG_IMAGE_DEFAULT
def any_image(post, default="/static/images/share.png"): return extract_any_image(post) or default