fixes bug #448
This commit is contained in:
parent
c04f72a33a
commit
14ece0a8f2
2 changed files with 16 additions and 19 deletions
|
@ -247,21 +247,21 @@ class Post(models.Model):
|
|||
self.last_forum_post.clear()
|
||||
|
||||
# If we actually delete the post, we lose any reports that my have come from it. Also, there is no recovery (but I don't care about that as much right now)
|
||||
if forum_settings.SOFT_DELETE_POSTS and (self.topic != get_object_or_404(Topic, pk=forum_settings.SOFT_DELETE_POSTS) or kwargs.get('staff', False)):
|
||||
self.topic = get_object_or_404(Topic, pk=forum_settings.SOFT_DELETE_POSTS)
|
||||
self.save()
|
||||
else:
|
||||
super(Post, self).delete(*args, **kwargs)
|
||||
#if post was last in topic - remove topic
|
||||
if self_id == head_post_id and not (forum_settings.SOFT_DELETE_POSTS and self.topic == get_object_or_404(Topic, pk=forum_settings.SOFT_DELETE_POSTS)):
|
||||
if self_id == head_post_id:
|
||||
topic.delete()
|
||||
else:
|
||||
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()
|
||||
if forum_settings.SOFT_DELETE_POSTS and (self.topic != get_object_or_404(Topic, pk=forum_settings.SOFT_DELETE_POSTS) or kwargs.get('staff', False)):
|
||||
self.topic = get_object_or_404(Topic, pk=forum_settings.SOFT_DELETE_POSTS)
|
||||
self.save()
|
||||
else:
|
||||
super(Post, self).delete(*args, **kwargs)
|
||||
#if post was last in topic - remove topic
|
||||
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:
|
||||
forum.last_post = Post.objects.filter(topic__forum__id=forum.id).latest()
|
||||
except Post.DoesNotExist:
|
||||
|
|
|
@ -876,6 +876,7 @@ def delete_post(request, post_id):
|
|||
last_post = post.topic.last_post
|
||||
topic = post.topic
|
||||
forum = post.topic.forum
|
||||
is_head = topic.posts.order_by('created')[0].id == post.id
|
||||
|
||||
if not (request.user.is_superuser or\
|
||||
request.user in post.topic.forum.moderators.all() or \
|
||||
|
@ -886,13 +887,9 @@ def delete_post(request, post_id):
|
|||
post.delete(**delete_kwargs)
|
||||
messages.success(request, _("Post deleted."))
|
||||
|
||||
try:
|
||||
Topic.objects.get(pk=topic.id)
|
||||
except Topic.DoesNotExist:
|
||||
#removed latest post in topic
|
||||
if is_head:
|
||||
return HttpResponseRedirect(forum.get_absolute_url())
|
||||
else:
|
||||
return HttpResponseRedirect(topic.get_absolute_url())
|
||||
return HttpResponseRedirect(topic.get_absolute_url())
|
||||
|
||||
|
||||
@login_required
|
||||
|
|
Reference in a new issue