|
@@ -1,11 +1,12 @@
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
|
|
+from datetime import datetime
|
|
|
|
|
|
from celery import states
|
|
from celery import states
|
|
-from django.core.cache import cache
|
|
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
+from django.core.cache import cache
|
|
from django.db.models import Avg, Count, F
|
|
from django.db.models import Avg, Count, F
|
|
from django.http import HttpResponse
|
|
from django.http import HttpResponse
|
|
from django.views.generic import DetailView, ListView
|
|
from django.views.generic import DetailView, ListView
|
|
@@ -30,10 +31,16 @@ class RecentGameList(LoginRequiredMixin, ListView):
|
|
def get_context_data(self, **kwargs):
|
|
def get_context_data(self, **kwargs):
|
|
cached_game_id = cache.get("todays_game_id", None)
|
|
cached_game_id = cache.get("todays_game_id", None)
|
|
if not cached_game_id:
|
|
if not cached_game_id:
|
|
- todays_game = Game.objects.filter(rating__gte=0.7).order_by("?").first()
|
|
|
|
|
|
+ todays_game = (
|
|
|
|
+ Game.objects.filter(rating__gte=0.7, featured_on__isnull=True)
|
|
|
|
+ .order_by("?")
|
|
|
|
+ .first()
|
|
|
|
+ )
|
|
cache.set("todays_game_id", todays_game.id, settings.FEATURED_GAME_DURATION)
|
|
cache.set("todays_game_id", todays_game.id, settings.FEATURED_GAME_DURATION)
|
|
else:
|
|
else:
|
|
todays_game = Game.objects.get(id=cached_game_id)
|
|
todays_game = Game.objects.get(id=cached_game_id)
|
|
|
|
+ todays_game.featured_on = datetime.now().date
|
|
|
|
+ todays_game.save(update_fields=["featured_on"])
|
|
|
|
|
|
return super(RecentGameList, self).get_context_data(
|
|
return super(RecentGameList, self).get_context_data(
|
|
todays_game=todays_game,
|
|
todays_game=todays_game,
|