Skip to content

Commit

Permalink
Merge pull request #3885 from GerardPaligot/fix_3842
Browse files Browse the repository at this point in the history
Marque le MP de réservation du staff comme lue.
  • Loading branch information
pierre-24 authored Oct 24, 2016
2 parents 9495485 + c0cf68c commit 7da461c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion templates/forum/find/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
{% for post in posts %}
<tr>
<td>
<div class="forum-entry-title {% if user.is_authenticated %} {% if topic.never_read %} unread {% endif %} {% endif %}">
<div class="forum-entry-title {% if user.is_authenticated %} {% if topic.is_unread %} unread {% endif %} {% endif %}">
<a href="{{ post.get_absolute_url }}">{{ post.topic.title }} </a>
{% if post.topic.subtitle %} <p> {{ post.topic.subtitle }} </p> {% endif %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/forum/find/topic.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{% for topic in topics %}
<tr>
<td>
<div class="forum-entry-title {% if user.is_authenticated %} {% if topic.never_read %} unread {% endif %} {% endif %}">
<div class="forum-entry-title {% if user.is_authenticated %} {% if topic.is_unread %} unread {% endif %} {% endif %}">
<a href="{{ topic.get_absolute_url }}">{{ topic.title }} </a>
{% if topic.subtitle %} <p> {{ topic.subtitle }} </p> {% endif %}
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/mp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
{% block content %}
<div class="topic-list navigable-list">
{% for topic in privatetopics %}
<div class="topic {% if topic.never_read %}unread{% endif %} navigable-elem">
<div class="topic {% if topic.is_unread %}unread{% endif %} navigable-elem">
<div class="topic-infos">
<input name="items" type="checkbox" value="{{ topic.pk }}" form="delete-conversations">
</div>
{% with profile=topic.author|profile %}
<div class="topic-description">
<a href="{{ topic.get_absolute_url }}" class="topic-title-link navigable-link">{% spaceless %}
{% if topic.never_read %}<span class="a11y">{% trans "Non-lu" %} :</span>{% endif %}
{% if topic.is_unread %}<span class="a11y">{% trans "Non-lu" %} :</span>{% endif %}
<span class="topic-title">{{ topic.title }}</span>
<span class="topic-subtitle">{{ topic.subtitle }}</span>
{% endspaceless %}</a>
Expand Down
6 changes: 3 additions & 3 deletions zds/mp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def alone(self):
"""
return self.participants.count() == 0

def never_read(self, user=None):
def is_unread(self, user=None):
"""
Check if an user has never read the current PrivateTopic.
Expand All @@ -168,7 +168,7 @@ def never_read(self, user=None):
if user is None:
user = get_current_user()

return never_privateread(self, user)
return is_privatetopic_unread(self, user)

def is_author(self, user):
"""
Expand Down Expand Up @@ -307,7 +307,7 @@ def __unicode__(self):
return u'<Sujet « {0} » lu par {1}, #{2}>'.format(self.privatetopic, self.user, self.privatepost.pk)


def never_privateread(privatetopic, user=None):
def is_privatetopic_unread(privatetopic, user=None):
"""
Check if a private topic has been read by an user since it last post was added.
Expand Down
18 changes: 9 additions & 9 deletions zds/mp/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from zds.member.factories import ProfileFactory
from zds.mp.factories import PrivateTopicFactory, PrivatePostFactory
from zds.mp.models import mark_read, never_privateread, PrivateTopicRead
from zds.mp.models import mark_read, is_privatetopic_unread, PrivateTopicRead
from zds import settings

# by moment, i wrote the scenario to be simpler
Expand Down Expand Up @@ -120,13 +120,13 @@ def test_never_read(self):
# scenario - topic1 :
# post1 - user1 - unread
# post2 - user2 - unread
self.assertTrue(self.topic1.never_read(self.profile1.user))
self.assertTrue(self.topic1.is_unread(self.profile1.user))

# scenario - topic1 :
# post1 - user1 - read
# post2 - user2 - read
mark_read(self.topic1, self.profile1.user)
self.assertFalse(self.topic1.never_read(self.profile1.user))
self.assertFalse(self.topic1.is_unread(self.profile1.user))

# scenario - topic1 :
# post1 - user1 - read
Expand All @@ -137,7 +137,7 @@ def test_never_read(self):
author=self.profile2.user,
position_in_topic=3)

self.assertTrue(self.topic1.never_read(self.profile1.user))
self.assertTrue(self.topic1.is_unread(self.profile1.user))

def test_topic_never_read_get_last_read(self):
""" Trying to read last message of a never read Private Topic
Expand Down Expand Up @@ -242,18 +242,18 @@ def setUp(self):
position_in_topic=2)

def test_never_privateread(self):
self.assertTrue(never_privateread(self.topic1, self.profile1.user))
self.assertTrue(is_privatetopic_unread(self.topic1, self.profile1.user))
mark_read(self.topic1, self.profile1.user)
self.assertFalse(never_privateread(self.topic1, self.profile1.user))
self.assertFalse(is_privatetopic_unread(self.topic1, self.profile1.user))

def test_mark_read(self):
self.assertTrue(self.topic1.never_read(self.profile1.user))
self.assertTrue(self.topic1.is_unread(self.profile1.user))

# scenario - topic1 :
# post1 - user1 - read
# post2 - user2 - read
mark_read(self.topic1, self.profile1.user)
self.assertFalse(self.topic1.never_read(self.profile1.user))
self.assertFalse(self.topic1.is_unread(self.profile1.user))

# scenario - topic1 :
# post1 - user1 - read
Expand All @@ -263,4 +263,4 @@ def test_mark_read(self):
privatetopic=self.topic1,
author=self.profile2.user,
position_in_topic=3)
self.assertTrue(self.topic1.never_read(self.profile1.user))
self.assertTrue(self.topic1.is_unread(self.profile1.user))
7 changes: 6 additions & 1 deletion zds/tutorialv2/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from zds.gallery.models import GALLERY_WRITE, UserGallery, Gallery
from zds.gallery.models import Image
from zds.member.factories import ProfileFactory, StaffProfileFactory, UserFactory
from zds.mp.models import PrivateTopic
from zds.mp.models import PrivateTopic, is_privatetopic_unread
from zds.notification.models import TopicAnswerSubscription, ContentReactionAnswerSubscription, \
NewPublicationSubscription, Notification
from zds.settings import BASE_DIR
Expand Down Expand Up @@ -5287,6 +5287,11 @@ def test_beta_article_closed_when_published(self):
follow=False)
self.assertEqual(result.status_code, 302)

# Check that the staff user doesn't have a notification for their reservation and their private topic is read.
self.assertEqual(0, len(Notification.objects.get_unread_notifications_of(self.user_staff)))
last_pm = PrivateTopic.objects.get_private_topics_of_user(self.user_staff.pk).last()
self.assertFalse(is_privatetopic_unread(last_pm, self.user_staff))

# publish the article
result = self.client.post(
reverse('validation:accept', kwargs={'pk': validation.pk}),
Expand Down
3 changes: 2 additions & 1 deletion zds/tutorialv2/views/views_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,8 @@ def post(self, request, *args, **kwargs):
msg,
True,
leave=False,
direct=False
direct=False,
mark_as_read=True
)

messages.info(request, _(u"Ce contenu a bien été réservé par {0}.").format(request.user.username))
Expand Down
7 changes: 5 additions & 2 deletions zds/utils/mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string

from zds.mp.models import PrivateTopic, PrivatePost
from zds.mp.models import PrivateTopic, PrivatePost, mark_read
from zds.notification import signals
from zds.utils.templatetags.emarkdown import emarkdown

Expand All @@ -19,7 +19,8 @@ def send_mp(
text,
send_by_mail=True,
leave=True,
direct=False):
direct=False,
mark_as_read=False):
"""
Send MP at members.
Most of the param are obvious, excepted :
Expand All @@ -41,6 +42,8 @@ def send_mp(
n_topic.participants.add(part)

topic = send_message_mp(author, n_topic, text, send_by_mail, direct)
if mark_as_read:
mark_read(topic, author)

if leave:
move = topic.participants.first()
Expand Down

0 comments on commit 7da461c

Please sign in to comment.