Add User.successful_words()
It lists all the words the user has successfully uploaded work for
This commit is contained in:
		| @@ -85,6 +85,13 @@ def _failed_words(self): | |||||||
|  |  | ||||||
|     return [draw.word for draw in flt] |     return [draw.word for draw in flt] | ||||||
|  |  | ||||||
|  | def _successful_words(self): | ||||||
|  |     from .models import Draw | ||||||
|  |  | ||||||
|  |     flt = filter(lambda x: x.successful(), Draw.objects.filter(user=self)) | ||||||
|  |  | ||||||
|  |     return [draw.word for draw in flt] | ||||||
|  |  | ||||||
| class WordsConfig(AppConfig): | class WordsConfig(AppConfig): | ||||||
|     name = 'words' |     name = 'words' | ||||||
|  |  | ||||||
| @@ -93,3 +100,4 @@ class WordsConfig(AppConfig): | |||||||
|         User.draw_word = _draw_word |         User.draw_word = _draw_word | ||||||
|         User.last_draw = _last_draw |         User.last_draw = _last_draw | ||||||
|         User.failed_words = _failed_words |         User.failed_words = _failed_words | ||||||
|  |         User.successful_words = _successful_words | ||||||
|   | |||||||
| @@ -195,7 +195,7 @@ class DrawTest(TestCase): | |||||||
|         self.assertIsNotNone(draw.successful()) |         self.assertIsNotNone(draw.successful()) | ||||||
|         self.assertFalse(draw.successful()) |         self.assertFalse(draw.successful()) | ||||||
|  |  | ||||||
|     def test_failed_words(self): |     def test_failed_successful_words(self): | ||||||
|         self.assertEquals([], self.user.failed_words()) |         self.assertEquals([], self.user.failed_words()) | ||||||
|  |  | ||||||
|         draw = Draw.objects.create(user=self.user, |         draw = Draw.objects.create(user=self.user, | ||||||
| @@ -203,6 +203,7 @@ class DrawTest(TestCase): | |||||||
|                                    accepted=True, |                                    accepted=True, | ||||||
|                                    timestamp=timezone.now() - timedelta(days=2)) |                                    timestamp=timezone.now() - timedelta(days=2)) | ||||||
|         self.assertEquals([draw.word], self.user.failed_words()) |         self.assertEquals([draw.word], self.user.failed_words()) | ||||||
|  |         self.assertEquals([], self.user.successful_words()) | ||||||
|  |  | ||||||
|         draw2 = Draw.objects.create(user=self.user, |         draw2 = Draw.objects.create(user=self.user, | ||||||
|                                    word=Word.objects.create(), |                                    word=Word.objects.create(), | ||||||
| @@ -212,3 +213,4 @@ class DrawTest(TestCase): | |||||||
|                             upload_time=timezone.now() - timedelta(days=3)) |                             upload_time=timezone.now() - timedelta(days=3)) | ||||||
|  |  | ||||||
|         self.assertEquals([draw.word], self.user.failed_words()) |         self.assertEquals([draw.word], self.user.failed_words()) | ||||||
|  |         self.assertEquals([draw2.word], self.user.successful_words()) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user