# HG changeset patch # User neko259 # Date 2015-07-08 13:09:28 # Node ID a2cae5eecb5311c066a502396eba10fa81c2541a # Parent f80af42cc2548a3fb97907b2b76c157fe014c7f7 Fixed thread bumping diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -7,7 +7,7 @@ import uuid from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.db import models, transaction -from django.db.models import TextField +from django.db.models import TextField, QuerySet from django.template.loader import render_to_string from django.utils import timezone @@ -66,7 +66,7 @@ REFMAP_STR = '>>{} list: + def get_threads(self) -> QuerySet: """ Gets post's thread. """ @@ -361,8 +361,6 @@ class Post(models.Model, Viewable): if self.id: for thread in self.get_threads().all(): - if thread.can_bump(): - thread.update_bump_status(exclude_posts=[self]) thread.last_edit_time = self.last_edit_time thread.save(update_fields=['last_edit_time', 'bumpable']) diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -211,13 +211,15 @@ class Thread(models.Model): return boards.models.Tag.objects.get_tag_url_list(self.get_tags()) def update_posts_time(self, exclude_posts=None): + last_edit_time = self.last_edit_time + for post in self.post_set.all(): if exclude_posts is None or post not in exclude_posts: # Manual update is required because uids are generated on save - post.last_edit_time = self.last_edit_time + post.last_edit_time = last_edit_time post.save(update_fields=['last_edit_time']) - post.threads.update(last_edit_time=self.last_edit_time) + post.get_threads().update(last_edit_time=last_edit_time) def notify_clients(self): if not settings.get_bool('External', 'WebsocketsEnabled'): diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -375,6 +375,9 @@ function processNewPost(post) { showAsErrors($('form'), gettext('Sending message...')); }, success: updateOnPost, + error: function() { + showAsErrors($('form'), gettext('Server error!')); + }, url: '/api/add_post/' + threadId + '/' }; diff --git a/boards/tests/test_post.py b/boards/tests/test_post.py --- a/boards/tests/test_post.py +++ b/boards/tests/test_post.py @@ -1,5 +1,6 @@ from django.core.paginator import Paginator from django.test import TestCase + from boards import settings from boards.models import Tag, Post, Thread @@ -124,8 +125,8 @@ class PostTests(TestCase): tags=[tag]) thread = opening_post.get_thread() - reply1 = Post.objects.create_post(title='title', text='text', thread=thread) - reply2 = Post.objects.create_post(title='title', text='text', thread=thread) + Post.objects.create_post(title='title', text='text', thread=thread) + Post.objects.create_post(title='title', text='text', thread=thread) replies = thread.get_replies() self.assertTrue(len(replies) > 0, 'No replies found for thread.') @@ -133,3 +134,45 @@ class PostTests(TestCase): replies = thread.get_replies(view_fields_only=True) self.assertTrue(len(replies) > 0, 'No replies found for thread with view fields only.') + + def test_bumplimit(self): + """ + Tests that the thread bumpable status is changed and post uids and + last update times are updated across all post threads. + """ + + op1 = Post.objects.create_post(title='title', text='text') + op2 = Post.objects.create_post(title='title', text='text') + + thread1 = op1.get_thread() + thread1.max_posts = 5 + thread1.save() + + uid_1 = op1.uid + uid_2 = op2.uid + + # Create multi reply + Post.objects.create_post( + title='title', text='text', thread=thread1, + opening_posts=[op1, op2]) + thread_update_time_2 = op2.get_thread().last_edit_time + for i in range(6): + Post.objects.create_post(title='title', text='text', + thread=thread1) + + self.assertFalse(op1.get_thread().can_bump(), + 'Thread is bumpable when it should not be.') + self.assertTrue(op2.get_thread().can_bump(), + 'Thread is not bumpable when it should be.') + self.assertNotEqual( + uid_1, Post.objects.get(id=op1.id).uid, + 'UID of the first OP should be changed but it is not.') + self.assertEqual( + uid_2, Post.objects.get(id=op2.id).uid, + 'UID of the first OP should not be changed but it is.') + + self.assertNotEqual( + thread_update_time_2, + Thread.objects.get(id=op2.get_thread().id).last_edit_time, + 'Thread last update time should change when the other thread ' + 'changes status.') diff --git a/boards/views/all_threads.py b/boards/views/all_threads.py --- a/boards/views/all_threads.py +++ b/boards/views/all_threads.py @@ -151,7 +151,7 @@ class AllThreadsView(PostMixin, BaseBoar tags = self.parse_tags_string(tag_strings) post = Post.objects.create_post(title=title, text=text, image=image, - ip=ip, tags=tags, threads=threads) + ip=ip, tags=tags, opening_posts=threads) # This is required to update the threads to which posts we have replied # when creating this one diff --git a/boards/views/thread/thread.py b/boards/views/thread/thread.py --- a/boards/views/thread/thread.py +++ b/boards/views/thread/thread.py @@ -111,7 +111,7 @@ class ThreadView(BaseBoardView, PostMixi post = Post.objects.create_post(title=title, text=text, image=image, thread=post_thread, ip=ip, - threads=threads) + opening_posts=threads) post.notify_clients() if html_response: