From 3c0882df07b7b45acade721e18d5d9c0b26fd6fc Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 27 Nov 2015 15:56:05 +0100 Subject: [PATCH] Add User.successful_words() It lists all the words the user has successfully uploaded work for --- words/apps.py | 8 ++++++++ words/tests.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/words/apps.py b/words/apps.py index 9f86f39..6fe4413 100644 --- a/words/apps.py +++ b/words/apps.py @@ -85,6 +85,13 @@ def _failed_words(self): 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): name = 'words' @@ -93,3 +100,4 @@ class WordsConfig(AppConfig): User.draw_word = _draw_word User.last_draw = _last_draw User.failed_words = _failed_words + User.successful_words = _successful_words diff --git a/words/tests.py b/words/tests.py index 704c714..fb227cb 100644 --- a/words/tests.py +++ b/words/tests.py @@ -195,7 +195,7 @@ class DrawTest(TestCase): self.assertIsNotNone(draw.successful()) self.assertFalse(draw.successful()) - def test_failed_words(self): + def test_failed_successful_words(self): self.assertEquals([], self.user.failed_words()) draw = Draw.objects.create(user=self.user, @@ -203,6 +203,7 @@ class DrawTest(TestCase): accepted=True, timestamp=timezone.now() - timedelta(days=2)) self.assertEquals([draw.word], self.user.failed_words()) + self.assertEquals([], self.user.successful_words()) draw2 = Draw.objects.create(user=self.user, word=Word.objects.create(), @@ -212,3 +213,4 @@ class DrawTest(TestCase): upload_time=timezone.now() - timedelta(days=3)) self.assertEquals([draw.word], self.user.failed_words()) + self.assertEquals([draw2.word], self.user.successful_words())