|
@@ -1,6 +1,7 @@
|
|
import json
|
|
import json
|
|
import logging
|
|
import logging
|
|
|
|
|
|
|
|
+from celery import states
|
|
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
|
|
@@ -8,6 +9,7 @@ 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
|
|
from django.views.generic.list import MultipleObjectMixin
|
|
from django.views.generic.list import MultipleObjectMixin
|
|
|
|
+from django_celery_results.models import TaskResult
|
|
|
|
|
|
from games.tasks import update_roms
|
|
from games.tasks import update_roms
|
|
|
|
|
|
@@ -16,6 +18,9 @@ from .models import Developer, Game, GameCollection, GameSystem, Genre, Publishe
|
|
logger = logging.Logger(__name__)
|
|
logger = logging.Logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
+IN_PROGRESS_STATES = [states.PENDING, states.STARTED, states.RETRY]
|
|
|
|
+
|
|
|
|
+
|
|
class RecentGameList(LoginRequiredMixin, ListView):
|
|
class RecentGameList(LoginRequiredMixin, ListView):
|
|
model = Game
|
|
model = Game
|
|
paginate_by = 20
|
|
paginate_by = 20
|
|
@@ -181,3 +186,22 @@ def trigger_rom_update(request):
|
|
status=200,
|
|
status=200,
|
|
content_type="application/json",
|
|
content_type="application/json",
|
|
)
|
|
)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@login_required
|
|
|
|
+def library_update_status(request):
|
|
|
|
+ update_task = TaskResult.objects.filter(
|
|
|
|
+ task_name="games.tasks.update_roms",
|
|
|
|
+ status__in=IN_PROGRESS_STATES,
|
|
|
|
+ ).first()
|
|
|
|
+
|
|
|
|
+ if not update_task:
|
|
|
|
+ state = states.SUCCESS
|
|
|
|
+ else:
|
|
|
|
+ state = update_task.status
|
|
|
|
+
|
|
|
|
+ return HttpResponse(
|
|
|
|
+ json.dumps({"state": state}),
|
|
|
|
+ status=200,
|
|
|
|
+ content_type="application/json",
|
|
|
|
+ )
|