Add User.failed_words()
It lists all the words the user has failed to upload work for
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user