Add User.failed_words()

It lists all the words the user has failed to upload work for
This commit is contained in:
Gergely Polonkai 2015-11-27 15:50:22 +01:00
parent 3da4b39860
commit 65019fd713
2 changed files with 26 additions and 0 deletions

View File

@ -78,6 +78,13 @@ def _draw_word(self):
return word
def _failed_words(self):
from .models import Draw
flt = filter(lambda x: not x.successful(), Draw.objects.filter(user=self))
return [draw.word for draw in flt]
class WordsConfig(AppConfig):
name = 'words'
@ -85,3 +92,4 @@ class WordsConfig(AppConfig):
User.current_word = _current_word
User.draw_word = _draw_word
User.last_draw = _last_draw
User.failed_words = _failed_words

View File

@ -194,3 +194,21 @@ class DrawTest(TestCase):
draw.save()
self.assertIsNotNone(draw.successful())
self.assertFalse(draw.successful())
def test_failed_words(self):
self.assertEquals([], self.user.failed_words())
draw = Draw.objects.create(user=self.user,
word=self.word,
accepted=True,
timestamp=timezone.now() - timedelta(days=2))
self.assertEquals([draw.word], self.user.failed_words())
draw2 = Draw.objects.create(user=self.user,
word=Word.objects.create(),
accepted=True,
timestamp=timezone.now() - timedelta(days=3))
Work.objects.create(draw=draw2,
upload_time=timezone.now() - timedelta(days=3))
self.assertEquals([draw.word], self.user.failed_words())