Skip to content

Commit 2641c23

Browse files
committed
✨ add PagePreview cms plugin
1 parent 27045e1 commit 2641c23

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

fragdenstaat_de/fds_cms/cms_plugins.py

+25
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.exceptions import ObjectDoesNotExist
55
from django.utils.translation import gettext_lazy as _
66

7+
from cms.models import Page
78
from cms.plugin_base import CMSPluginBase
89
from cms.plugin_pool import plugin_pool
910
from datashow.models import Dataset
@@ -34,6 +35,7 @@
3435
ModalCMSPlugin,
3536
OneClickFoiRequestCMSPlugin,
3637
PageAnnotationCMSPlugin,
38+
PagePreviewCMSPlugin,
3739
PretixEmbedCMSPlugin,
3840
PrimaryLinkCMSPlugin,
3941
RevealMoreCMSPlugin,
@@ -763,3 +765,26 @@ def render(self, context, instance, placeholder):
763765
column.sortable = False
764766
context["columns"] = columns
765767
return super().render(context, instance, placeholder)
768+
769+
770+
@plugin_pool.register_plugin
771+
class PagePreviewPlugin(CMSPluginBase):
772+
model = PagePreviewCMSPlugin
773+
module = _("Elements")
774+
name = _("Page Preview")
775+
render_template = "fds_cms/page_preview.html"
776+
777+
def render(self, context, instance, placeholder):
778+
page = instance.page
779+
context["page"] = page
780+
781+
try:
782+
context["image"] = page.fdspageextension.image
783+
except Page.fdspageextension.RelatedObjectDoesNotExist:
784+
context["image"] = None
785+
print("NO IMAGE")
786+
787+
context["title"] = page.get_title()
788+
context["description"] = page.get_meta_description()
789+
790+
return super().render(context, instance, placeholder)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 4.2.16 on 2025-03-10 13:42
2+
3+
import cms.models.fields
4+
from django.conf import settings
5+
from django.db import migrations, models
6+
import django.db.models.deletion
7+
import filer.fields.image
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
dependencies = [
13+
("cms", "0035_auto_20230822_2208_squashed_0036_auto_20240311_1028"),
14+
migrations.swappable_dependency(settings.FILER_IMAGE_MODEL),
15+
("fds_cms", "0071_datashowtablecmsplugin_datashowdatasettheme"),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name="PagePreviewCMSPlugin",
21+
fields=[
22+
(
23+
"cmsplugin_ptr",
24+
models.OneToOneField(
25+
auto_created=True,
26+
on_delete=django.db.models.deletion.CASCADE,
27+
parent_link=True,
28+
primary_key=True,
29+
related_name="%(app_label)s_%(class)s",
30+
serialize=False,
31+
to="cms.cmsplugin",
32+
),
33+
),
34+
(
35+
"page",
36+
cms.models.fields.PageField(
37+
on_delete=django.db.models.deletion.CASCADE, to="cms.page"
38+
),
39+
),
40+
],
41+
bases=("cms.cmsplugin",),
42+
),
43+
]

fragdenstaat_de/fds_cms/models.py

+7
Original file line numberDiff line numberDiff line change
@@ -717,3 +717,10 @@ class DatashowTableCMSPlugin(CMSPlugin):
717717

718718
def __str__(self):
719719
return self.table.label
720+
721+
722+
class PagePreviewCMSPlugin(CMSPlugin):
723+
page = PageField()
724+
725+
def __str__(self):
726+
return str(self.page)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<article class="blog-article-item w-100 mx-auto">
2+
{% if image %}
3+
<a href="{{ page.get_absolute_url }}">
4+
{% include "fds_blog/includes/blog_picture.html" with picture=image columns="col-12 col-md-10 col-lg-8" %}
5+
</a>
6+
{% endif %}
7+
<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 %}">
8+
<div>
9+
<h3 class="h4 mt-0 mb-2">
10+
<a href="{{ page.get_absolute_url }}">{{ title }}</a>
11+
</h3>
12+
</div>
13+
<div class="tight-margin">
14+
<p>{{ description }}</p>
15+
</div>
16+
</div>
17+
</article>

0 commit comments

Comments
 (0)