# Imports
|
|
|
|
from datetime import date
|
|
|
|
from django.conf import settings
|
|
from django.contrib.auth.decorators import user_passes_test
|
|
from django.http import HttpResponseForbidden
|
|
from django.shortcuts import render, get_object_or_404
|
|
from django.utils import timezone
|
|
|
|
from eventos.models import Noticia, Evento
|
|
from .models import Ayuda
|
|
|
|
from rest_framework import status
|
|
from rest_framework.decorators import api_view
|
|
from rest_framework.response import Response
|
|
|
|
from .serializers import AyudaSerializer
|
|
|
|
import markdown # Importa la biblioteca de markdown
|
|
|
|
import os
|
|
|
|
|
|
@user_passes_test(lambda u: u.is_staff)
|
|
def ver_variables_entorno(request):
|
|
if not settings.DEBUG:
|
|
return HttpResponseForbidden("Acceso prohibido")
|
|
|
|
# Variables a excluir por motivos de seguridad
|
|
variables_excluidas = {'SECRET_KEY', 'DATABASES', 'EMAIL_HOST_PASSWORD', 'API_KEY'}
|
|
|
|
# Obtiene todas las variables de entorno
|
|
entorno = {key: os.getenv(key) for key in os.environ.keys() if key not in variables_excluidas}
|
|
|
|
# Obtiene todas las variables de settings excluyendo las confidenciales
|
|
configuracion = {
|
|
key: getattr(settings, key) for key in dir(settings)
|
|
if key.isupper() and key not in variables_excluidas
|
|
}
|
|
|
|
# Combina ambas en un solo diccionario
|
|
contexto = {
|
|
'entorno': entorno,
|
|
'configuracion': configuracion
|
|
}
|
|
|
|
return render(request, 'ver_entorno.html', contexto)
|
|
|
|
|
|
def principal(request):
|
|
# Filtra solo las noticias publicadas
|
|
noticias = Noticia.objects.filter(publicado=True)
|
|
|
|
for noticia in noticias:
|
|
print("Principal en gestion_reservas: ", noticia.titulo)
|
|
|
|
return render(request, 'index.html', {'noticias': noticias})
|
|
|
|
|
|
def ayuda(request):
|
|
elementos_ayuda = Ayuda.objects.all().order_by('apartado')
|
|
apartados = Ayuda.APARTADOS
|
|
|
|
# Convierte la descripción de cada item a HTML usando Markdown
|
|
for item in elementos_ayuda:
|
|
item.descripcion = markdown.markdown(item.descripcion)
|
|
|
|
return render(request, 'ayuda.html', {'elementos': elementos_ayuda, 'apartados': apartados})
|
|
|
|
|
|
def politica_privacidad(request):
|
|
return render(request, 'politica_privacidad.html', {'fecha_actual': date.today()})
|
|
|
|
|
|
def acerca_de(request):
|
|
context = {
|
|
"app_name": settings.APP_NAME,
|
|
"app_version": settings.APP_VERSION,
|
|
"img_version": settings.IMG_VERSION
|
|
}
|
|
return render(request, "acerca_de.html", context)
|
|
|
|
|
|
#
|
|
# API
|
|
#
|
|
|
|
@api_view(['GET'])
|
|
def api_lista_ayuda(request):
|
|
"""Devuelve la lista de toda la ayuda."""
|
|
ayuda = Ayuda.objects.all()
|
|
serializer = AyudaSerializer(ayuda, many=True)
|
|
return Response(serializer.data)
|