Skip to content

Commit

Permalink
Allow adding some custom context to the rendered spark mails preview
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Nov 7, 2018
1 parent 4c6526f commit c1ee671
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion spark/spark_mails/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from django.conf import settings
from django.contrib import admin
from django.utils.html import format_html
from django.utils.module_loading import import_string
from django.utils.translation import ugettext_lazy as _

from django.utils.translation import ugettext_lazy as _
from .models import Mail


def spark_mails_context(instance):
return {}


if getattr(settings, "SPARK_MAILS_CONTEXT", None):
spark_mails_context = import_string(settings.SPARK_MAILS_CONTEXT)


@admin.register(Mail)
class MailAdmin(admin.ModelAdmin):
list_display = ["event_group"]
Expand All @@ -18,7 +29,7 @@ def rendered(self, instance):
return format_html(
'<div style="white-space:pre-wrap; max-width:40rem">'
"<code>{}\n\n{}</code></div>",
*instance.render({}),
*instance.render(spark_mails_context(instance)),
)
except Exception:
return format_html('<div style="color:red">INVALID</div>')
Expand Down

0 comments on commit c1ee671

Please sign in to comment.