The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ

Add User.last_draw()

gitter-badge
Gergely Polonkai 7 years ago
parent 0c16d9a73b
commit 3a1e234176
  1. 6
      words/apps.py
  2. 17
      words/tests.py

@ -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…
Cancel
Save