Add support for sending out news as HTML email
authorMagnus Hagander <magnus@hagander.net>
Thu, 10 Sep 2020 12:52:41 +0000 (14:52 +0200)
committerMagnus Hagander <magnus@hagander.net>
Thu, 10 Sep 2020 12:52:41 +0000 (14:52 +0200)
commite4453cdda9d811c17974a71ec8b3644ba1c8c38d
treefa46db8ac3d1ad371401787e4c5ed329fd44db1d
parentf2fc72f93a1a1603863d709ebc081b505066b756
Add support for sending out news as HTML email

When a news article is approved, it gets delivered as an email to the
pgsql-announce mailinglist. It will render the markdown of the news
article into a HTML part of the email, and include the markdown raw as
the text part (for those unable or unwilling to read html mail).

For each organisation, a mail template can be specified. Initially only
two templates are supported, one "default" and one "pgproject" which is
for official project news. The intention is *not* to provide generic
templates, but we may want to extend this to certain related projects in
the future *maybe* (such as regional NPOs).

These templates are stored in templates/news/mail/*.html, and for each
template *all* images found in templates/news/mail/img.<template>/ will
be attached to the email. "Conditional image inclusion" currently not
supported.

To do CSS inlining on top of the markdown output, module pynliner is now
required (available in the python3-pynliner package on Debian).

A testing script is added as news_send_email.py in order to easier test
out templates. This is *not* intended for production sending, so it will
for example send unmoderated news. By sending, it adds it to the
outgoing mailqueue in the system, so unless the cronjob is set up to
send, nothing will happen until that is run manually.

Support is included for tagged delivery using pglister, by directly
mapping NewsTags to pglister tags.

While at it, update the moderation preview forms to preview news items
using the HTML template for the email (while leaving other types of
items previewing without a particular stylesheet).
21 files changed:
media/css/admin_pgweb.css
media/css/main.css
media/js/admin_pgweb.js
pgweb/core/forms.py
pgweb/core/migrations/0003_mailtemplate.py [new file with mode: 0644]
pgweb/core/models.py
pgweb/core/templatetags/pgfilters.py
pgweb/core/views.py
pgweb/news/management/commands/news_send_email.py [new file with mode: 0644]
pgweb/news/models.py
pgweb/news/util.py [new file with mode: 0644]
pgweb/settings.py
pgweb/util/moderation.py
requirements.txt
templates/account/submit_preview.html
templates/core/admin_moderation_form.html
templates/news/mail/base.html [new file with mode: 0644]
templates/news/mail/default.html [new file with mode: 0644]
templates/news/mail/img.pgproject/slonik.png [new file with mode: 0644]
templates/news/mail/inline.css [new file with mode: 0644]
templates/news/mail/pgproject.html [new file with mode: 0644]