fixes tracker issue #137

This commit is contained in:
Nathan Dinsmore 2013-01-14 21:13:32 -05:00
parent 62ac2296ca
commit b1d65bd4d6
4 changed files with 57 additions and 24 deletions

View 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();
}
});
});
});

View file

@ -3,6 +3,11 @@
{% load forum_extras %}
{% load i18n %}
{% block js %}
{{ block.super }}
<script type="text/javascript" src="{{ STATIC_URL }}/djangobb_forum/js/move_posts.js"></script>
{% endblock %}
{% block content %}
{% autopaginate posts forum_settings.TOPIC_PAGE_SIZE %}
<div class="linkst">
@ -20,8 +25,8 @@
{% 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 }}&nbsp;</span><a href="{{ post.get_absolute_url }}">{{ post.created|forum_time }}</a></span></h2>
<div class="box">
<h2><span><span class="conr">#{{ forloop.counter }}&nbsp;</span><a href="{{ post.get_absolute_url }}">{{ post.created|forum_time }}</a></span></h2>
<div class="inbox box-content">
<div class="postleft">
<dl>
@ -32,37 +37,41 @@
<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 }} ({{ post.updated|forum_time }})</em></p>
{% endif %}
<p class="post_body_html">{{ post.body_html|safe }}</p>
{% if post.updated %}
<p class="postedit"><em>{% trans "Edited" %} {{ post.user.username }} ({{ post.updated|forum_time }})</em></p>
{% endif %}
</div>
<p class="multidelete"><label><strong>{% trans "Select" %}</strong>&nbsp;&nbsp;<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 class="clearer"></div>
</div>
</div>
</div>
{% endfor %}
<div class="postlinksb">
<div class="inbox">
<div class="pagelink conl">{% paginate %}</div>
</div>
</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><button type="submit" class="grey button"><span>{% trans "Move" %}</span></button> <a href="javascript:history.go(-1)">{% trans "Go back" %}</a></p>
<div class="blockform">
<div class="box-content">
<div class="inform">
{% for topic_id in topic_ids %}
<input type="hidden" value="{{ topic_id }}" name="topic_id"/>
{% endfor %}
<fieldset>
<legend>{% trans "Move posts" %}</legend>
<div class="infldset">
<label>{% trans "Move to Topic id:" %}<input type="text" name="to_topic"></input></label>
</div>
</fieldset>
</div>
<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>
</div>

View file

@ -28,6 +28,7 @@ urlpatterns = patterns('',
# 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('^topic/(?P<topic_id>\d+)/delete_posts/$', forum_views.delete_posts, name='delete_posts'),
url('^topic/move/$', forum_views.move_topic, name='move_topic'),

View file

@ -1,6 +1,7 @@
# coding: utf-8
import math
import re
from datetime import datetime, timedelta
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)
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
@transaction.commit_on_success
def edit_post(request, post_id):
@ -727,11 +734,11 @@ def move_posts(request, topic_id):
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:
match = re.match(r'.*?(\d+)', request.POST['to_topic'])
if match is None:
messages.error(request, _("The topic must be an integer."))
else:
to_topic_id = int(match.group(1))
try:
to_topic = Topic.objects.select_related().get(pk=to_topic_id)
except Topic.DoesNotExist: