mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 06:51:08 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
@@ -15,8 +15,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from apps.rides.models import RideRanking, RidePairComparison, RankingSnapshot
|
||||
from apps.rides.services import RideRankingService
|
||||
# Import models inside methods to avoid Django initialization issues
|
||||
from .serializers_rankings import (
|
||||
RideRankingSerializer,
|
||||
RideRankingDetailSerializer,
|
||||
@@ -104,6 +103,8 @@ class RideRankingViewSet(ReadOnlyModelViewSet):
|
||||
|
||||
def get_queryset(self):
|
||||
"""Get rankings with optimized queries."""
|
||||
from apps.rides.models import RideRanking
|
||||
|
||||
queryset = RideRanking.objects.select_related(
|
||||
"ride", "ride__park", "ride__park__location", "ride__manufacturer"
|
||||
)
|
||||
@@ -141,6 +142,8 @@ class RideRankingViewSet(ReadOnlyModelViewSet):
|
||||
@action(detail=True, methods=["get"])
|
||||
def history(self, request, ride_slug=None):
|
||||
"""Get ranking history for a specific ride."""
|
||||
from apps.rides.models import RankingSnapshot
|
||||
|
||||
ranking = self.get_object()
|
||||
history = RankingSnapshot.objects.filter(ride=ranking.ride).order_by(
|
||||
"-snapshot_date"
|
||||
@@ -154,6 +157,8 @@ class RideRankingViewSet(ReadOnlyModelViewSet):
|
||||
@action(detail=False, methods=["get"])
|
||||
def statistics(self, request):
|
||||
"""Get overall ranking system statistics."""
|
||||
from apps.rides.models import RideRanking, RidePairComparison, RankingSnapshot
|
||||
|
||||
total_rankings = RideRanking.objects.count()
|
||||
total_comparisons = RidePairComparison.objects.count()
|
||||
|
||||
@@ -246,6 +251,8 @@ class RideRankingViewSet(ReadOnlyModelViewSet):
|
||||
@action(detail=True, methods=["get"])
|
||||
def comparisons(self, request, ride_slug=None):
|
||||
"""Get head-to-head comparisons for a specific ride."""
|
||||
from apps.rides.models import RidePairComparison
|
||||
|
||||
ranking = self.get_object()
|
||||
|
||||
comparisons = (
|
||||
@@ -326,6 +333,8 @@ class TriggerRankingCalculationView(APIView):
|
||||
{"error": "Admin access required"}, status=status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
|
||||
from apps.rides.services import RideRankingService
|
||||
|
||||
category = request.data.get("category")
|
||||
|
||||
service = RideRankingService()
|
||||
|
||||
Reference in New Issue
Block a user