Skip to content

Commit

Permalink
Suivi des contenus par mail (#4036)
Browse files Browse the repository at this point in the history
* Ajoute le suivi par courriel aux reactions des contenus.

* Add test
  • Loading branch information
EGabbro authored and pierre-24 committed Dec 8, 2016
1 parent 4f8bc28 commit bb3d38a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "email/base_from_staff.html" %}

{% load i18n %}

{% block content_from_staff %}
<p>
{% blocktrans %}
<strong>{{ author }}</strong> a réagi au contenu « {{ title }} » que vous suivez sur {{ site_name }}.
{% endblocktrans %}
</p>

<p>
{% blocktrans %}
Pour le lire, <a href="{{ url }}">cliquez ici</a>.
{% endblocktrans %}
</p>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "email/base_from_staff.txt" %}
{% load i18n %}

{% block content_from_staff %}
{% blocktrans %}
{{ author }} a réagi au contenu « {{ title }} » que vous suivez sur {{ site_name }}.
{% endblocktrans %}

{% blocktrans %}
Pour le lire, cliquez ou recopiez l'url suivante : {{ url }}
{% endblocktrans %}
{% endblock %}
13 changes: 13 additions & 0 deletions templates/tutorialv2/view/content_online.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ <h2 class="subtitle" itemprop="description">
{% include 'notification/follow_template.html' with link=link_follow is_followed=content_is_followed data_onclick=data_onclick button_text=button_text subscriber_count=subscriber_count %}
{% endwith %}
</li>
<li>
{% with content_is_followed=object|is_content_email_followed %}
{% url 'content:follow-reactions' object.pk as link_follow %}
{% if content_is_followed %}
{% trans "Être notifié par courriel" as data_onclick %}
{% trans "Ne plus être notifié par courriel" as button_text %}
{% else %}
{% trans "Être notifié par courriel" as button_text %}
{% trans "Ne plus être notifié par courriel" as data_onclick %}
{% endif %}
{% include 'notification/follow_by_email_template.html' with link=link_follow is_followed=content_is_followed data_onclick=data_onclick button_text=button_text %}
{% endwith %}
</li>
{% if not user in content.authors.all %}
<li>
<a href="{{ pm_link }}" class="ico-after cite blue">
Expand Down
31 changes: 31 additions & 0 deletions zds/tutorialv2/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.models import Group
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.utils import override_settings
Expand Down Expand Up @@ -4920,6 +4921,36 @@ def test_last_reactions(self):
result = self.client.get(reverse('pages-index')) # go to whatever page
self.assertEqual(result.status_code, 200)

def test_reaction_follow_email(self):
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
self.assertEquals(0, len(mail.outbox))

profile = ProfileFactory()
self.assertTrue(self.client.login(username=profile.user.username, password='hostel77'))
response = self.client.post(reverse('content:follow-reactions', args=[self.tuto.pk]), {"email": "1"})
self.assertEquals(302, response.status_code)

self.assertIsNotNone(ContentReactionAnswerSubscription.objects.get_existing(
profile.user, self.tuto, is_active=True, by_email=True))

self.client.logout()

self.assertEqual(
self.client.login(
username=self.user_author.username,
password='hostel77'),
True)

# post another reaction
self.client.post(
reverse("content:add-reaction") + u'?pk={}'.format(self.tuto.pk),
{
'text': u'message',
'last_note': '0'
}, follow=True)

self.assertEquals(1, len(mail.outbox))

def test_note_with_bad_param(self):
self.assertEqual(
self.client.login(
Expand Down
3 changes: 3 additions & 0 deletions zds/tutorialv2/views/views_published.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ def post(self, request, *args, **kwargs):
.toggle_follow(self.get_object(), self.request.user).is_active
response['subscriberCount'] = ContentReactionAnswerSubscription\
.objects.get_subscriptions(self.get_object()).count()
elif 'email' in request.POST:
response['follow'] = ContentReactionAnswerSubscription.objects\
.toggle_follow(self.get_object(), self.request.user, True).is_active
if self.request.is_ajax():
return HttpResponse(json_writer.dumps(response), content_type='application/json')
return redirect(self.get_object().get_absolute_url())
Expand Down
7 changes: 7 additions & 0 deletions zds/utils/templatetags/interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def is_content_followed(content):
user, content, is_active=True)


@register.filter('is_content_email_followed')
def is_content_email_followed(content):
user = get_current_user()
return user.is_authenticated() and ContentReactionAnswerSubscription.objects.does_exist(
user, content, is_active=True, by_email=True)


@register.filter('is_new_publication_followed')
def is_new_publication_followed(user_to_follow):
user = get_current_user()
Expand Down

0 comments on commit bb3d38a

Please sign in to comment.