##// 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 3 import time
4 4 import math
5 5 import re
6 from django.core.cache import cache
7 6
8 7 from django.db import models
9 8 from django.http import Http404
@@ -79,15 +78,12 b' class PostManager(models.Manager):'
79 78 if post.replies.count() > 0:
80 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 82 thread = post.thread
84 83 if thread:
85 thread.clear_cache()
86
87 84 thread.last_edit_time = timezone.now()
88 85 thread.save()
89 86
90 post.clear_cache()
91 87 post.delete()
92 88
93 89 def delete_posts_by_ip(self, ip):
@@ -123,17 +119,10 b' class PostManager(models.Manager):'
123 119 except Post.DoesNotExist:
124 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 122 if opening_post.replies:
132 123 thread = [opening_post]
133 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 126 return thread
138 127
139 128 def get_thread_page_count(self, tag=None):
@@ -253,20 +242,12 b' class Post(models.Model):'
253 242
254 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 245 def bump(self):
263 246 """Bump (move to up) thread"""
264 247
265 248 if self.can_bump():
266 249 self.bump_time = timezone.now()
267 250
268 self.clear_cache()
269
270 251 def get_last_replies(self):
271 252 if settings.LAST_REPLIES_COUNT > 0:
272 253 reply_count = self.get_reply_count()
@@ -284,9 +265,6 b' class Post(models.Model):'
284 265
285 266 return self.tags.order_by('name')
286 267
287 def get_cache_key(self):
288 return 'thread_cache' + str(self.id)
289
290 268 def get_sorted_referenced_posts(self):
291 269 return self.referenced_posts.order_by('id')
292 270
@@ -41,7 +41,7 b' class PostTests(TestCase):'
41 41
42 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 46 def test_delete_thread(self):
47 47 """Test thread deletion"""
@@ -51,7 +51,7 b' class PostTests(TestCase):'
51 51
52 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 56 def test_post_to_thread(self):
57 57 """Test adding post to a thread"""
@@ -72,7 +72,7 b' class PostTests(TestCase):'
72 72
73 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 77 def test_get_thread(self):
78 78 """Test getting all posts of a thread"""
General Comments 0
You need to be logged in to leave comments. Login now