Skip to content

Improve MailingOut's Notification Field: Add Scrollable Wrapper for Long Notifications #217

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

Merged
merged 3 commits into from
May 21, 2025
Merged
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
21 changes: 19 additions & 2 deletions massmail/site/mailingoutadmin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.conf import settings
from django.contrib import messages
from django.template.defaultfilters import linebreaks
from django.template.defaultfilters import linebreaksbr
from django.utils import timezone
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -106,7 +106,24 @@ def content_type_name(instance):
@staticmethod
@admin.display(description=_('notification'))
def notification(instance):
return mark_safe(linebreaks(instance.report))
report = instance.report or ""
lines = report.count('\n') + 1 if report else 0
content = linebreaksbr(report)
style = (
"overflow:auto; max-height:200px;"
"white-space:pre-wrap;"
) if lines >= 20 else "white-space:pre-wrap;"
custom_scrollbar = (
"<style>"
"div.mailingout-scroll::-webkit-scrollbar {width:10px;}"
"div.mailingout-scroll::-webkit-scrollbar-thumb {background:#ccc; border-radius:3px;}"
"</style>"
if lines >= 20 else ""
)
div_class = "mailingout-scroll" if lines >= 20 else ""
return mark_safe(
f'{custom_scrollbar}<div class="{div_class}" style="{style}">{content}</div>'
)

@staticmethod
@admin.display(description=progress_safe_str)
Expand Down