Przeglądaj źródła

Update admin and add library update endpoint

Colin Powell 3 lat temu
rodzic
commit
37501f4f10
3 zmienionych plików z 40 dodań i 4 usunięć
  1. 16 3
      games/admin.py
  2. 5 0
      games/urls.py
  3. 19 1
      games/views.py

+ 16 - 3
games/admin.py

@@ -5,14 +5,27 @@ from games.models import Developer, Game, GameSystem, Genre, Publisher, GameColl
 
 class GameAdmin(admin.ModelAdmin):
     list_display = ("name", "game_system", "rating", "region")
-    list_filter = ("game_system", "undub", "english_patched", "hack")
+    list_filter = (
+        "undub",
+        "english_patched",
+        "hack",
+        "region",
+        "game_system",
+    )
+
 
 class GameInline(admin.TabularInline):
     model = Game
 
+
 class GameCollectionAdmin(admin.ModelAdmin):
-    filter_horizontal = ('games',)
-    raw_id_fields = ('game_system', 'developer', 'publisher', 'genre',)
+    filter_horizontal = ("games",)
+    raw_id_fields = (
+        "developer",
+        "publisher",
+        "genre",
+        "game_system",
+    )
 
 
 admin.site.register(GameCollection, GameCollectionAdmin)

+ 5 - 0
games/urls.py

@@ -15,6 +15,11 @@ urlpatterns = [
         views.LibraryGameList.as_view(),
         name="game_library_list",
     ),
+    path(
+        "library/update/",
+        views.trigger_rom_update,
+        name="game_library_update",
+    ),
     path(
         "publisher/",
         views.PublisherList.as_view(),

+ 19 - 1
games/views.py

@@ -1,11 +1,17 @@
+import json
 import logging
 
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
 from django.contrib.auth.mixins import LoginRequiredMixin
 from django.db.models import Avg, Count, F
+from django.http import HttpResponse
 from django.views.generic import DetailView, ListView
 from django.views.generic.list import MultipleObjectMixin
 
-from .models import Developer, Game, GameSystem, Genre, Publisher, GameCollection
+from games.tasks import update_roms
+
+from .models import Developer, Game, GameCollection, GameSystem, Genre, Publisher
 
 logger = logging.Logger(__name__)
 
@@ -150,3 +156,15 @@ class GameCollectionDetail(DetailView, LoginRequiredMixin):
             object_list=object_list, **kwargs
         )
         return context
+
+
+@login_required
+def trigger_rom_update(request):
+    full_scan = request.GET.get("full_scan")
+    if full_scan == "true":
+        full_scan = True
+    else:
+        full_scan = False
+    all_slugs = settings.GAME_SYSTEM_DEFAULTS.keys()
+    update_roms.delay(all_slugs, full_scan=full_scan)
+    return HttpResponse({"success": "true"}, mimetype="application/json")