Add a mail-template system (registry + DB-backed templates + API + sandboxed Jinja2 rendering) #5

Closed
opened 2026-10-25 21:01:23 +00:00 by Gilles · 0 comments
Owner

Generalizes the EmailTemplate pattern currently hardcoded in drh's apps.events into a reusable poulpinou feature:

  • poulpinou.registry: static, code-side declaration of mail types (key, label, variables, default subject/body), registered by host apps via AppConfig.ready(); plus global variables merged into every render.
  • MailTemplate / MailTemplateImage / MailTemplateAttachment models: the actual, DB-editable subject/body/attachments per key.
  • poulpinou.rendering: sandboxed Jinja2 (ImmutableSandboxedEnvironment, no Loader, soft-undefined so an unknown/removed variable renders blank instead of raising, autoescape for HTML bodies but not subjects) -- supports {% if %}/{% for %}, same {{ var }} syntax as drh's current templates so a later read-migration from drh doesn't need template rewrites.
  • poulpinou.sending.send_mail_type(key, recipient, context): renders + attaches + sends.
  • Optional [api] extra (djangorestframework): list/detail/patch/reset endpoints + image/attachment upload, permission classes configurable via settings (POULPINOU_MAIL_TEMPLATE_PERMISSION_CLASSES).

Migrating drh itself onto this (vs. its own apps.events.EmailTemplate) is a separate, later PR in ws-backend.

Generalizes the EmailTemplate pattern currently hardcoded in drh's apps.events into a reusable poulpinou feature: - poulpinou.registry: static, code-side declaration of mail types (key, label, variables, default subject/body), registered by host apps via AppConfig.ready(); plus global variables merged into every render. - MailTemplate / MailTemplateImage / MailTemplateAttachment models: the actual, DB-editable subject/body/attachments per key. - poulpinou.rendering: sandboxed Jinja2 (ImmutableSandboxedEnvironment, no Loader, soft-undefined so an unknown/removed variable renders blank instead of raising, autoescape for HTML bodies but not subjects) -- supports {% if %}/{% for %}, same {{ var }} syntax as drh's current templates so a later read-migration from drh doesn't need template rewrites. - poulpinou.sending.send_mail_type(key, recipient, context): renders + attaches + sends. - Optional [api] extra (djangorestframework): list/detail/patch/reset endpoints + image/attachment upload, permission classes configurable via settings (POULPINOU_MAIL_TEMPLATE_PERMISSION_CLASSES). Migrating drh itself onto this (vs. its own apps.events.EmailTemplate) is a separate, later PR in ws-backend.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Gilles/poulpinou-django#5
No description provided.