Skip to content

Commit

Permalink
Merge pull request #2785 from artragis/precalculs
Browse files Browse the repository at this point in the history
Precalculs
  • Loading branch information
SpaceFox committed Jun 3, 2015
2 parents 3e59ec4 + 58eb225 commit 112f349
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion templates/article/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ <h3 class="comments-title" id="reactions">
{% endfor %}


{% include "misc/pagination.part.html" with position="bottom" topic=article is_online=True anchor="reactions" %}
{% include "misc/pagination.part.html" with position="bottom" topic=article is_online=True anchor="reactions" perms_change=is_staff %}



Expand Down
4 changes: 2 additions & 2 deletions templates/forum/topic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
{% set True as answer_schema %}
{% endif %}

{% include "misc/message.part.html" with answer_schema=answer_schema can_unread=True unread_link=unread_link %}
{% include "misc/message.part.html" with answer_schema=answer_schema can_unread=True unread_link=unread_link perms_change=is_staff%}
{% endfor %}

{% include "misc/paginator.html" with position="bottom" %}
Expand Down Expand Up @@ -294,4 +294,4 @@ <h3>{% trans "Modération" %}</h3>
</ul>
</div>
{% endif %}
{% endblock %}
{% endblock %}
22 changes: 11 additions & 11 deletions templates/misc/message.part.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% load i18n %}


{% if topic.author == message.author and helpful_link %}
{% if topic.author = message.author and helpful_link %}
{% set True as is_author %}
{% else %}
{% set False as is_author %}
Expand Down Expand Up @@ -50,15 +50,15 @@
</a>
</li>
{% endif %}
{% if message.author == user or is_staff %}
{% if message.author = user or perms_change %}
{% if can_hide != False %}
<li>
<a href="#hide-message-{{ message.id }}" class="ico-after hide open-modal">
{% trans "Masquer" %}
</a>
<form action="{{ edit_link|safe }}" method="post" id="hide-message-{{ message.id }}" class="modal modal-medium">
{% csrf_token %}
{% if is_staff %}
{% if perms_change %}
<p>
{% trans "Pour quelle raison souhaitez vous masquer ce message" %} ?
</p>
Expand All @@ -77,7 +77,7 @@
{% endif %}
{% endif %}

{% if message.author == user or is_staff %}
{% if message.author = user or perms_change %}
{% if can_edit != False %}
<li>
<a href="{{ edit_link|safe }}" class="ico-after edit">
Expand Down Expand Up @@ -114,7 +114,7 @@
</a>
</li>
{% endif %}
{% elif is_staff %}
{% elif perms_change %}
<li>
<a href="#show-message-hidden-{{ message.id }}" class="ico-after view">
{% trans "Voir" %}
Expand Down Expand Up @@ -175,7 +175,7 @@
<div itemprop="text">
{{ message.text_html|safe }}
</div>
{% elif is_staff %}
{% elif perms_change %}
<div class="message-hidden-content">
{{ message.text_html|safe }}
</div>
Expand All @@ -201,7 +201,7 @@
{% endif %}
</div>

{% if is_staff %}
{% if perms_change %}
{% for alert in message.alerts.all %}
<div class="alert-box error">
{{ alert.pubdate|format_date|capfirst }} {% trans "par" %}
Expand Down Expand Up @@ -243,8 +243,8 @@
{% if upvote_link %}
<div class="message-karma">
{% if user.is_authenticated and helpful_link and not is_author %}
{% if message.author != user or is_staff %}
{% if topic.author == user or is_staff %}
{% if message.author != user or perms_change %}
{% if topic.author = user or perms_change %}
<form action="{{ helpful_link }}" method="post">
{% csrf_token %}
<button
Expand Down Expand Up @@ -280,7 +280,7 @@
ico-after
{% if message.like > message.dislike %}more-voted{% endif %}
{% if message.like > 0 %}has-vote{% endif %}
{% if message.pk in user_like %}voted{% endif %}"
{% if profile_user|liked:message.pk %}voted{% endif %}"
>
+{{ message.like }}
</button>
Expand All @@ -295,7 +295,7 @@
ico-after
{% if message.like < message.dislike %}more-voted{% endif %}
{% if message.dislike > 0 %}has-vote{% endif %}
{% if message.pk in user_dislike %}voted{% endif %}"
{% if profile_user|disliked:message.pk %}voted{% endif %}"
>
-{{ message.dislike }}
</button>
Expand Down
2 changes: 1 addition & 1 deletion templates/tutorial/tutorial/view_online.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ <h3 class="comments-title" id="comments">
{% url 'zds.tutorial.views.answer' %}?tutorial={{ tutorial.pk }}
{% endcaptureas %}

{% include "misc/message_form.html" with member=user topic=tutorial %}
{% include "misc/message_form.html" with member=user topic=tutorial perms_change=is_staff %}
{% endblock %}


Expand Down
7 changes: 4 additions & 3 deletions zds/forum/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ def perform_edit_info(topic, data, editor):
class PostEditMixin(object):
@staticmethod
def perform_hide_message(request, post, user, data):
if post.author == user or user.has_perm('forum.change_post'):
is_staff = user.has_perm('forum.change_post')
if post.author == user or is_staff:
post.alerts.all().delete()
post.is_visible = False
post.editor = user

if user.has_perm('forum.change_post'):
post.text_hidden = data.get('text_hidden')
if is_staff:
post.text_hidden = data.get('text_hidden', '')

messages.success(request, _(u'Le message est désormais masqué.'))
else:
Expand Down
3 changes: 2 additions & 1 deletion zds/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ def test_success_edit_post_hide_message_by_author(self):
topic = add_topic_in_a_forum(forum, profile)

self.assertTrue(self.client.login(username=profile.user.username, password='hostel77'))
# WARNING : if author is not staff he can't send a delete message.
data = {
'delete_message': ''
}
Expand All @@ -1114,7 +1115,7 @@ def test_success_edit_post_hide_message_by_staff(self):

staff = StaffProfileFactory()
self.assertTrue(self.client.login(username=staff.user.username, password='hostel77'))
text_hidden_expected = 'Bad guy!'
text_hidden_expected = u'Bad guy!'
data = {
'delete_message': '',
'text_hidden': text_hidden_expected
Expand Down
9 changes: 6 additions & 3 deletions zds/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def get_context_data(self, **kwargs):
.select_related('comment')\
.filter(user__pk=self.request.user.pk, comments__pk__in=reaction_ids)\
.values_list('pk', flat=True)

context["is_staff"] = self.request.user.has_perm('forum.change_topic')
if self.request.user.is_authenticated():
if never_read(self.object):
mark_read(self.object)
Expand Down Expand Up @@ -233,7 +233,8 @@ def dispatch(self, request, *args, **kwargs):
return super(TopicEdit, self).dispatch(request, *args, **kwargs)

def get(self, request, *args, **kwargs):
if self.object.author != request.user and request.user.has_perm("forum.change_topic"):
is_staff = request.user.has_perm("forum.change_topic")
if self.object.author != request.user and is_staff:
messages.warning(request, _(
u'Vous éditez un topic en tant que modérateur (auteur : {}). Soyez encore plus '
u'prudent lors de l\'édition de celui-ci !').format(self.object.author.username))
Expand All @@ -246,7 +247,9 @@ def get(self, request, *args, **kwargs):
'subtitle': self.object.subtitle,
'text': self.object.first_post().text
})
return render(request, self.template_name, {'topic': self.object, 'form': form})
return render(request,
self.template_name,
{'topic': self.object, 'form': form, 'is_staff': is_staff})

def post(self, request, *args, **kwargs):
if 'text' in request.POST:
Expand Down

0 comments on commit 112f349

Please sign in to comment.