Skip to content

Commit

Permalink
💄 redesign archive mailing detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed May 6, 2024
1 parent 9e8c62a commit 6303402
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
{% extends "base.html" %}
{% block app_body %}
<div class="row justify-content-center mb-5">
<div class="col-md-6">
<h4>Diesen Newsletter abonnieren</h4>
{% include "fds_newsletter/plugins/newsletter_form.html" %}
{% load i18n %}
{% block body %}
<div class="text-bg-body-tertiary pb-5">
<div class="container py-5">
<p>
{% with date|date:"DATE_FORMAT" as date %}
{% blocktrans %}Newsletter from {{ date }}{% endblocktrans %}
{% endwith %}
</p>
<h1>{{ message.subject }}</h1>
{% if not has_newsletter %}
<div class="row">
<div class="col col-md-8">
<div class="border-yellow text-bg-body shadow-md-yellow p-3 mt-3">
<p class="lead mt-0">{% trans "Don't miss out on any future updates by subscribing to this newsletter!" %}</p>
{% include "fds_newsletter/plugins/newsletter_form.html" %}
</div>
</div>
</div>
{% endif %}
</div>
</div>
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Newsletter vom {{ date|date:"DATE_FORMAT" }}</div>
<div class="card-body">
<h3 class="card-title">{{ message.subject }}</h3>
<div class="card-text">{{ content }}</div>
</div>
<div class="container pb-5">
<div class="row">
<div class="col col-md-10 col-lg-8">
<div class="border-gray shadow-md-gray mt-n3 mt-n6 p-3 text-bg-body">{{ content }}</div>
{% if not has_newsletter %}
<div class="border-yellow shadow-md-yellow p-3 mt-5">
<p class="lead mt-0">{% trans "Don't miss out on any future updates by subscribing to this newsletter!" %}</p>
{% include "fds_newsletter/plugins/newsletter_form.html" %}
</div>
{% endif %}
</div>
</div>
</div>
<div class="row justify-content-center mt-5">
<div class="col-md-6">{% include "fds_newsletter/plugins/newsletter_form.html" %}</div>
</div>
{% endblock %}
{% endblock body %}
3 changes: 2 additions & 1 deletion fragdenstaat_de/fds_mailing/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.urls import path

from .models import Mailing
from .views import MailingArchiveDetailView

urlpatterns = [
path(
"<slug:newsletter_slug>/archiv/<int:year>/<int:month>/<int:day>/<int:pk>/",
MailingArchiveDetailView.as_view(),
MailingArchiveDetailView.as_view(model=Mailing),
name="newsletter_archive_detail",
),
]
24 changes: 23 additions & 1 deletion fragdenstaat_de/fds_mailing/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from django.shortcuts import get_object_or_404
from django.utils.formats import date_format
from django.utils.translation import gettext_lazy as _
from django.views.generic import DateDetailView

from cms.models.pagemodel import Page
from cms.utils.i18n import get_current_language
from fragdenstaat_de.fds_newsletter.models import Newsletter
from fragdenstaat_de.fds_newsletter.utils import has_newsletter

from .models import Mailing

Expand Down Expand Up @@ -46,15 +51,32 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

message = self.object.email_template

context.update(
{
"message": message,
"content": message.get_body_html(
template="fds_mailing/render_browser.html"
),
"date": self.object.sending_date,
"has_newsletter": has_newsletter(
self.request.user, self.object.newsletter
),
}
)

return context

def get_breadcrumbs(self, context):
try:
newsletter_url = Page.objects.get(reverse_id="newsletter").get_absolute_url(
language=get_current_language()
)
return [
(_("Newsletter"), newsletter_url),
(
_("Mailing from %s")
% date_format(self.object.sending_date, "DATE_FORMAT")
),
]
except Exception:
return None
19 changes: 4 additions & 15 deletions fragdenstaat_de/fds_newsletter/templatetags/newsletter_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from django.conf import settings

from ..forms import NewsletterForm, NewslettersUserForm
from ..models import Newsletter, Subscriber
from ..models import Newsletter
from ..utils import has_newsletter

register = template.Library()

Expand All @@ -23,18 +24,6 @@ def _get_newsletter(newsletter_slug=None):
return None


def _has_newsletter(context, newsletter):
user = context["request"].user
if user.is_authenticated:
try:
instance = Subscriber.objects.get(newsletter=newsletter, user=user)
if instance.subscribed:
return True
except Subscriber.DoesNotExist:
pass
return False


def get_newsletter_context(context, next=None, newsletter=None, fallback=True):
ctx = {"next": next, "fallback": fallback, "has_newsletter": False}

Expand All @@ -44,7 +33,7 @@ def get_newsletter_context(context, next=None, newsletter=None, fallback=True):

ctx["newsletter"] = newsletter
ctx["form"] = NewsletterForm(request=context["request"])
ctx["has_newsletter"] = _has_newsletter(context, newsletter)
ctx["has_newsletter"] = has_newsletter(context["request"].user, newsletter)
user = context["request"].user
ctx["user"] = user

Expand All @@ -64,4 +53,4 @@ def newsletter_subscribe(context, next=None, newsletter_slug=None, fallback=True
@register.simple_tag(takes_context=True)
def newsletter_is_subscribed(context):
newsletter = _get_newsletter()
return _has_newsletter(context, newsletter)
return has_newsletter(context["request"].user, newsletter)
15 changes: 8 additions & 7 deletions fragdenstaat_de/fds_newsletter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ def subscribe_user(newsletter, user, reference="", keyword="") -> SubscriptionRe
return (SubscriptionResult.SUBSCRIBED, subscriber)


def has_newsletter(user, newsletter_slug=None) -> bool:
def has_newsletter(user, newsletter=None, newsletter_slug=None) -> bool:
if not user.is_authenticated:
return None
try:
newsletter = Newsletter.objects.get(
slug=newsletter_slug or settings.DEFAULT_NEWSLETTER
)
except Newsletter.DoesNotExist:
return None
if not newsletter:
try:
newsletter = Newsletter.objects.get(
slug=newsletter_slug or settings.DEFAULT_NEWSLETTER
)
except Newsletter.DoesNotExist:
return None

return Subscriber.objects.filter(
newsletter=newsletter, user=user, subscribed__isnull=False
Expand Down
17 changes: 13 additions & 4 deletions frontend/styles/cms_utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,28 @@
box-shadow: 7px 7px 0 var(--shadow-color);
}

@include media-breakpoint-up(md) {
@include media-breakpoint-down(md) {
[class*=' md\:shadow'],
[class^='md\:shadow'] {
--shadow-color: var(--shadow-blue);
box-shadow: 7px 7px 0 var(--shadow-color);
[class^='md\:shadow'],
[class*=' shadow-md'],
[class^='shadow-md'] {
box-shadow: none;
}
}

.shadow-blue,
.shadow-md-blue,
.md\:shadow-blue {
--shadow-color: var(--shadow-blue);
}

.shadow-gray,
.shadow-md-gray,
.md\:shadow-gray {
--shadow-color: var(--shadow-gray);
}
.shadow-yellow,
.shadow-md-yellow,
.md\:shadow-yellow {
--shadow-color: var(--shadow-yellow);
}
Expand Down

0 comments on commit 6303402

Please sign in to comment.