Skip to content

Commit 0055fdd

Browse files
authored
Merge pull request #217 from MULTidll/main
Improve MailingOut's Notification Field: Add Scrollable Wrapper for Long Notifications
2 parents 3e913b1 + be9cdc8 commit 0055fdd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

massmail/site/mailingoutadmin.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from django.contrib import admin
22
from django.conf import settings
33
from django.contrib import messages
4-
from django.template.defaultfilters import linebreaks
4+
from django.template.defaultfilters import linebreaksbr
55
from django.utils import timezone
66
from django.utils.translation import gettext
77
from django.utils.translation import gettext_lazy as _
@@ -106,7 +106,24 @@ def content_type_name(instance):
106106
@staticmethod
107107
@admin.display(description=_('notification'))
108108
def notification(instance):
109-
return mark_safe(linebreaks(instance.report))
109+
report = instance.report or ""
110+
lines = report.count('\n') + 1 if report else 0
111+
content = linebreaksbr(report)
112+
style = (
113+
"overflow:auto; max-height:200px;"
114+
"white-space:pre-wrap;"
115+
) if lines >= 20 else "white-space:pre-wrap;"
116+
custom_scrollbar = (
117+
"<style>"
118+
"div.mailingout-scroll::-webkit-scrollbar {width:10px;}"
119+
"div.mailingout-scroll::-webkit-scrollbar-thumb {background:#ccc; border-radius:3px;}"
120+
"</style>"
121+
if lines >= 20 else ""
122+
)
123+
div_class = "mailingout-scroll" if lines >= 20 else ""
124+
return mark_safe(
125+
f'{custom_scrollbar}<div class="{div_class}" style="{style}">{content}</div>'
126+
)
110127

111128
@staticmethod
112129
@admin.display(description=progress_safe_str)

0 commit comments

Comments
 (0)