BaseRichMailTextPlaceholder
pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
Base for placeholders that emit different plain-text and HTML variants. Subclasses override _render_plain_value() and _render_html_value(); render() wraps the pair in an EmailAlternativeString for the formatter to dispatch on.
Inherited attributes 1
account_requiredFalseBaseMailTextPlaceholderProperties 4
Defined here
explanationsource
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
@property
def explanation(self):
return self._explanation or ""
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
@property
def explanation(self):
return ""
identifiersource
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
@property
def identifier(self):
return self._identifier
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
Unique key the placeholder is referenced by in templates.
@property
def identifier(self):
"""Unique key the placeholder is referenced by in templates."""
raise NotImplementedError
is_visiblesource
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
@property
def is_visible(self):
return self._is_visible
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
Set False to hide from the placeholder picker (e.g. aliases).
@property
def is_visible(self):
"""Set ``False`` to hide from the placeholder picker (e.g. aliases)."""
return True
required_contextsource
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
@property
def required_context(self):
return self._args
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
Keys this placeholder needs in the render context.
@property
def required_context(self):
"""Keys this placeholder needs in the render context."""
return ["event"]
Methods 6
Defined here
render(context)sourceReturn the rendered value given a context dict.
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
def render(self, context):
kwargs = {key: context[key] for key in self._args}
return EmailAlternativeString(
self.render_plain(**kwargs), self.render_html(**kwargs)
)
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
Return the rendered value given a context dict.
def render(self, context):
"""Return the rendered value given a context dict."""
raise NotImplementedError
render_html(**kwargs)source
def render_html(self, **kwargs):
return self._render_html_value(self._func(**kwargs))
render_plain(**kwargs)source
def render_plain(self, **kwargs):
return self._render_plain_value(self._func(**kwargs))
render_sample(event)sourceReturn a preview value that depends only on event.
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
def render_sample(self, event):
if callable(self._sample):
return self._sample(event)
return self._sample
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
Return a preview value that depends only on event.
def render_sample(self, event):
"""Return a preview value that depends only on ``event``."""
raise NotImplementedError
render_sample_for_preview(event)sourceShape the sample like render's output so the preview pipeline matches delivery.
on pretalx.mail.domain.placeholders.BaseRichMailTextPlaceholder source
def render_sample_for_preview(self, event):
# Coerce to ``str`` so lazy i18n samples match the plain-string
# shape ``self._func`` returns in production and satisfy
# ``EmailAlternativeString``'s type guard.
sample = str(self.render_sample(event) or "")
return EmailAlternativeString(
self._render_plain_value(sample), self._render_html_value(sample)
)
on pretalx.mail.domain.placeholders.BaseMailTextPlaceholder source
Shape the sample like render()'s output so the preview pipeline matches delivery.
def render_sample_for_preview(self, event):
"""Shape the sample like :meth:`render`'s output so the preview
pipeline matches delivery."""
return self.render_sample(event)
__init__(identifier, args, sample, explanation=None, is_visible=True)sourceInitialize self.
See help(type(self)) for accurate signature.
def __init__(self, identifier, args, sample, explanation=None, is_visible=True):
self._identifier = identifier
self._args = args
self._sample = sample
self._explanation = explanation
self._is_visible = is_visible