Moving multiple posts at once functionality. Follows delete pattern.
Also can be used to merge two threads.
This commit is contained in:
parent
5412e344ca
commit
c8b4acb452
4 changed files with 160 additions and 0 deletions
djangobb_forum
70
djangobb_forum/templates/djangobb_forum/move_posts.html
Normal file
70
djangobb_forum/templates/djangobb_forum/move_posts.html
Normal file
|
@ -0,0 +1,70 @@
|
|||
{% extends 'djangobb_forum/base.html' %}
|
||||
{% load pagination_tags %}
|
||||
{% load forum_extras %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
|
||||
<div class="linkst">
|
||||
<div class="inbox">
|
||||
<div class="pagelink conl">{% paginate %}</div>
|
||||
<ul><li><a href="{% url djangobb:index %}">{% trans "Root" %} </a></li><li>» {% link topic.forum %} </li><li>» {{ topic }}
|
||||
<a href="{% url djangobb:forum_topic_feed topic.id %}"><img src="{{ STATIC_URL }}djangobb_forum/img/feed-icon-small.png" alt="[RSS Feed]" title="[RSS Feed]" style="vertical-align:middle;" /></a>
|
||||
</li></ul>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{% for post in posts %}
|
||||
<div id="p{{ post.id }}" class="blockpost roweven firstpost">
|
||||
<a name="post-{{ post.id }}"></a>
|
||||
<h2><span><span class="conr">#{{ forloop.counter }} </span><a href="{{ post.get_absolute_url }}">{% forum_time post.created %}</a></span></h2>
|
||||
<div class="box">
|
||||
<div class="inbox box-content">
|
||||
<div class="postleft">
|
||||
<dl>
|
||||
<dt><strong><a href="{% url profile_detail post.user.username %}">{{ post.user.username }}</a></strong></dt>
|
||||
<dd class="usertitle"><strong>{{ post.user.forum_profile.status }}</strong></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="postright">
|
||||
<h3>{{ post.topic.name }}</h3>
|
||||
<div class="postmsg">
|
||||
{{ post.body_html|safe }}
|
||||
{% if post.updated %}
|
||||
<p class="postedit"><em>{% trans "Edited" %} {{ post.user.username }} ({% forum_time post.updated %})</em></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<p class="multidelete"><label><strong>{% trans "Select" %}</strong> <input type="checkbox" name="post" value="{{ post.id }}" /></label></p>
|
||||
</div>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<div class="postlinksb">
|
||||
<div class="inbox">
|
||||
<div class="pagelink conl">{% paginate %}</div>
|
||||
|
||||
<div class="inform">
|
||||
{% for topic_id in topic_ids %}
|
||||
<input type="hidden" value="{{ topic_id }}" name="topic_id"/>
|
||||
{% endfor %}
|
||||
<fieldset>
|
||||
<legend>{% trans "Select destination of move" %}</legend>
|
||||
<div class="infldset">
|
||||
<label>{% trans "Move to Topic id:" %}<br />
|
||||
<input type="text" name="to_topic"></input>
|
||||
<br /></label>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<p><input type="submit" value="{% trans "Move" %}" class="small grey button" /><a href="javascript:history.go(-1)">{% trans "Go back" %}</a></p>
|
||||
<div class="clearer"></div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -228,6 +228,7 @@
|
|||
{% if moderator %}
|
||||
<dl id="modcontrols"><dt><strong>{% trans "Moderator control" %}</strong></dt>
|
||||
<dd><a class="moderator-only" href="{% url djangobb:delete_posts topic.id %}">{% trans "Delete multiple posts" %}</a></dd>
|
||||
<dd><a class="moderator-only" href="{% url djangobb:move_posts topic.id %}">{% trans "Move multiple posts" %}</a></dd>
|
||||
<dd><a class="moderator-only" href="{% url djangobb:move_topic %}?topic_id={{ topic.id }}">{% trans "Move topic" %}</a></dd>
|
||||
{% if topic.closed %}
|
||||
<dd><a class="moderator-only" href="{% url djangobb:open_close_topic topic.id 'o' %}">{% trans "Open topic" %}</a></dd>
|
||||
|
|
|
@ -56,6 +56,7 @@ urlpatterns = patterns('',
|
|||
url('^(?P<forum_id>\d+)/topic/add/$', forum_views.add_topic, name='add_topic'),
|
||||
url('^topic/(?P<topic_id>\d+)/delete_posts/$', forum_views.delete_posts, name='delete_posts'),
|
||||
url('^topic/move/$', forum_views.move_topic, name='move_topic'),
|
||||
url('^topic/(?P<topic_id>\d+)/move_posts/$', forum_views.move_posts, name='move_posts'),
|
||||
url('^topic/(?P<topic_id>\d+)/stick_unstick/(?P<action>[s|u])/$', forum_views.stick_unstick_topic, name='stick_unstick_topic'),
|
||||
url('^topic/(?P<topic_id>\d+)/open_close/(?P<action>[c|o])/$', forum_views.open_close_topic, name='open_close_topic'),
|
||||
|
||||
|
|
|
@ -709,6 +709,94 @@ def delete_posts(request, topic_id):
|
|||
})
|
||||
|
||||
|
||||
@login_required
|
||||
@transaction.commit_on_success
|
||||
def move_posts(request, topic_id):
|
||||
|
||||
topic = Topic.objects.select_related().get(pk=topic_id)
|
||||
from_forum = topic.forum
|
||||
|
||||
if forum_moderated_by(topic, request.user):
|
||||
moved = False
|
||||
post_list = request.POST.getlist('post')
|
||||
if 'to_topic' in request.POST:
|
||||
try:
|
||||
to_topic_id = int(request.POST['to_topic'])
|
||||
except ValueError:
|
||||
messages.error(request, _("The topic must be an integer."))
|
||||
else:
|
||||
try:
|
||||
to_topic = Topic.objects.select_related().get(pk=to_topic_id)
|
||||
except Topic.DoesNotExist:
|
||||
messages.error(request, _("I cannot find that thread."))
|
||||
else:
|
||||
for post_id in post_list:
|
||||
if not moved:
|
||||
moved = True
|
||||
post = get_object_or_404(Post, pk=post_id)
|
||||
if post.topic != to_topic:
|
||||
last = (topic.last_post == post)
|
||||
if forum_moderated_by(to_topic, request.user):
|
||||
post.topic = to_topic
|
||||
post.save()
|
||||
if Post.objects.filter(topic__id=topic.id).count() == 0:
|
||||
topic.delete()
|
||||
deleted = True
|
||||
else:
|
||||
deleted = False
|
||||
try:
|
||||
topic.last_post = Post.objects.filter(topic__id=topic.id).latest()
|
||||
except Post.DoesNotExist:
|
||||
topic.last_post = None
|
||||
topic.post_count = Post.objects.filter(topic__id=topic.id).count()
|
||||
topic.save()
|
||||
try:
|
||||
from_forum.last_post = Post.objects.filter(topic__forum__id=from_forum.id).latest()
|
||||
except Post.DoesNotExist:
|
||||
from_forum.last_post = None
|
||||
from_forum.post_count = Post.objects.filter(topic__forum__id=from_forum.id).count()
|
||||
from_forum.topic_count = Topic.objects.filter(forum__id=from_forum.id).count()
|
||||
from_forum.save()
|
||||
|
||||
to_topic.post_count = Post.objects.filter(topic__id=to_topic.id).count()
|
||||
to_topic.save()
|
||||
|
||||
|
||||
if moved:
|
||||
messages.success(request, _("Posts moved."))
|
||||
if not deleted:
|
||||
return HttpResponseRedirect(topic.get_absolute_url())
|
||||
else:
|
||||
return HttpResponseRedirect(from_forum.get_absolute_url())
|
||||
|
||||
last_post = topic.posts.latest()
|
||||
|
||||
if request.user.is_authenticated():
|
||||
topic.update_read(request.user)
|
||||
|
||||
posts = topic.posts.all().select_related()
|
||||
|
||||
initial = {}
|
||||
if request.user.is_authenticated():
|
||||
initial = {'markup': request.user.forum_profile.markup}
|
||||
form = AddPostForm(topic=topic, initial=initial)
|
||||
|
||||
moderator = request.user.is_superuser or\
|
||||
request.user in topic.forum.moderators.all()
|
||||
if request.user.is_authenticated() and request.user in topic.subscribers.all():
|
||||
subscribed = True
|
||||
else:
|
||||
subscribed = False
|
||||
return render(request, 'djangobb_forum/move_posts.html', {'categories': Category.objects.all(),
|
||||
'exclude_topic': from_forum,
|
||||
'topic': topic,
|
||||
'last_post': last_post,
|
||||
'form': form,
|
||||
'moderator': moderator,
|
||||
'subscribed': subscribed,
|
||||
'posts': posts,
|
||||
})
|
||||
|
||||
@login_required
|
||||
@transaction.commit_on_success
|
||||
def move_topic(request):
|
||||
|
|
Reference in a new issue