Commits

neko259 committed 61416f4

Fixed indents for pycharm. Moved images upload path to settings. Some cosmetic changes.

  • Participants
  • Parent commits 8aafc19

Comments (0)

Files changed (3)

 from django.conf import settings
 
 class BoardManager(models.Manager):
-    def create_thread(self, board):
-	thread = self.create(board=board, posts=0, pub_date=timezone.now())
+    def create_thread(self):
+        thread = self.create(posts=0, pub_date=timezone.now())
 
-	return thread
+        return thread
 
     def create_post(self, title, text, thread, image):
-	post = self.create(title=title, text=text, pub_date=timezone.now(),
-		thread=thread, image=image, poster_ip='0.0.0.0',
-		poster_user_agent='')
-	thread.posts = thread.posts + 1
+        post = self.create(title=title, text=text, pub_date=timezone.now(),
+            thread=thread, image=image, poster_ip='0.0.0.0',
+            poster_user_agent='')
+        thread.posts += 1
 
-	return post
+        return post
 
     def delete_post(self, post):
-	thread = post.thread
-	post.delete()
-	thread.posts = thread.posts - 1
+        thread = post.thread
+        post.delete()
+        thread.posts -= 1
 
-	if (thread.is_empty):
-	    thread.delete()
+        if thread.is_empty:
+            thread.delete()
     
     def delete_posts_by_ip(self, ip):
-	posts = self.filter(poster_ip=ip)
-	for post in posts:
-	    self.delete_post(post)
+        posts = self.filter(poster_ip=ip)
+        for post in posts:
+            self.delete_post(post)
 
 class Board(models.Model):
     name = models.CharField(max_length=10)
     description = models.CharField(max_length=50)
 
     def __unicode__(self):
-	return self.name
+        return self.name
 
 class Thread(models.Model):
     objects = BoardManager()
 
-    board = models.ForeignKey(Board)
+    boards = models.ManyToManyField(Board)
     posts = models.IntegerField()
     pub_date = models.DateTimeField()
 
     def __unicode__(self):
-	return str(self.id)
+        return str(self.id)
 
     def is_dead(self):
-	return self.posts >= settings.MAX_POSTS_PER_THREAD
+        return self.posts >= settings.MAX_POSTS_PER_THREAD
 
     def is_empty(self):
-	return self.posts == 0
+        return self.posts == 0
 
 class Post(models.Model):
     objects = BoardManager()
     pub_date = models.DateTimeField()
     text = models.TextField()
     thread = models.ForeignKey(Thread)
-    image = models.ImageField(upload_to='images/src/')
+    image = models.ImageField(upload_to=settings.IMAGES_PATH)
     poster_ip = models.IPAddressField()
     poster_user_agent = models.TextField()
 
     def __unicode__(self):
-	return self.title + ' (' + self.text + ')'
+        return self.title + ' (' + self.text + ')'
 from django.test import TestCase
-from django.utils import timezone
 from django.conf import settings
 
 from boards.models import Board, Thread, Post
 class BoardTests(TestCase):
     
     def create_board(self):
-	return Board.objects.create(name='t', description='test')
+        return Board.objects.create(name='t', description='test')
 
     def create_thread(self, board):
-	return Thread.objects.create_thread(board=board)
+        thread = Thread.objects.create_thread()
+        thread.boards.add(board)
+
+        return thread
 
     def create_post(self, thread):
-	return Post.objects.create_post(title='title',
-		text='text', thread=thread, image=None)
+        return Post.objects.create_post(title='title',
+            text='text', thread=thread, image=None)
 
     def test_add_thread(self):
-	thread = self.create_thread(self.create_board())
+        thread = self.create_thread(self.create_board())
 
         self.assertIsNotNone(thread)
 
     def test_post_add(self):
-	thread = self.create_thread(self.create_board())
-	post = self.create_post(thread)
+        thread = self.create_thread(self.create_board())
+        post = self.create_post(thread)
 	
-	self.assertIsNotNone(post)
-	self.assertEqual(thread, post.thread)
+        self.assertIsNotNone(post)
+        self.assertEqual(thread, post.thread)
 
     def test_thread_post_count(self):
-	thread = self.create_thread(self.create_board())
-	self.create_post(thread)
+        thread = self.create_thread(self.create_board())
+        self.create_post(thread)
 
-	self.assertEqual(1, thread.posts)
+        self.assertEqual(1, thread.posts)
 
     def test_thread_dead(self):
-	thread = self.create_thread(self.create_board())
+        thread = self.create_thread(self.create_board())
 
-	for i in range(0, settings.MAX_POSTS_PER_THREAD):
-	    self.create_post(thread)
+        for i in range(0, settings.MAX_POSTS_PER_THREAD):
+            self.create_post(thread)
 
-	self.assertTrue(thread.is_dead())
+        self.assertTrue(thread.is_dead())
 
     def test_thread_empty(self):
-	thread = self.create_thread(self.create_board())
+        thread = self.create_thread(self.create_board())
 
-	self.assertTrue(thread.is_empty)
+        self.assertTrue(thread.is_empty)
 
     def test_delete_post(self):
-	thread = self.create_thread(self.create_board())
-	post = self.create_post(thread)
+        thread = self.create_thread(self.create_board())
+        post = self.create_post(thread)
 	
-	Post.objects.delete_post(post)
+        Post.objects.delete_post(post)
 
-	self.assertTrue(thread.is_empty())
+        self.assertTrue(thread.is_empty())
 
     def test_delete_posts_by_ip(self):
-	thread = self.create_thread(self.create_board())
-	self.create_post(thread)
+        thread = self.create_thread(self.create_board())
+        self.create_post(thread)
 
-	Post.objects.delete_posts_by_ip('0.0.0.0')
+        Post.objects.delete_posts_by_ip('0.0.0.0')
 
-	self.assertTrue(thread.is_empty())
+        self.assertTrue(thread.is_empty())

neboard/settings.py

 
 # Custom imageboard settings
 MAX_POSTS_PER_THREAD = 100
+IMAGES_PATH = "images"