mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-06 09:57:57 +00:00

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.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Script to send out a news email
|
|
# THIS IS FOR TESTING ONLY
|
|
# Normal emails are triggered automatically on moderation!
|
|
# Note that emails are queued up in the MailQueue model, to be sent asynchronously
|
|
# by the sender (or viewed locally).
|
|
#
|
|
#
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from pgweb.news.models import NewsArticle
|
|
from pgweb.news.util import send_news_email
|
|
|
|
|
|
def yesno(prompt):
|
|
while True:
|
|
r = input(prompt)
|
|
if r.lower().startswith('y'):
|
|
return True
|
|
elif r.lower().startswith('n'):
|
|
return False
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Test news email'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('id', type=int, help='id of news article to post')
|
|
|
|
def handle(self, *args, **options):
|
|
try:
|
|
news = NewsArticle.objects.get(pk=options['id'])
|
|
except NewsArticle.DoesNotExist:
|
|
raise CommandError("News article not found.")
|
|
|
|
print("Title: {}".format(news.title))
|
|
print("Moderation state: {}".format(news.modstate_string))
|
|
if not yesno('Proceed to send mail for this article?'):
|
|
raise CommandError("OK, aborting")
|
|
|
|
send_news_email(news)
|
|
print("Sent.")
|