Skip to content

Commit

Permalink
✨ redesign newsletter archive, allow limits + filtering in plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed May 6, 2024
1 parent 18a81c6 commit 9e8c62a
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 20 deletions.
21 changes: 11 additions & 10 deletions fragdenstaat_de/fds_mailing/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from fragdenstaat_de.fds_cms.utils import get_plugin_children
from fragdenstaat_de.fds_newsletter.models import Newsletter

from .models import (
EmailActionCMSPlugin,
EmailHeaderCMSPlugin,
EmailSectionCMSPlugin,
EmailStoryCMSPlugin,
Mailing,
NewsletterArchiveCMSPlugin,
)
from .utils import render_plugin_text

Expand Down Expand Up @@ -174,6 +174,7 @@ def render_text(self, context, instance):

@plugin_pool.register_plugin
class NewsletterArchivePlugin(CMSPluginBase):
model = NewsletterArchiveCMSPlugin
module = _("Newsletter")
name = _("Newsletter Archive")
cache = True
Expand All @@ -182,14 +183,14 @@ class NewsletterArchivePlugin(CMSPluginBase):

def render(self, context, instance, placeholder):
context = super().render(context, instance, placeholder)
context["newsletter"] = None
try:
context["newsletter"] = Newsletter.objects.get(
slug=settings.DEFAULT_NEWSLETTER
)
except Newsletter.DoesNotExist:
return context
context["latest"] = Mailing.published.filter(
newsletter=context["newsletter"]

latest_mailings = Mailing.published.filter(
newsletter=instance.newsletter
).order_by("-sending_date")

if instance.number_of_mailings != 0:
latest_mailings = latest_mailings[: instance.number_of_mailings]

context["latest"] = latest_mailings

return context
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Generated by Django 4.2.4 on 2024-04-25 11:19

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cms", "0035_auto_20230822_2208"),
("fds_newsletter", "0003_newsletter_description"),
("fds_mailing", "0001_squashed_0013_auto_20210526_2232"),
]

operations = [
migrations.RemoveField(
model_name="emailtemplate",
name="email_body",
),
migrations.AlterField(
model_name="emailactioncmsplugin",
name="cmsplugin_ptr",
field=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",
),
),
migrations.AlterField(
model_name="emailheadercmsplugin",
name="cmsplugin_ptr",
field=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",
),
),
migrations.AlterField(
model_name="emailsectioncmsplugin",
name="cmsplugin_ptr",
field=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",
),
),
migrations.AlterField(
model_name="emailstorycmsplugin",
name="cmsplugin_ptr",
field=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",
),
),
migrations.CreateModel(
name="NewsletterArchiveCMSPlugin",
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",
),
),
(
"number_of_mailings",
models.PositiveIntegerField(
default=6,
help_text="0 means all the mailings. Should be devisible by 3.",
verbose_name="number of mailing",
),
),
(
"newsletter",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="fds_newsletter.newsletter",
),
),
],
bases=("cms.cmsplugin",),
),
]
9 changes: 9 additions & 0 deletions fragdenstaat_de/fds_mailing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,12 @@ def send_message(self, mailing_context=None, email_template=None):

except Exception as e:
logger.error("Mailing message %s failed with error: %s" % (self, e))


class NewsletterArchiveCMSPlugin(CMSPlugin):
newsletter = models.ForeignKey(Newsletter, on_delete=models.CASCADE)
number_of_mailings = models.PositiveIntegerField(
_("number of mailing"),
default=6,
help_text=_("0 means all the mailings. Should be devisible by 3."),
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<div class="list-group mt-3 mb-3">
{% load i18n %}
<ul class="row list-unstyled row-gap-2">
{% for mailing in latest %}
<a class="list-group-item list-group-item-action"
href="{% url 'newsletter_archive_detail' newsletter_slug=newsletter.slug year=mailing.sending_date.year month=mailing.sending_date.month day=mailing.sending_date.day pk=mailing.pk %}">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ mailing.email_template.subject }}</h5>
<small class="text-body-secondary">{{ mailing.sending_date|date:"DATE_FORMAT" }}</small>
</div>
</a>
<li class="col-12 col-md-6 col-lg-4 px-1 d-flex">
<article class="box-card position-relative border-gray p-3 text-bg-body">
<h3 class="h5">{{ mailing.email_template.subject }}</h3>
<p class="text-body-secondary">{{ mailing.sending_date|date:"DATE_FORMAT" }}</p>
<a class="stretched-link mt-auto"
href="{% url 'newsletter_archive_detail' newsletter_slug=mailing.newsletter.slug year=mailing.sending_date.year month=mailing.sending_date.month day=mailing.sending_date.day pk=mailing.pk %}">→ {% trans "Read more" %}</a>
</article>
</li>
{% endfor %}
</div>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.4 on 2024-04-25 11:19

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("cms", "0035_auto_20230822_2208"),
("fds_newsletter", "0003_newsletter_description"),
]

operations = [
migrations.AlterField(
model_name="newslettercmsplugin",
name="cmsplugin_ptr",
field=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",
),
),
migrations.AlterField(
model_name="subscribertag",
name="slug",
field=models.SlugField(
allow_unicode=True, max_length=100, unique=True, verbose_name="slug"
),
),
]
3 changes: 2 additions & 1 deletion frontend/styles/cards.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
}
}

a > .box-card {
a > .box-card,
.box-card:has(a.stretched-link) {
box-shadow: 0 0 0 var(--shadow-color, var(--shadow-gray));
transform: translate(0, 0);
transition: box-shadow 0.15s ease-in-out, transform 0.15s ease-in-out;
Expand Down

0 comments on commit 9e8c62a

Please sign in to comment.