Fixed ExtentForLocation API issue
This commit is contained in:
21
rog/views.py
21
rog/views.py
@ -729,14 +729,29 @@ def ExtentForLocations(request):
|
||||
return JsonResponse({"error": "No event code associated with the user"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
try:
|
||||
locs = Location2025.objects.filter(group__contains=ec).aggregate(Extent('geom'), Union('geom'))
|
||||
# event_codeに基づいてイベントを検索し、そのイベントに関連するLocation2025を取得
|
||||
from rog.models import NewEvent2
|
||||
from django.db.models import Q
|
||||
|
||||
# event_codeでイベントを検索(event_nameに含まれる場合も考慮)
|
||||
events = NewEvent2.objects.filter(
|
||||
Q(event_code=ec) |
|
||||
Q(event_name__icontains=ec)
|
||||
)
|
||||
|
||||
if not events.exists():
|
||||
logger.warning(f"No events found for event_code: {ec}")
|
||||
return JsonResponse({"error": "No events found for the given event code"}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
# 見つかったイベントに関連するLocation2025を取得
|
||||
locs = Location2025.objects.filter(event__in=events).aggregate(Extent('location'), Union('location'))
|
||||
|
||||
if not locs['geom__extent']:
|
||||
if not locs['location__extent']:
|
||||
logger.info(f"No locations found for event_code: {ec}")
|
||||
return JsonResponse({"error": "No locations found for the given event code"}, status=status.HTTP_404_NOT_FOUND)
|
||||
|
||||
logger.info(f"Successfully retrieved extent for event_code: {ec}")
|
||||
return JsonResponse(locs['geom__extent'], safe=False)
|
||||
return JsonResponse(locs['location__extent'], safe=False)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in ExtentForLocations: {str(e)}", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user