fixes tracker issue #137
This commit is contained in:
parent
62ac2296ca
commit
b1d65bd4d6
4 changed files with 57 additions and 24 deletions
16
djangobb_forum/static/djangobb_forum/js/move_posts.js
Normal file
16
djangobb_forum/static/djangobb_forum/js/move_posts.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
$(document).ready(function () {
|
||||||
|
$('form').submit(function (e) {
|
||||||
|
var t = this,
|
||||||
|
id = /\d+/.exec($('[name=to_topic]').val());
|
||||||
|
e.preventDefault();
|
||||||
|
if (!id) {
|
||||||
|
alert('Invalid topic ID.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$.get('/forums/topic/' + id[0] + '/title/', function (title) {
|
||||||
|
if (confirm('Do you really want to move these posts to "' + title + '"?')) {
|
||||||
|
t.submit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -3,6 +3,11 @@
|
||||||
{% load forum_extras %}
|
{% load forum_extras %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{{ block.super }}
|
||||||
|
<script type="text/javascript" src="{{ STATIC_URL }}/djangobb_forum/js/move_posts.js"></script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
|
{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
|
||||||
<div class="linkst">
|
<div class="linkst">
|
||||||
|
@ -20,8 +25,8 @@
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<div id="p{{ post.id }}" class="blockpost roweven firstpost">
|
<div id="p{{ post.id }}" class="blockpost roweven firstpost">
|
||||||
<a name="post-{{ post.id }}"></a>
|
<a name="post-{{ post.id }}"></a>
|
||||||
<h2><span><span class="conr">#{{ forloop.counter }} </span><a href="{{ post.get_absolute_url }}">{{ post.created|forum_time }}</a></span></h2>
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
<h2><span><span class="conr">#{{ forloop.counter }} </span><a href="{{ post.get_absolute_url }}">{{ post.created|forum_time }}</a></span></h2>
|
||||||
<div class="inbox box-content">
|
<div class="inbox box-content">
|
||||||
<div class="postleft">
|
<div class="postleft">
|
||||||
<dl>
|
<dl>
|
||||||
|
@ -32,37 +37,41 @@
|
||||||
<div class="postright">
|
<div class="postright">
|
||||||
<h3>{{ post.topic.name }}</h3>
|
<h3>{{ post.topic.name }}</h3>
|
||||||
<div class="postmsg">
|
<div class="postmsg">
|
||||||
{{ post.body_html|safe }}
|
<p class="post_body_html">{{ post.body_html|safe }}</p>
|
||||||
{% if post.updated %}
|
{% if post.updated %}
|
||||||
<p class="postedit"><em>{% trans "Edited" %} {{ post.user.username }} ({{ post.updated|forum_time }})</em></p>
|
<p class="postedit"><em>{% trans "Edited" %} {{ post.user.username }} ({{ post.updated|forum_time }})</em></p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<p class="multidelete"><label><strong>{% trans "Select" %}</strong> <input type="checkbox" name="post" value="{{ post.id }}" /></label></p>
|
<p class="multidelete"><label>
|
||||||
|
<strong>{% trans "Select" %}</strong>
|
||||||
|
<input type="checkbox" name="post" value="{{ post.id }}" />
|
||||||
|
</label></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="clearer"></div>
|
<div class="clearer"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
<div class="postlinksb">
|
<div class="postlinksb">
|
||||||
<div class="inbox">
|
<div class="inbox">
|
||||||
<div class="pagelink conl">{% paginate %}</div>
|
<div class="pagelink conl">{% paginate %}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="inform">
|
<div class="blockform">
|
||||||
{% for topic_id in topic_ids %}
|
<div class="box-content">
|
||||||
<input type="hidden" value="{{ topic_id }}" name="topic_id"/>
|
<div class="inform">
|
||||||
{% endfor %}
|
{% for topic_id in topic_ids %}
|
||||||
<fieldset>
|
<input type="hidden" value="{{ topic_id }}" name="topic_id"/>
|
||||||
<legend>{% trans "Select destination of move" %}</legend>
|
{% endfor %}
|
||||||
<div class="infldset">
|
<fieldset>
|
||||||
<label>{% trans "Move to Topic id:" %}<br />
|
<legend>{% trans "Move posts" %}</legend>
|
||||||
<input type="text" name="to_topic"></input>
|
<div class="infldset">
|
||||||
<br /></label>
|
<label>{% trans "Move to Topic id:" %}<input type="text" name="to_topic"></input></label>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<p><button type="submit" class="grey button"><span>{% trans "Move" %}</span></button> <a href="javascript:history.go(-1)">{% trans "Go back" %}</a></p>
|
<p><button type="submit" class="grey button"><span>{% trans "Move" %}</span></button> <a href="javascript:history.go(-1)">{% trans "Go back" %}</a></p>
|
||||||
<div class="clearer"></div>
|
<div class="clearer"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,6 +28,7 @@ urlpatterns = patterns('',
|
||||||
|
|
||||||
# Topic
|
# Topic
|
||||||
url('^topic/(?P<topic_id>\d+)/$', forum_views.show_topic, name='topic'),
|
url('^topic/(?P<topic_id>\d+)/$', forum_views.show_topic, name='topic'),
|
||||||
|
url('^topic/(?P<topic_id>\d+)/title/$', forum_views.get_topic_title, name='topic_title'),
|
||||||
url('^(?P<forum_id>\d+)/topic/add/$', forum_views.add_topic, name='add_topic'),
|
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/(?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/move/$', forum_views.move_topic, name='move_topic'),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
import math
|
import math
|
||||||
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
@ -648,6 +649,12 @@ def get_post_source(request, post_id):
|
||||||
post = get_object_or_404(Post, pk=post_id)
|
post = get_object_or_404(Post, pk=post_id)
|
||||||
return HttpResponse(post.body, mimetype='text/plain')
|
return HttpResponse(post.body, mimetype='text/plain')
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
def get_topic_title(request, topic_id):
|
||||||
|
'Raw (plain text) topic title for move posts confirmation'
|
||||||
|
topic = get_object_or_404(Topic, pk=topic_id)
|
||||||
|
return HttpResponse(topic.name, mimetype='text/plain')
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@transaction.commit_on_success
|
@transaction.commit_on_success
|
||||||
def edit_post(request, post_id):
|
def edit_post(request, post_id):
|
||||||
|
@ -727,11 +734,11 @@ def move_posts(request, topic_id):
|
||||||
moved = False
|
moved = False
|
||||||
post_list = request.POST.getlist('post')
|
post_list = request.POST.getlist('post')
|
||||||
if 'to_topic' in request.POST:
|
if 'to_topic' in request.POST:
|
||||||
try:
|
match = re.match(r'.*?(\d+)', request.POST['to_topic'])
|
||||||
to_topic_id = int(request.POST['to_topic'])
|
if match is None:
|
||||||
except ValueError:
|
|
||||||
messages.error(request, _("The topic must be an integer."))
|
messages.error(request, _("The topic must be an integer."))
|
||||||
else:
|
else:
|
||||||
|
to_topic_id = int(match.group(1))
|
||||||
try:
|
try:
|
||||||
to_topic = Topic.objects.select_related().get(pk=to_topic_id)
|
to_topic = Topic.objects.select_related().get(pk=to_topic_id)
|
||||||
except Topic.DoesNotExist:
|
except Topic.DoesNotExist:
|
||||||
|
|
Reference in a new issue