##// END OF EJS Templates
Removed strange 'exists' method in post manager, fixed tests in which it was...
neko259 -
r396:0d260248 default
parent child Browse files
Show More
@@ -3,7 +3,6 b' from random import random'
3 import time
3 import time
4 import math
4 import math
5 import re
5 import re
6 from django.core.cache import cache
7
6
8 from django.db import models
7 from django.db import models
9 from django.http import Http404
8 from django.http import Http404
@@ -79,15 +78,12 b' class PostManager(models.Manager):'
79 if post.replies.count() > 0:
78 if post.replies.count() > 0:
80 map(self.delete_post, post.replies.all())
79 map(self.delete_post, post.replies.all())
81
80
82 # Update thread's last edit time (used as cache key)
81 # Update thread's last edit time
83 thread = post.thread
82 thread = post.thread
84 if thread:
83 if thread:
85 thread.clear_cache()
86
87 thread.last_edit_time = timezone.now()
84 thread.last_edit_time = timezone.now()
88 thread.save()
85 thread.save()
89
86
90 post.clear_cache()
91 post.delete()
87 post.delete()
92
88
93 def delete_posts_by_ip(self, ip):
89 def delete_posts_by_ip(self, ip):
@@ -123,17 +119,10 b' class PostManager(models.Manager):'
123 except Post.DoesNotExist:
119 except Post.DoesNotExist:
124 raise Http404
120 raise Http404
125
121
126 cache_key = opening_post.get_cache_key()
127 thread = cache.get(cache_key)
128 if thread:
129 return thread
130
131 if opening_post.replies:
122 if opening_post.replies:
132 thread = [opening_post]
123 thread = [opening_post]
133 thread.extend(opening_post.replies.all().order_by('pub_time'))
124 thread.extend(opening_post.replies.all().order_by('pub_time'))
134
125
135 cache.set(cache_key, thread, boards_settings.CACHE_TIMEOUT)
136
137 return thread
126 return thread
138
127
139 def get_thread_page_count(self, tag=None):
128 def get_thread_page_count(self, tag=None):
@@ -253,20 +242,12 b' class Post(models.Model):'
253
242
254 return post_count <= settings.MAX_POSTS_PER_THREAD
243 return post_count <= settings.MAX_POSTS_PER_THREAD
255
244
256 def clear_cache(self):
257 """Remove the post from cache"""
258
259 cache_key = self.get_cache_key()
260 cache.delete(cache_key)
261
262 def bump(self):
245 def bump(self):
263 """Bump (move to up) thread"""
246 """Bump (move to up) thread"""
264
247
265 if self.can_bump():
248 if self.can_bump():
266 self.bump_time = timezone.now()
249 self.bump_time = timezone.now()
267
250
268 self.clear_cache()
269
270 def get_last_replies(self):
251 def get_last_replies(self):
271 if settings.LAST_REPLIES_COUNT > 0:
252 if settings.LAST_REPLIES_COUNT > 0:
272 reply_count = self.get_reply_count()
253 reply_count = self.get_reply_count()
@@ -284,9 +265,6 b' class Post(models.Model):'
284
265
285 return self.tags.order_by('name')
266 return self.tags.order_by('name')
286
267
287 def get_cache_key(self):
288 return 'thread_cache' + str(self.id)
289
290 def get_sorted_referenced_posts(self):
268 def get_sorted_referenced_posts(self):
291 return self.referenced_posts.order_by('id')
269 return self.referenced_posts.order_by('id')
292
270
@@ -41,7 +41,7 b' class PostTests(TestCase):'
41
41
42 Post.objects.delete_post(post)
42 Post.objects.delete_post(post)
43
43
44 self.assertFalse(Post.objects.exists(post_id))
44 self.assertFalse(Post.objects.filter(id=post_id).exists())
45
45
46 def test_delete_thread(self):
46 def test_delete_thread(self):
47 """Test thread deletion"""
47 """Test thread deletion"""
@@ -51,7 +51,7 b' class PostTests(TestCase):'
51
51
52 Post.objects.delete_post(thread)
52 Post.objects.delete_post(thread)
53
53
54 self.assertFalse(Post.objects.exists(reply.id))
54 self.assertFalse(Post.objects.filter(id=reply.id).exists())
55
55
56 def test_post_to_thread(self):
56 def test_post_to_thread(self):
57 """Test adding post to a thread"""
57 """Test adding post to a thread"""
@@ -72,7 +72,7 b' class PostTests(TestCase):'
72
72
73 Post.objects.delete_posts_by_ip('0.0.0.0')
73 Post.objects.delete_posts_by_ip('0.0.0.0')
74
74
75 self.assertFalse(Post.objects.exists(post_id))
75 self.assertFalse(Post.objects.filter(id=post_id).exists())
76
76
77 def test_get_thread(self):
77 def test_get_thread(self):
78 """Test getting all posts of a thread"""
78 """Test getting all posts of a thread"""
General Comments 0
You need to be logged in to leave comments. Login now