Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ add PagePreview cms plugin #664

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions fragdenstaat_de/fds_cms/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.utils.translation import gettext_lazy as _

from cms.models import Page
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from datashow.models import Dataset
Expand Down Expand Up @@ -34,6 +35,7 @@
ModalCMSPlugin,
OneClickFoiRequestCMSPlugin,
PageAnnotationCMSPlugin,
PagePreviewCMSPlugin,
PretixEmbedCMSPlugin,
PrimaryLinkCMSPlugin,
RevealMoreCMSPlugin,
Expand Down Expand Up @@ -763,3 +765,26 @@ def render(self, context, instance, placeholder):
column.sortable = False
context["columns"] = columns
return super().render(context, instance, placeholder)


@plugin_pool.register_plugin
class PagePreviewPlugin(CMSPluginBase):
model = PagePreviewCMSPlugin
module = _("Elements")
name = _("Page Preview")
render_template = "fds_cms/page_preview.html"

def render(self, context, instance, placeholder):
page = instance.page
context["page"] = page

try:
context["image"] = page.fdspageextension.image
except Page.fdspageextension.RelatedObjectDoesNotExist:
context["image"] = None
print("NO IMAGE")

context["title"] = page.get_title()
context["description"] = page.get_meta_description()

return super().render(context, instance, placeholder)
43 changes: 43 additions & 0 deletions fragdenstaat_de/fds_cms/migrations/0072_pagepreviewcmsplugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2.16 on 2025-03-10 13:42

import cms.models.fields
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import filer.fields.image


class Migration(migrations.Migration):

dependencies = [
("cms", "0035_auto_20230822_2208_squashed_0036_auto_20240311_1028"),
migrations.swappable_dependency(settings.FILER_IMAGE_MODEL),
("fds_cms", "0071_datashowtablecmsplugin_datashowdatasettheme"),
]

operations = [
migrations.CreateModel(
name="PagePreviewCMSPlugin",
fields=[
(
"cmsplugin_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
related_name="%(app_label)s_%(class)s",
serialize=False,
to="cms.cmsplugin",
),
),
(
"page",
cms.models.fields.PageField(
on_delete=django.db.models.deletion.CASCADE, to="cms.page"
),
),
],
bases=("cms.cmsplugin",),
),
]
7 changes: 7 additions & 0 deletions fragdenstaat_de/fds_cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,10 @@ class DatashowTableCMSPlugin(CMSPlugin):

def __str__(self):
return self.table.label


class PagePreviewCMSPlugin(CMSPlugin):
page = PageField()

def __str__(self):
return str(self.page)
17 changes: 17 additions & 0 deletions fragdenstaat_de/fds_cms/templates/fds_cms/page_preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<article class="blog-article-item w-100 mx-auto">
{% if image %}
<a href="{{ page.get_absolute_url }}">
{% include "fds_blog/includes/blog_picture.html" with picture=image columns="col-12 col-md-10 col-lg-8" %}
</a>
{% endif %}
<div class="text-bg-body border-gray md:shadow-gray z-index-20 position-relative mx-1 mx-md-3 p-3 p-md-4 {% if image %}mt-n5{% endif %}">
<div>
<h3 class="h4 mt-0 mb-2">
<a href="{{ page.get_absolute_url }}">{{ title }}</a>
</h3>
</div>
<div class="tight-margin">
<p>{{ description }}</p>
</div>
</div>
</article>
Loading