Skip to content

Commit

Permalink
Signaler une faute dans un article
Browse files Browse the repository at this point in the history
  • Loading branch information
DevHugo committed Mar 20, 2015
1 parent 0708f8b commit 91aa901
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
32 changes: 32 additions & 0 deletions templates/article/includes/warn_typo.part.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% load i18n %}

{% if user.is_authenticated %}
{% if user not in authors.all %}
<a href="#warn-typo-modal" class="open-modal btn btn-grey ico-after edit blue">
{% trans "Signaler une faute dans l'article" %}
</a>
<form class="modal modal-big" id="warn-typo-modal" action="{% url "zds.article.views.warn_typo" %}" method="post" >
<p>
{% trans "J'ai trouvé une faute dans l'article" %}
:
</p>
{% csrf_token %}
<input type="hidden" name="article_pk" value="{{ article.pk }}">
<p>
<textarea name="explication" placeholder="{% blocktrans %}Expliquez ici la faute{% endblocktrans %}" required="required"></textarea>
</p>
<p>
{% trans "Pas assez de place ?" %}
<a href="{% url 'mp-new' %}?title={% trans "Je voudrais signaler une faute dans l'article" %} &quot;{{ article.title }}&quot;{% for username in authors.all %}&amp;username={{ username }}{% endfor %}" >
{% trans "Envoyez un MP" %}
{% if tutorial.authors.all|length > 1 %}
{% trans "aux auteurs" %}
{% else %}
{% trans "à l'auteur" %}
{% endif %}
</a>
</p>
<button type="submit">{% trans "Envoyer" %}</button>
</form>
{% endif %}
{% endif %}
4 changes: 3 additions & 1 deletion templates/article/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ <h2 class="subtitle">
{% block content %}
{{ article.txt|safe }}


{% include "article/includes/pager.part.html" %}

{% include "article/includes/warn_typo.part.html" with article=article authors=authors%}

{% endblock %}


Expand Down
2 changes: 2 additions & 0 deletions zds/article/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
53 changes: 53 additions & 0 deletions zds/article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 91aa901

Please sign in to comment.