Skip to content

Commit

Permalink
Merge pull request #4212 from GCodeur/alerte_contenus_attente
Browse files Browse the repository at this point in the history
Ajoute une alerte sur le nombre de contenus orphelins en validation
  • Loading branch information
artragis committed Apr 10, 2017
2 parents 659f4b7 + fcc8d99 commit b02adc6
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 9 deletions.
7 changes: 6 additions & 1 deletion assets/scss/components/_mobile-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,9 @@
}
}
}
}


.mobile-menu-link .validations-count {
display: none;
}
}
18 changes: 17 additions & 1 deletion assets/scss/layout/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
height: 60px;
width: 60px;
float: right;
position: relative;

.username {
display: none;
Expand Down Expand Up @@ -481,11 +482,26 @@
right: 2.5%;
}
}

.my-account {
.validations-count {
display: block !important;
position: absolute;
z-index: 1;
top: 50%;
right: 50%;
margin: -20px -22px 0 0;
padding: 0 5px;
height: 16px;
line-height: 14px;
background: #c0392b; //@TODO: Color
border-radius: 16px;
}
}
}

@media only screen and #{$media-extra-wide} {
.header-container header .header-menu {
margin-left: 5%;
}
}

14 changes: 14 additions & 0 deletions doc/source/front-end/template-tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ Récupère la liste des alertes (si l'utilisateur possède les droits pour le fa
- ``alert.pubdate`` donne la date à laquelle l'alerte à été faite ;
- ``alert.topic`` donne le texte d'alerte.

``waiting_count``
---------------

Récupère le nombre de contenus, de tutoriels ou d'articles dans la zone de validation n'ayant pas été réservés par un validateur.

.. sourcecode:: html

{% load interventions %}
{% with waiting_all_count=""|waiting_count waiting_tutorials_count="TUTORIAL"|waiting_count waiting_articles_count="ARTICLE"|waiting_count %}
...
{% endwith %}
Le filtre doit être appelé sur ``"TUTORIAL"`` pour récupérer le nombre de tutoriels en attente et sur ``"ARTICLE"`` pour le nombre d'articles. Pour le nombre de contenus, il faut l'appeler sur une chaîne de caractères vide ``""``.

``humane_delta``
----------------

Expand Down
31 changes: 25 additions & 6 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,13 @@
data-active="open-my-account"
{% endif %}
>
{% if perms.forum.change_post %}
{% with waiting_all_count=""|waiting_count %}
{% if waiting_all_count > 0 %}
<span class="validations-count">{{ waiting_all_count }}</span>
{% endif %}
{% endwith %}
{% endif %}
<img src="{{ profile.get_avatar_url|remove_url_protocole }}" alt="" class="avatar">
<span class="username label">{{ user.username }}</span>
</a>
Expand All @@ -509,12 +516,24 @@
</li>

{% if perms.tutorialv2.change_validation %}
<li class="staff-only">
<a href="{% url "validation:list" %}?type=tuto">{% trans "Validation des tutoriels" %}</a>
</li>
<li class="staff-only">
<a href="{% url "validation:list" %}?type=article">{% trans "Validation des articles" %}</a>
</li>
{% with waiting_tutorials_count="TUTORIAL"|waiting_count waiting_articles_count="ARTICLE"|waiting_count %}
<li class="staff-only">
<a href="{% url "validation:list" %}?type=tuto">
{% trans "Validation des tutoriels" %}
{% if waiting_tutorials_count > 0 %}
({{ waiting_tutorials_count }})
{% endif %}
</a>
</li>
<li class="staff-only">
<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
18 changes: 18 additions & 0 deletions zds/utils/templatetags/interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

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
from zds.utils import get_current_user
from zds.utils.models import Alert
from zds import settings
from zds.tutorialv2.models import TYPE_CHOICES_DICT

register = template.Library()

Expand Down Expand Up @@ -194,3 +196,19 @@ def alerts_list(user):
'text': alert.text})

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


@register.filter(name='waiting_count')
def waiting_count(content_type):

queryset = Validation.objects.filter(
validator__isnull=True,
status='PENDING')

if content_type:
if content_type not in TYPE_CHOICES_DICT:
raise template.TemplateSyntaxError("'content_type' must be in 'zds.tutorialv2.models.TYPE_CHOICES_DICT'")
else:
queryset = queryset.filter(content__type=content_type)

return queryset.count()
46 changes: 45 additions & 1 deletion zds/utils/templatetags/tests/tests_interventions.py
Original file line number Diff line number Diff line change
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 b02adc6

Please sign in to comment.