From 91aa901be17084321dc8fc9775e5597780ab19ff Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 18 Mar 2015 15:45:37 +0100 Subject: [PATCH] Signaler une faute dans un article --- .../article/includes/warn_typo.part.html | 32 +++++++++++ templates/article/view.html | 4 +- zds/article/urls.py | 2 + zds/article/views.py | 53 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 templates/article/includes/warn_typo.part.html diff --git a/templates/article/includes/warn_typo.part.html b/templates/article/includes/warn_typo.part.html new file mode 100644 index 0000000000..c0993e0142 --- /dev/null +++ b/templates/article/includes/warn_typo.part.html @@ -0,0 +1,32 @@ +{% load i18n %} + +{% if user.is_authenticated %} + {% if user not in authors.all %} + + {% trans "Signaler une faute dans l'article" %} + + + {% endif %} +{% endif %} \ No newline at end of file diff --git a/templates/article/view.html b/templates/article/view.html index 0e3a151c26..e6571395bd 100644 --- a/templates/article/view.html +++ b/templates/article/view.html @@ -113,8 +113,10 @@

{% block content %} {{ article.txt|safe }} - {% include "article/includes/pager.part.html" %} + + {% include "article/includes/warn_typo.part.html" with article=article authors=authors%} + {% endblock %} diff --git a/zds/article/urls.py b/zds/article/urls.py index 0797113cef..0dae6b834f 100644 --- a/zds/article/urls.py +++ b/zds/article/urls.py @@ -56,4 +56,6 @@ 'zds.article.views.like_reaction'), url(r'^message/dislike/$', 'zds.article.views.dislike_reaction'), + url(r'^message/typo/$', + 'zds.article.views.warn_typo'), ) diff --git a/zds/article/views.py b/zds/article/views.py index f1b5a0604d..9a89122872 100644 --- a/zds/article/views.py +++ b/zds/article/views.py @@ -2,6 +2,8 @@ from datetime import datetime from operator import attrgetter +from zds.member.models import Profile + try: import ujson as json_reader except ImportError: @@ -215,6 +217,57 @@ def view_online(request, article_pk, article_slug): }) +@can_write_and_read_now +@login_required +@require_POST +def warn_typo(request): + """Warn author(s) about a mistake in its (their) article by sending him/her (them) a private message.""" + + # Need profile + profile = get_object_or_404(Profile, user=request.user) + + # Get article + try: + article_pk = int(request.POST['article_pk']) + except (KeyError, ValueError): + raise Http404 + + article = get_object_or_404(Article, pk=article_pk) + + # Fetch explanation + if 'explication' not in request.POST or not request.POST['explication'].strip(): + messages.error(request, _(u'Votre proposition de correction est vide')) + else: + explanation = request.POST['explication'] + explanation = '\n'.join(['> ' + line for line in explanation.split('\n')]) + + # Is the user trying to send PM to himself ? + if request.user in article.authors.all(): + messages.error(request, _(u'Impossible d\'envoyer la correction car vous êtes l\'auteur de cet article !')) + else: + # Create message : + msg = _(u'[{}]({}) souhaite vous proposer une correction pour votre article [{}]({}).\n\n').format( + request.user.username, + settings.ZDS_APP['site']['url'] + profile.get_absolute_url(), + article.title, + settings.ZDS_APP['site']['url'] + article.get_absolute_url_online() + ) + + msg += _(u'Voici son message :\n\n{}').format(explanation) + + # send it : + send_mp(request.user, + article.authors.all(), + _(u"Proposition de correction"), + article.title, + msg, + leave=False) + messages.success(request, _(u'Votre correction a bien été proposée !')) + + # return to page : + return redirect(article.get_absolute_url_online()) + + @can_write_and_read_now @login_required def new(request):