closed #8 move button not work in Moderate forum

This commit is contained in:
alafin 2009-12-19 16:40:01 +02:00
parent 42cbcb5259
commit 441f8225c9
5 changed files with 70 additions and 54 deletions

View file

@ -27,46 +27,33 @@
</tr>
</thead>
<tbody>
{% for topic in sticky_topics %}
<tr class="isticky">
<td class="tcl">
<div class="intd">
<div class="icon"><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user }}</span>
{% endif %}
{% if topics %}
{% for topic in topics %}
<tr>
<td class="tcl">
<div class="intd">
<div {% if topic.sticky %}class="sticky"{% else %}{% if topic.closed %}class="closed"{% else %}{% if topic|has_unreads:user %}class="inew"{% else %}class="icon"{% endif %}{% endif %}{% endif %}><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic.sticky %}
{% trans "Sticky:" %}
{% endif %}
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user.username }}</span>
{% endif %}
</div>
</div>
</div>
</td>
<td class="tc2">{{ topic.post_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user }}</span></td>
<td class="tcmod"><input type="checkbox" name="{{ topic.id }}" value="1" /></td>
</tr>
{% endfor %}
{% for topic in topics %}
<tr {% if topic|has_unreads:user %}class="inew"{% endif %} {% if topic.closed %}class="iclosed"{% endif %}>
<td class="tcl">
<div class="intd">
<div class="icon"><div class="nosize"><!-- --></div></div>
<div class="tclcon">
{% if topic|has_unreads:user %}
<strong>{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user }}</span></strong>
{% else %}
{% link topic %} <span class="byuser">{% trans "by" %} {{ topic.user }}</span>
{% endif %}
</div>
</div>
</td>
<td class="tc2">{{ topic.reply_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user }}</span></td>
<td class="tcmod"><input type="checkbox" name="topic_id" value="{{ topic.id }}" /></td>
</tr>
{% endfor %}
</td>
<td class="tc2">{{ topic.reply_count }}</td>
<td class="tc3">{{ topic.views }}</td>
<td class="tcr"><a href="{{ topic.get_absolute_url }}">{% forum_time topic.updated %}</a> <span class="byuser">{% trans "by" %} {{ topic.last_post.user.username }}</span></td>
<td class="tcmod"><input type="checkbox" name="topic_id" value="{{ topic.id }}" /></td>
</tr>
{% endfor %}
{% else %}
<tr><td class="djangobbcon1" colspan="4">{% trans "Forum is empty." %}</td></tr>
{% endif %}
</tbody>
</table>
</div>

View file

@ -6,8 +6,9 @@
<div class="blockform">
<h2><span>{% trans "Move topic" %}</span></h2>
<div class="box">
<form method="get">
<form method="get" action="{% url djangobb:move_topic %}">
<div class="inform">
<input type="hidden" value="{{ topic_id }}" name="topic_id"/>
<fieldset>
<legend>{% trans "Select destination of move" %}</legend>
<div class="infldset">

View file

@ -202,7 +202,7 @@
<dl id="modcontrols"><dt><strong>{% trans "Moderator control" %}</strong></dt>
{% if moderator %}
<dd><a href="{% url djangobb:delete_posts topic.id %}">{% trans "Delete multiple posts" %}</a></dd>
<dd><a href="{% url djangobb:move_topic topic.id %}">{% trans "Move topic" %}</a></dd>
<dd><a href="{% url djangobb:move_topic %}?topic_id={{ topic.id }}">{% trans "Move topic" %}</a></dd>
{% if topic.closed %}
<dd><a href="{% url djangobb:open_topic topic.id %}">{% trans "Open topic" %}</a></dd>
{% else %}

View file

@ -31,7 +31,7 @@ urlpatterns = patterns('',
url('^(?P<forum_id>\d+)/topic/add/$', forum_views.add_post,
{'topic_id': None}, name='add_topic'),
url('^topic/(?P<topic_id>\d+)/delete_posts/$', forum_views.delete_posts, name='delete_posts'),
url('^topic/(?P<topic_id>\d+)/move/$', forum_views.move_topic, name='move_topic'),
url('^topic/move/$', forum_views.move_topic, name='move_topic'),
url('^topic/(?P<topic_id>\d+)/stick/$', forum_views.stick_topic, name='stick_topic'),
url('^topic/(?P<topic_id>\d+)/unstick/$', forum_views.unstick_topic, name='unstick_topic'),
url('^topic/(?P<topic_id>\d+)/close/$', forum_views.close_topic, name='close_topic'),

View file

@ -72,11 +72,15 @@ def index(request, full=True):
@paged('topics', forum_settings.FORUM_PAGE_SIZE)
def moderate(request, forum_id):
forum = Forum.objects.get(pk=forum_id)
topics = forum.topics.filter(sticky=False).select_related()
topics = forum.topics.order_by('-sticky', '-updated').select_related()
if request.user.is_superuser or request.user in forum.moderators.all():
topic_list = request.POST.getlist('topic_id')
if 'move_topics' in request.POST:
#TODO
topic_ids = ','.join([topic for topic in request.POST.getlist('topic_id')])
return {
'categories': Category.objects.all(),
'topic_id': topic_ids,
'TEMPLATE': 'forum/move_topic.html'
}
return HttpResponseRedirect(reverse('djangobb:index'))
elif 'delete_topics' in request.POST:
for topic_id in topic_list:
@ -94,7 +98,7 @@ def moderate(request, forum_id):
return {'forum': forum,
'topics': topics,
'sticky_topics': forum.topics.filter(sticky=True),
#'sticky_topics': forum.topics.filter(sticky=True),
'paged_qs': topics,
'posts': forum.posts.count(),
}
@ -594,16 +598,40 @@ def delete_posts(request, topic_id):
@login_required
@render_to('forum/move_topic.html')
def move_topic(request, topic_id):
def move_topic(request):
from forum.templatetags.forum_extras import forum_moderated_by
topic = get_object_or_404(Topic, pk=topic_id)
if forum_moderated_by(topic, request.user):
if 'to_forum' in request.GET:
topic.forum_id = request.GET['to_forum']
topic.save()
return HttpResponseRedirect(topic.forum.get_absolute_url())
first_topic = topic_ids = list(request.GET['topic_id'])
if len(topic_ids) > 1:
topic_ids = [topic_id for topic_id in topic_ids if topic_id != ',']
first_topic = topic_ids[0]
topic = get_object_or_404(Topic, pk=first_topic)
from_forum = topic.forum_id
if 'to_forum' in request.GET:
to_forum = int(request.GET['to_forum'])
for topic_id in topic_ids:
topic = get_object_or_404(Topic, pk=topic_id)
if topic.forum_id != to_forum:
if forum_moderated_by(topic, request.user):
forum = get_object_or_404(Forum, pk=topic.forum_id)
topic.forum_id = to_forum
forum.post_count -= topic.post_count
topic.forum.post_count += topic.post_count
forum.topic_count -= 1
topic.forum.topic_count += 1
topic.forum.save()
forum.save()
topic.save()
from_forum = get_object_or_404(Forum, pk=from_forum)
to_forum = get_object_or_404(Forum, pk=to_forum)
post = Post.objects.filter(topic__forum=from_forum)
from_forum.last_post = post.latest() if post else None
to_forum.last_post = Post.objects.filter(topic__forum=to_forum).latest()
from_forum.save()
to_forum.save()
return HttpResponseRedirect(to_forum.get_absolute_url())
return {'categories': Category.objects.all(),
'topic_id': topic_ids[0]
}
@login_required