diff --git a/djangobb_forum/models.py b/djangobb_forum/models.py index e5c5f41..4982648 100644 --- a/djangobb_forum/models.py +++ b/djangobb_forum/models.py @@ -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: diff --git a/djangobb_forum/views.py b/djangobb_forum/views.py index 0067fb3..d0f2ed3 100644 --- a/djangobb_forum/views.py +++ b/djangobb_forum/views.py @@ -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