diff options
author | Giancarlo Razzolini <grazzolini@archlinux.org> | 2017-03-20 17:11:02 -0300 |
---|---|---|
committer | Giancarlo Razzolini <grazzolini@archlinux.org> | 2017-03-20 17:11:02 -0300 |
commit | fba04673d91707ac33ba24ff3d904ee8764d8745 (patch) | |
tree | 496134793cd71a4acec31582c0653f873eab898a /news | |
parent | c68ae29cc4c16bfff05625c1df106a8a650ca94f (diff) | |
download | archweb-fba04673d91707ac33ba24ff3d904ee8764d8745.tar.gz archweb-fba04673d91707ac33ba24ff3d904ee8764d8745.zip |
news/views: Send e-mail to arch-announce on news creation
When send_announce is True, we send an e-mail to the arch-announce
mail list, containing the content of the news and the URL (slug to it).
Diffstat (limited to 'news')
-rw-r--r-- | news/views.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/news/views.py b/news/views.py index 274ba75d..b5bb4801 100644 --- a/news/views.py +++ b/news/views.py @@ -1,6 +1,8 @@ from django import forms +from django.core.mail import send_mail from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect +from django.template import Context, loader from django.views.decorators.http import require_POST from django.views.generic import (DetailView, ListView, CreateView, UpdateView, DeleteView) @@ -37,6 +39,16 @@ class NewsCreateView(CreateView): newsitem.author = self.request.user newsitem.slug = find_unique_slug(News, newsitem.title) newsitem.save() + if newsitem.send_announce: + ctx = Context({ + 'news': newsitem, + }) + template = loader.get_template('news/news_email_notification.txt') + send_mail('[arch-announce] %s' % newsitem.title, + template.render(ctx), + 'Arch Linux: Recent news updates: %s <arch-announce@archlinux.org>' % newsitem.author.get_full_name(), + ['arch-announce@archlinux.org'], + fail_silently=True) return super(NewsCreateView, self).form_valid(form) |