##// END OF EJS Templates
Small changes to the docstrings. Added some TODOs
neko259 -
r418:5f184db4 default
parent child Browse files
Show More
@@ -57,6 +57,10 b' class PostManager(models.Manager):'
57
57
58 def create_post(self, title, text, image=None, thread=None,
58 def create_post(self, title, text, image=None, thread=None,
59 ip=NO_IP, tags=None, user=None):
59 ip=NO_IP, tags=None, user=None):
60 """
61 Create new post
62 """
63
60 self.clear_ppd_cache_if_old()
64 self.clear_ppd_cache_if_old()
61
65
62 posting_time = timezone.now()
66 posting_time = timezone.now()
@@ -95,6 +99,10 b' class PostManager(models.Manager):'
95 return post
99 return post
96
100
97 def delete_post(self, post):
101 def delete_post(self, post):
102 """
103 Delete post and update its thread
104 """
105
98 thread = post.thread_new
106 thread = post.thread_new
99 thread.last_edit_time = timezone.now()
107 thread.last_edit_time = timezone.now()
100 thread.save()
108 thread.save()
@@ -102,6 +110,10 b' class PostManager(models.Manager):'
102 post.delete()
110 post.delete()
103
111
104 def delete_posts_by_ip(self, ip):
112 def delete_posts_by_ip(self, ip):
113 """
114 Delete all posts of the author with same IP
115 """
116
105 posts = self.filter(poster_ip=ip)
117 posts = self.filter(poster_ip=ip)
106 map(self.delete_post, posts)
118 map(self.delete_post, posts)
107
119
@@ -159,7 +171,9 b' class PostManager(models.Manager):'
159 map(Thread.delete_with_posts, old_threads)
171 map(Thread.delete_with_posts, old_threads)
160
172
161 def connect_replies(self, post):
173 def connect_replies(self, post):
162 """Connect replies to a post to show them as a refmap"""
174 """
175 Connect replies to a post to show them as a reflink map
176 """
163
177
164 for reply_number in re.finditer(REGEX_REPLY, post.text.raw):
178 for reply_number in re.finditer(REGEX_REPLY, post.text.raw):
165 post_id = reply_number.group(1)
179 post_id = reply_number.group(1)
@@ -171,10 +185,16 b' class PostManager(models.Manager):'
171 referenced_post.save()
185 referenced_post.save()
172
186
173 def _get_page_count(self, thread_count):
187 def _get_page_count(self, thread_count):
188 """
189 Get number of pages that will be needed for all threads
190 """
191
174 return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE)))
192 return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE)))
175
193
176 def get_posts_per_day(self):
194 def get_posts_per_day(self):
177 """Get average count of posts per day for the last 7 days"""
195 """
196 Get average count of posts per day for the last 7 days
197 """
178
198
179 ppd = cache.get(CACHE_KEY_PPD)
199 ppd = cache.get(CACHE_KEY_PPD)
180 if ppd:
200 if ppd:
@@ -210,6 +230,7 b' class Post(models.Model):'
210 class Meta:
230 class Meta:
211 app_label = APP_LABEL_BOARDS
231 app_label = APP_LABEL_BOARDS
212
232
233 # TODO Save original file name to some field
213 def _update_image_filename(self, filename):
234 def _update_image_filename(self, filename):
214 """Get unique image filename"""
235 """Get unique image filename"""
215
236
@@ -279,12 +300,16 b' class Thread(models.Model):'
279 blank=True, related_name='tre+')
300 blank=True, related_name='tre+')
280
301
281 def get_tags(self):
302 def get_tags(self):
282 """Get a sorted tag list"""
303 """
304 Get a sorted tag list
305 """
283
306
284 return self.tags.order_by('name')
307 return self.tags.order_by('name')
285
308
286 def bump(self):
309 def bump(self):
287 """Bump (move to up) thread"""
310 """
311 Bump (move to up) thread
312 """
288
313
289 if self.can_bump():
314 if self.can_bump():
290 self.bump_time = timezone.now()
315 self.bump_time = timezone.now()
@@ -296,14 +321,18 b' class Thread(models.Model):'
296 return self.replies.filter(image_width__gt=0).count()
321 return self.replies.filter(image_width__gt=0).count()
297
322
298 def can_bump(self):
323 def can_bump(self):
299 """Check if the thread can be bumped by replying"""
324 """
325 Check if the thread can be bumped by replying
326 """
300
327
301 post_count = self.get_reply_count()
328 post_count = self.get_reply_count()
302
329
303 return post_count <= settings.MAX_POSTS_PER_THREAD
330 return post_count <= settings.MAX_POSTS_PER_THREAD
304
331
305 def delete_with_posts(self):
332 def delete_with_posts(self):
306 """Completely delete thread"""
333 """
334 Completely delete thread and all its posts
335 """
307
336
308 if self.replies.count() > 0:
337 if self.replies.count() > 0:
309 map(Post.objects.delete_post, self.replies.all())
338 map(Post.objects.delete_post, self.replies.all())
@@ -311,7 +340,9 b' class Thread(models.Model):'
311 self.delete()
340 self.delete()
312
341
313 def get_last_replies(self):
342 def get_last_replies(self):
314 """Get last replies, not including opening post"""
343 """
344 Get last replies, not including opening post
345 """
315
346
316 if settings.LAST_REPLIES_COUNT > 0:
347 if settings.LAST_REPLIES_COUNT > 0:
317 reply_count = self.get_reply_count()
348 reply_count = self.get_reply_count()
@@ -325,21 +356,34 b' class Thread(models.Model):'
325 return last_replies
356 return last_replies
326
357
327 def get_replies(self):
358 def get_replies(self):
328 """Get sorted thread posts"""
359 """
360 Get sorted thread posts
361 """
329
362
330 return self.replies.all().order_by('pub_time')
363 return self.replies.all().order_by('pub_time')
331
364
332 def add_tag(self, tag):
365 def add_tag(self, tag):
333 """Connect thread to a tag and tag to a thread"""
366 """
367 Connect thread to a tag and tag to a thread
368 """
334
369
335 self.tags.add(tag)
370 self.tags.add(tag)
336 tag.threads.add(self)
371 tag.threads.add(self)
337
372
338 def get_opening_post(self):
373 def get_opening_post(self):
374 """
375 Get first post of the thread
376 """
377
339 return self.get_replies()[0]
378 return self.get_replies()[0]
340
379
341 def __unicode__(self):
380 def __unicode__(self):
342 return str(self.get_replies()[0].id)
381 return str(self.get_replies()[0].id)
343
382
344 def get_pub_time(self):
383 def get_pub_time(self):
384 """
385 Thread does not have its own pub time, so we need to get it from
386 the opening post
387 """
388
345 return self.get_opening_post().pub_time
389 return self.get_opening_post().pub_time
General Comments 0
You need to be logged in to leave comments. Login now