diff options
author | Angel Velásquez <angvp@archlinux.org> | 2017-04-03 01:06:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 01:06:57 -0400 |
commit | 88576923cf02371743bf5f7a38a23667c694c59d (patch) | |
tree | 496134793cd71a4acec31582c0653f873eab898a | |
parent | 0e093e5c2b47022fd787ba1231ae61051d54175f (diff) | |
parent | fba04673d91707ac33ba24ff3d904ee8764d8745 (diff) | |
download | archweb-88576923cf02371743bf5f7a38a23667c694c59d.tar.gz archweb-88576923cf02371743bf5f7a38a23667c694c59d.zip |
Merge pull request #7 from grazzolini/news2email
News2email
-rw-r--r-- | news/migrations/0002_news_send_announce.py | 20 | ||||
-rw-r--r-- | news/models.py | 1 | ||||
-rw-r--r-- | news/views.py | 12 | ||||
-rw-r--r-- | templates/news/news_email_notification.txt | 3 |
4 files changed, 36 insertions, 0 deletions
diff --git a/news/migrations/0002_news_send_announce.py b/news/migrations/0002_news_send_announce.py new file mode 100644 index 00000000..62c23226 --- /dev/null +++ b/news/migrations/0002_news_send_announce.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='news', + name='send_announce', + field=models.BooleanField(default=True), + preserve_default=True, + ), + ] diff --git a/news/models.py b/news/models.py index a66da8d4..b413d17b 100644 --- a/news/models.py +++ b/news/models.py @@ -17,6 +17,7 @@ class News(models.Model): guid = models.CharField(max_length=255, editable=False) content = models.TextField() safe_mode = models.BooleanField(default=True) + send_announce = models.BooleanField(default=True) def get_absolute_url(self): return '/news/%s/' % self.slug 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) diff --git a/templates/news/news_email_notification.txt b/templates/news/news_email_notification.txt new file mode 100644 index 00000000..2588c921 --- /dev/null +++ b/templates/news/news_email_notification.txt @@ -0,0 +1,3 @@ +{{ news.content }} + +URL: https://www.archlinux.org{{ news.get_absolute_url }} |