|
|
@ -1,5 +1,4 @@ |
|
|
from rest_framework.response import Response |
|
|
from rest_framework.response import Response |
|
|
from rest_framework.decorators import api_view |
|
|
|
|
|
from django.utils import timezone |
|
|
from django.utils import timezone |
|
|
from rest_framework import status |
|
|
from rest_framework import status |
|
|
|
|
|
|
|
|
@ -52,53 +51,6 @@ def principal(request): |
|
|
return render(request, 'index.html', {'noticias': noticias}) |
|
|
return render(request, 'index.html', {'noticias': noticias}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['GET']) |
|
|
|
|
|
def proximo_evento(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.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: |
|
|
|
|
|
serializer = EventoSerializer(evento) |
|
|
|
|
|
return Response(serializer.data) |
|
|
|
|
|
else: |
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def ayuda(request): |
|
|
def ayuda(request): |
|
|
elementos_ayuda = Ayuda.objects.all().order_by('apartado') |
|
|
elementos_ayuda = Ayuda.objects.all().order_by('apartado') |
|
|
apartados = Ayuda.APARTADOS |
|
|
apartados = Ayuda.APARTADOS |
|
|
|