Add User.last_draw()
This commit is contained in:
parent
0c16d9a73b
commit
3a1e234176
@ -24,6 +24,11 @@ def _current_word(self):
|
||||
|
||||
return None
|
||||
|
||||
def _last_draw(self):
|
||||
from .models import Draw
|
||||
|
||||
return Draw.objects.filter(user=self).order_by('-timestamp').first()
|
||||
|
||||
def _draw_word(self):
|
||||
if self.current_word() is not None:
|
||||
return self.current_word()
|
||||
@ -52,3 +57,4 @@ class WordsConfig(AppConfig):
|
||||
def ready(self):
|
||||
User.current_word = _current_word
|
||||
User.draw_word = _draw_word
|
||||
User.last_draw = _last_draw
|
||||
|
@ -1,5 +1,7 @@
|
||||
from datetime import timedelta
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import activate
|
||||
from django.test import TestCase
|
||||
|
||||
@ -93,3 +95,18 @@ class DrawTest(TestCase):
|
||||
Work.objects.create(draw=draw)
|
||||
|
||||
self.assertIsNone(self.user.draw_word())
|
||||
|
||||
def test_last_draw(self):
|
||||
draw = Draw.objects.create(
|
||||
user=self.user,
|
||||
word=self.word,
|
||||
accepted=True,
|
||||
timestamp=timezone.now() - timedelta(days=1))
|
||||
Work.objects.create(draw=draw)
|
||||
word = Word.objects.create()
|
||||
draw = Draw.objects.create(user=self.user,
|
||||
word=word,
|
||||
accepted=True)
|
||||
Work.objects.create(draw=draw)
|
||||
|
||||
self.assertEquals(word, self.user.last_draw().word)
|
||||
|
Loading…
Reference in New Issue
Block a user