Add User.successful_words()

It lists all the words the user has successfully uploaded work for
This commit is contained in:
Gergely Polonkai 2015-11-27 15:56:05 +01:00
parent 65019fd713
commit 3c0882df07
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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())