Commit 46985ca4 by Jocelyn Delalande

Ne notifie pas (email) sur les articles non publiés

- état brouillon

OU

- date de publication dans le futur

Ref #62

Par contre, pour les publications programmées, on ne notifie pas à la date
programmée par email (les articles se mettent par contre bien à apparaître sur
le site).
parent 902cce2e
......@@ -22,7 +22,15 @@ def notify_email_new_text(sender, instance, created, raw, *args, **kwargs):
@receiver(post_save, sender=Article, dispatch_uid='notify-email-new-article')
def notify_email_new_article(sender, instance, created, raw, *args, **kwargs):
article = instance
if not raw and created:
if (
not raw
and
created
and
article.pub_date <= datetime.datetime.now()
and
article.publication_status == article.PUB_STATE_PUBLISHED
):
if article.is_publication():
subscribers = PaperbackEmailSubscription.objects.all()
else:
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
import datetime
from django.contrib.auth.models import User
from django.core import mail
......@@ -156,6 +157,36 @@ class EmailNotificationsTests(TestCase):
mail.outbox[0].body)
self.assertIn('/desinscription/', mail.outbox[0].body)
def test_dont_notify_unpublished_event(self):
EmailSubscription.objects.create(email='bacon@example.com',
targets='events')
EmailSubscription.objects.create(email='sausage@example.com',
targets='texts+paperbacks')
mail.outbox = []
Article.objects.create(
auteur=self.user,
categorie=Article.EVENEMENT,
publication_status=Article.PUB_STATE_DRAFT,
texte='<p>On fait un concerté, youhouuuuu</p>',
titre='Concert lu et chanté au chateau de Vezelay (42)'
)
self.assertEqual(len(mail.outbox), 0)
def test_dont_notify_future_event(self):
EmailSubscription.objects.create(email='bacon@example.com',
targets='events')
mail.outbox = []
Article.objects.create(
auteur=self.user,
categorie=Article.EVENEMENT,
publication_status=Article.PUB_STATE_PUBLISHED,
pub_date=datetime.datetime(2048, 2, 2),
texte='<p>On fait un concerté, youhouuuuu</p>',
titre='Concert lu et chanté au chateau de Vezelay (42)'
)
self.assertEqual(len(mail.outbox), 0)
def test_notify_published_paperback(self):
EmailSubscription.objects.create(email='sausage@example.com',
targets='paperbacks+texts')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment