Allow drawing once every day
The duration between two draws is controlled by settings.DRAW_TIME
This commit is contained in:
parent
3a1e234176
commit
a53b2827a9
@ -101,3 +101,5 @@ USE_TZ = True
|
||||
# https://docs.djangoproject.com/en/1.8/howto/static-files/
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
DRAW_TIME = '1 00:00:00'
|
||||
|
@ -1,6 +1,8 @@
|
||||
from django.apps import AppConfig
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_duration
|
||||
|
||||
def _current_word(self):
|
||||
from .models import Draw
|
||||
@ -35,6 +37,12 @@ def _draw_word(self):
|
||||
|
||||
from .models import Word, Draw
|
||||
|
||||
last_draw = self.last_draw()
|
||||
duration = parse_duration(settings.DRAW_TIME)
|
||||
|
||||
if last_draw.timestamp + duration > timezone.now():
|
||||
return last_draw.word
|
||||
|
||||
# Find all words
|
||||
# Exclude all words that has an accepted draw for this user
|
||||
# Choose a random one
|
||||
|
@ -1,7 +1,9 @@
|
||||
from datetime import timedelta
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_duration
|
||||
from django.utils.translation import activate
|
||||
from django.test import TestCase
|
||||
|
||||
@ -80,6 +82,8 @@ class DrawTest(TestCase):
|
||||
accepted=None)
|
||||
self.assertEquals(self.word, self.user.draw_word())
|
||||
draw.accepted = True
|
||||
duration = parse_duration(settings.DRAW_TIME)
|
||||
draw.timestamp -= 2 * duration
|
||||
draw.save()
|
||||
Work.objects.create(draw=draw)
|
||||
|
||||
@ -91,6 +95,7 @@ class DrawTest(TestCase):
|
||||
self.assertIsNone(draw.accepted)
|
||||
|
||||
draw.accepted = True
|
||||
draw.timestamp -= 2 * duration
|
||||
draw.save()
|
||||
Work.objects.create(draw=draw)
|
||||
|
||||
@ -110,3 +115,12 @@ class DrawTest(TestCase):
|
||||
Work.objects.create(draw=draw)
|
||||
|
||||
self.assertEquals(word, self.user.last_draw().word)
|
||||
|
||||
def test_draw_per_day(self):
|
||||
draw = Draw.objects.create(user=self.user,
|
||||
word=self.word,
|
||||
accepted=True)
|
||||
Work.objects.create(draw=draw)
|
||||
Word.objects.create()
|
||||
|
||||
self.assertEquals(self.word, self.user.draw_word())
|
||||
|
Loading…
Reference in New Issue
Block a user