Skip to content

Commit

Permalink
Ajoute une alerte sur le nombre de contenus orphelins en validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gllmc committed Feb 14, 2017
1 parent 94480bb commit c03963b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
24 changes: 18 additions & 6 deletions templates/base.html
Expand Up @@ -509,12 +509,24 @@
</li>

{% if perms.tutorialv2.change_validation %}
<li>
<a href="{% url "validation:list" %}?type=tuto">{% trans "Validation des tutoriels" %}</a>
</li>
<li>
<a href="{% url "validation:list" %}?type=article">{% trans "Validation des articles" %}</a>
</li>
{% with waiting_tutorials_count=user|waiting_tutorials_count waiting_articles_count=user|waiting_articles_count %}
<li>
<a href="{% url "validation:list" %}?type=tuto">
{% trans "Validation des tutoriels" %}
{% if waiting_tutorials_count > 0 %}
({{ waiting_tutorials_count }})
{% endif %}
</a>
</li>
<li>
<a href="{% url "validation:list" %}?type=article">
{% trans "Validation des articles" %}
{% if waiting_articles_count > 0 %}
({{ waiting_articles_count }})
{% endif %}
</a>
</li>
{% endwith %}
{% endif %}

{% if perms.featured.change_featuredresource %}
Expand Down
17 changes: 17 additions & 0 deletions zds/utils/templatetags/interventions.py
Expand Up @@ -9,6 +9,7 @@

from zds.forum.models import Post, is_read as topic_is_read
from zds.mp.models import PrivateTopic
from zds.tutorialv2.models.models_database import Validation
from zds.notification.models import Notification, TopicAnswerSubscription, ContentReactionAnswerSubscription, \
NewTopicSubscription, NewPublicationSubscription
from zds.tutorialv2.models.models_database import ContentReaction
Expand Down Expand Up @@ -182,3 +183,19 @@ def alerts_list(user):
'text': alert.text})

return {'alerts': total, 'nb_alerts': nb_alerts}


@register.filter(name='waiting_tutorials_count')
def waiting_tutorials_count(user):
return Validation.objects.filter(
validator__isnull=True,
status='PENDING',
content__type='TUTORIAL').count()


@register.filter(name='waiting_articles_count')
def waiting_articles_count(user):
return Validation.objects.filter(
validator__isnull=True,
status='PENDING',
content__type='ARTICLE').count()
46 changes: 45 additions & 1 deletion zds/utils/templatetags/tests/tests_interventions.py
Expand Up @@ -7,7 +7,9 @@
from django.test import TestCase

from zds.forum.factories import CategoryFactory, ForumFactory, PostFactory, TopicFactory
from zds.member.factories import ProfileFactory, StaffFactory
from zds.tutorialv2.models.models_database import Validation
from zds.tutorialv2.factories import PublishableContentFactory, LicenceFactory, SubCategoryFactory
from zds.member.factories import ProfileFactory, StaffProfileFactory, StaffFactory
from zds.utils.models import Alert
from zds.utils.mps import send_message_mp, send_mp
from zds.utils.templatetags.interventions import alerts_list
Expand All @@ -24,8 +26,27 @@ class InterventionsTest(TestCase):
"""

def setUp(self):
self.licence = LicenceFactory()
self.subcategory = SubCategoryFactory()

self.author = ProfileFactory()
self.user = ProfileFactory()
self.staff = StaffProfileFactory()

self.tuto = PublishableContentFactory(type='TUTORIAL')
self.tuto.authors.add(self.author.user)
self.tuto.licence = self.licence
self.tuto.subcategory.add(self.subcategory)
self.tuto.save()

self.validation = Validation(
content=self.tuto,
version=self.tuto.sha_draft,
comment_authors='bla',
date_proposition=datetime.now(),
)
self.validation.save()

self.topic = send_mp(author=self.author.user, users=[], title='Title', text='Testing', subtitle='', leave=False)
self.topic.participants.add(self.user.user)
send_message_mp(self.user.user, self.topic, 'Testing')
Expand Down Expand Up @@ -82,6 +103,29 @@ def test_interventions_privatetopics_author_leave(self):
self.assertEqual(200, response.status_code)
self.assertContains(response, '<span class="notif-count">1</span>', html=True)

def test_interventions_waiting_contents(self):
# Login as staff
self.assertTrue(
self.client.login(
username=self.staff.user.username,
password='hostel77'
)
)

# check that the number of waiting tutorials is correct
response = self.client.post(reverse('homepage'))
self.assertEqual(200, response.status_code)
self.assertContains(response, '(1)')

# Mark the content as reserved
self.validation.status = 'PENDING_V'
self.validation.save()

# and check that the count was removed
response = self.client.post(reverse('homepage'))
self.assertEqual(200, response.status_code)
self.assertNotContains(response, '(1)')

def test_interventions_humane_delta(self):
tr = Template('{% load interventions %}'
'{{ date_today|humane_delta }}'
Expand Down

0 comments on commit c03963b

Please sign in to comment.