Add "Mark as Spam/Ham" views for posts.
This commit is contained in:
parent
052c5ba7ba
commit
7727cf39c7
4 changed files with 82 additions and 2 deletions
|
@ -150,6 +150,12 @@
|
|||
<ul>
|
||||
{% if user.is_authenticated %}
|
||||
<li class="postreport"><a href="{% url djangobb:misc %}?action=report&post_id={{ post.id }}">{% trans "Report" %}</a> </li>
|
||||
{% if moderator and post.poststatus and can_proceed|post.poststatus.mark_spam %}
|
||||
<li class="postmarkspam">| <a onclick="return confirm('{% trans "Are you sure you want to mark this as spam?" %}')" href="{% url djangobb:mark_post_spam post.id %}">{% trans "Mark as Spam" %}</a> </li>
|
||||
{% endif %}
|
||||
{% if moderator and post.poststatus and can_proceed|post.poststatus.mark_ham %}
|
||||
<li class="postmarkspam">| <a onclick="return confirm('{% trans "Are you sure you want to unmark this as spam?" %}')" href="{% url djangobb:mark_post_ham post.id %}">{% trans "Un-mark as Spam" %}</a> </li>
|
||||
{% endif %}
|
||||
{% if reply_form %}
|
||||
{% if moderator or user|forum_can_delete:post %}
|
||||
<li class="postdelete">| <a onclick="return confirm('{% trans "Are you sure you want to delete this post?" %}')" href="{% url djangobb:delete_post post.id %}">{% trans "Delete" %}</a> </li>
|
||||
|
|
|
@ -15,6 +15,8 @@ from django.utils.html import escape
|
|||
from django.utils.hashcompat import md5_constructor
|
||||
from django.contrib.humanize.templatetags.humanize import naturalday
|
||||
|
||||
from django_fsm.db.fields import can_proceed
|
||||
|
||||
from pagination.templatetags.pagination_tags import paginate
|
||||
|
||||
from djangobb_forum.models import Report, Post
|
||||
|
@ -235,6 +237,11 @@ def forum_authority(user):
|
|||
return mark_safe('<img src="%sdjangobb_forum/img/authority/vote0.gif" alt="" />' % (settings.STATIC_URL))
|
||||
|
||||
|
||||
@register.filter
|
||||
def can_proceed(method):
|
||||
return fsm_can_proceed(method)
|
||||
|
||||
|
||||
@register.filter
|
||||
def online(user):
|
||||
return cache.get('djangobb_user%d' % user.id)
|
||||
|
|
|
@ -36,6 +36,8 @@ urlpatterns = patterns('',
|
|||
url('^post/(?P<post_id>\d+)/$', forum_views.show_post, name='post'),
|
||||
url('^post/(?P<post_id>\d+)/edit/$', forum_views.edit_post, name='edit_post'),
|
||||
url('^post/(?P<post_id>\d+)/delete/$', forum_views.delete_post, name='delete_post'),
|
||||
url('^post/(?P<post_id>\d+)/mark_spam/$', forum_views.mark_spam, name='mark_post_spam'),
|
||||
url('^post/(?P<post_id>\d+)/mark_ham/$', forum_views.mark_ham, name='mark_post_ham'),
|
||||
url('^post/(?P<post_id>\d+)/source/$', forum_views.get_post_source, name='post_source'),
|
||||
# Post preview
|
||||
url(r'^preview/$', forum_views.post_preview, name='post_preview'),
|
||||
|
|
|
@ -27,7 +27,7 @@ from haystack.query import SearchQuerySet, SQ
|
|||
from djangobb_forum import settings as forum_settings
|
||||
from djangobb_forum.forms import AddPostForm, EditPostForm, UserSearchForm, \
|
||||
PostSearchForm, ReputationForm, MailToForm, PersonalityProfileForm, \
|
||||
VotePollForm, ReportForm, VotePollForm, PollForm
|
||||
VotePollForm, ReportForm, VotePollForm, PollForm, PostStatus
|
||||
from djangobb_forum.models import Category, Forum, Topic, Post, Reputation, \
|
||||
Report, Attachment, PostTracking
|
||||
from djangobb_forum.templatetags import forum_extras
|
||||
|
@ -401,7 +401,7 @@ def show_topic(request, topic_id, full=True):
|
|||
# without specifying, following query wouldn't select related properly
|
||||
posts = topic.posts.select_related('user__userprofile',
|
||||
'user__forum_profile',
|
||||
'updated_by', 'user').prefetch_related('user__groups').all()
|
||||
'updated_by', 'user', 'poststatus').prefetch_related('user__groups').all()
|
||||
edit_start = timezone.now() - timedelta(minutes=1)
|
||||
edit_end = timezone.now()
|
||||
editable = posts.filter(created__range=(edit_start, edit_end)).filter(user_id=request.user.id)
|
||||
|
@ -973,6 +973,71 @@ def delete_post(request, post_id):
|
|||
return HttpResponseRedirect(topic.get_absolute_url())
|
||||
|
||||
|
||||
@login_required
|
||||
@transaction.commit_on_success
|
||||
def mark_spam(request, post_id):
|
||||
post = get_object_or_404(Post, pk=post_id)
|
||||
topic = post.topic
|
||||
forum = post.topic.forum
|
||||
is_head = topic.head == post
|
||||
|
||||
try:
|
||||
post_status = post.poststatus
|
||||
except PostStatus.DoesNotExist:
|
||||
post_status = None
|
||||
|
||||
if not (
|
||||
request.user.is_superuser or
|
||||
request.user in post.topic.forum.moderators.all()):
|
||||
messages.success(request, _("You don't have permission to mark this post."))
|
||||
return HttpResponseRedirect(post.get_absolute_url())
|
||||
|
||||
if post_status is None:
|
||||
messages.success(request, _("There was not enough data collected to mark this post."))
|
||||
return HttpResponseRedirect(post.get_absolute_url())
|
||||
|
||||
if can_proceed(post_status.mark_spam):
|
||||
post_status.mark_spam()
|
||||
messages.success(request, _("Post marked as spam."))
|
||||
else:
|
||||
messages.success(request, _("This post is not in the right state to be marked as spam."))
|
||||
return HttpResponseRedirect(post.get_absolute_url())
|
||||
|
||||
if is_head:
|
||||
return HttpResponseRedirect(forum.get_absolute_url())
|
||||
return HttpResponseRedirect(topic.get_absolute_url())
|
||||
|
||||
|
||||
@login_required
|
||||
@transaction.commit_on_success
|
||||
def mark_ham(request, post_id):
|
||||
post = get_object_or_404(Post, pk=post_id)
|
||||
|
||||
try:
|
||||
post_status = post.poststatus
|
||||
except PostStatus.DoesNotExist:
|
||||
post_status = None
|
||||
|
||||
if not (
|
||||
request.user.is_superuser or
|
||||
request.user in post.topic.forum.moderators.all()):
|
||||
messages.success(request, _("You don't have permission to mark this post."))
|
||||
return HttpResponseRedirect(post.get_absolute_url())
|
||||
|
||||
if post_status is None:
|
||||
messages.success(request, _("There was not enough data collected to mark this post."))
|
||||
return HttpResponseRedirect(post.get_absolute_url())
|
||||
|
||||
if can_proceed(post_status.mark_ham):
|
||||
post_status.mark_ham()
|
||||
messages.success(request, _("Post un-marked as spam."))
|
||||
else:
|
||||
messages.success(request, _("This post is not in the right state to be un-marked as spam."))
|
||||
return HttpResponseRedirect(post.get_absolute_url())
|
||||
|
||||
return HttpResponseRedirect(post_status.post.get_absolute_url())
|
||||
|
||||
|
||||
@login_required
|
||||
@transaction.commit_on_success
|
||||
def open_close_topic(request, topic_id, action):
|
||||
|
|
Reference in a new issue