|
|
@ -1,6 +1,7 @@ |
|
|
from rest_framework.response import Response |
|
|
from rest_framework.response import Response |
|
|
from rest_framework.decorators import api_view |
|
|
from rest_framework.decorators import api_view |
|
|
from django.utils import timezone |
|
|
from django.utils import timezone |
|
|
|
|
|
from rest_framework import status |
|
|
|
|
|
|
|
|
from django.shortcuts import render, get_object_or_404, redirect |
|
|
from django.shortcuts import render, get_object_or_404, redirect |
|
|
from django.contrib.auth.decorators import login_required, user_passes_test |
|
|
from django.contrib.auth.decorators import login_required, user_passes_test |
|
|
@ -211,9 +212,22 @@ def apuntar_lista_espera(request, evento_id): |
|
|
|
|
|
|
|
|
@api_view(['GET']) |
|
|
@api_view(['GET']) |
|
|
def proximo_evento(request): |
|
|
def proximo_evento(request): |
|
|
# Obtén el próximo evento que esté publicado y cuya fecha sea mayor a la fecha actual |
|
|
|
|
|
# evento = Evento.objects.filter(publicado=True, fecha__gte=timezone.now()).order_by('fecha').first() |
|
|
|
|
|
evento = Evento.objects.filter(fecha__gte=timezone.now()).order_by('fecha').first() |
|
|
|
|
|
|
|
|
# Obtiene y valida el parámetro `publicado` |
|
|
|
|
|
publicado_param = request.GET.get('publicado', 'true').lower() |
|
|
|
|
|
if publicado_param not in ['true', 'false', 'all']: |
|
|
|
|
|
return Response( |
|
|
|
|
|
{'detail': 'El parámetro "publicado" debe ser "true", "false" o "all".'}, |
|
|
|
|
|
status=status.HTTP_400_BAD_REQUEST |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Configura el filtro según el parámetro `publicado` |
|
|
|
|
|
if publicado_param == 'all': |
|
|
|
|
|
eventos = Evento.objects.filter(fecha__gte=timezone.now()).order_by('fecha') |
|
|
|
|
|
else: |
|
|
|
|
|
publicado = publicado_param == 'true' |
|
|
|
|
|
eventos = Evento.objects.filter(publicado=publicado, fecha__gte=timezone.now()).order_by('fecha') |
|
|
|
|
|
|
|
|
|
|
|
evento = eventos.first() |
|
|
|
|
|
|
|
|
if evento: |
|
|
if evento: |
|
|
serializer = EventoSerializer(evento) |
|
|
serializer = EventoSerializer(evento) |
|
|
@ -221,3 +235,24 @@ def proximo_evento(request): |
|
|
else: |
|
|
else: |
|
|
return Response({'detail': 'No hay eventos próximos.'}, status=404) |
|
|
return Response({'detail': 'No hay eventos próximos.'}, status=404) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['GET']) |
|
|
|
|
|
def todos_los_eventos(request): |
|
|
|
|
|
# Obtiene y valida el parámetro `publicado` |
|
|
|
|
|
publicado_param = request.GET.get('publicado', 'true').lower() |
|
|
|
|
|
if publicado_param not in ['true', 'false', 'all']: |
|
|
|
|
|
return Response( |
|
|
|
|
|
{'detail': 'El parámetro "publicado" debe ser "true", "false" o "all".'}, |
|
|
|
|
|
status=status.HTTP_400_BAD_REQUEST |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
# Configura el filtro según el parámetro `publicado` |
|
|
|
|
|
if publicado_param == 'all': |
|
|
|
|
|
eventos = Evento.objects.all().order_by('fecha') |
|
|
|
|
|
else: |
|
|
|
|
|
publicado = publicado_param == 'true' |
|
|
|
|
|
eventos = Evento.objects.filter(publicado=publicado).order_by('fecha') |
|
|
|
|
|
|
|
|
|
|
|
serializer = EventoSerializer(eventos, many=True) # `many=True` para serializar una lista de eventos |
|
|
|
|
|
return Response(serializer.data) |
|
|
|
|
|
|