def save(self, commit=False): def grab(s): return self.cleaned_data[s] game = Game.nearest_game() player = Player.user_to_player(self.user, game) self.thread = Thread( game=game, team=grab('team'), title=grab('title'), slug=slugify(grab('title')), ) self.thread.save() post = Post( author=player, thread=self.thread, body=grab('post_body'), created=settings.NOW(), ) if commit: post.save() return self.thread
def save(self, commit=False): post = Post( author=self.player, thread=self.thread, body=self.cleaned_data['body'], created=settings.NOW(), ) if commit: post.save() return post
def test_illegal_posting(self): game = Game.objects.get() human_thread = Thread(game=game, title="Humans Only", slug="humans-only", team="H") human_thread.full_clean() human_thread.save() zombie = Player.objects.get(team='Z') self.assertEqual(Post.objects.count(), 0) post = Post(thread=human_thread, author=zombie, created=settings.NOW(), body="H4%0R3D") self.assertRaises(ValidationError, post.full_clean)