From 33b8c24809eed63156c866c48c5a86e61257dbca Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Mon, 12 May 2025 12:19:07 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1ado=20estad=C3=ADsticas=20de=20usuarios?= =?UTF-8?q?=20y=20b=C3=BAsqueda=20por=20email=20y=20nombre=20en=20lista=20?= =?UTF-8?q?de=20usuarios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JugarAlPadel/K8S/Makefile | 2 +- JugarAlPadel/K8S/env-prod-configmap.yaml | 1 + JugarAlPadel/gestion_reservas/eventos/urls.py | 3 +++ .../gestion_reservas/eventos/views.py | 11 ++++++++++ .../gestion_reservas/settings.py | 4 ++-- .../gestion_reservas/views.py | 12 ++++++---- .../gestion_reservas/reymotausers/admin.py | 2 +- .../gestion_reservas/templates/_branding.html | 2 +- .../gestion_reservas/templates/base.html | 11 ++++++++++ .../eventos/estadisticas_usuarios.html | 22 +++++++++++++++++++ 10 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 JugarAlPadel/gestion_reservas/templates/eventos/estadisticas_usuarios.html diff --git a/JugarAlPadel/K8S/Makefile b/JugarAlPadel/K8S/Makefile index ff7686f..c389f2f 100644 --- a/JugarAlPadel/K8S/Makefile +++ b/JugarAlPadel/K8S/Makefile @@ -1,7 +1,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') export REGISTRY=registry.reymota.es -export IMG_VERSION = 0.70.24 +export IMG_VERSION = 0.70.26 export IMG_NGINX_VERSION = 2.3 # limpia todo diff --git a/JugarAlPadel/K8S/env-prod-configmap.yaml b/JugarAlPadel/K8S/env-prod-configmap.yaml index 124cd36..3675e71 100644 --- a/JugarAlPadel/K8S/env-prod-configmap.yaml +++ b/JugarAlPadel/K8S/env-prod-configmap.yaml @@ -2,6 +2,7 @@ apiVersion: v1 data: DEBUG: "False" APP_VERSION: 13.0.1 + DATABASE: postgres kind: ConfigMap metadata: labels: diff --git a/JugarAlPadel/gestion_reservas/eventos/urls.py b/JugarAlPadel/gestion_reservas/eventos/urls.py index e4a4ad6..fe4f57a 100644 --- a/JugarAlPadel/gestion_reservas/eventos/urls.py +++ b/JugarAlPadel/gestion_reservas/eventos/urls.py @@ -36,4 +36,7 @@ urlpatterns = [ path('api/noticias/', api_lista_noticias, name='api_lista_noticias'), path('api/noticias//', api_detalle_noticia, name='api_detalle_noticia'), + + path("estadisticas/usuarios/", views.estadisticas_por_usuario, name="estadisticas_por_usuario"), + ] diff --git a/JugarAlPadel/gestion_reservas/eventos/views.py b/JugarAlPadel/gestion_reservas/eventos/views.py index c97ffb6..bd0e8ce 100644 --- a/JugarAlPadel/gestion_reservas/eventos/views.py +++ b/JugarAlPadel/gestion_reservas/eventos/views.py @@ -21,6 +21,11 @@ from .serializers import EventoSerializer, ReservaSerializer, ListaEsperaSeriali from .models import Evento, Reserva, ListaEspera, Noticia from .forms import ListaEsperaForm, EventoForm, MensajeCorreoForm +from django.contrib.auth import get_user_model +from django.db.models import Count + +User = get_user_model() + logger = logging.getLogger(__name__) @@ -357,3 +362,9 @@ def enviar_correo_inscritos(request, evento_id): return render(request, 'eventos/enviar_correo_inscritos.html', {'form': form, 'evento': evento}) + +@user_passes_test(es_admin) +def estadisticas_por_usuario(request): + usuarios = User.objects.annotate(num_eventos=Count("reserva__evento")).order_by("-num_eventos") + return render(request, "eventos/estadisticas_usuarios.html", {"usuarios": usuarios}) + diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py b/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py index d69bd40..d324580 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py @@ -32,8 +32,8 @@ SECRET_KEY = 'hey' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.environ["DEBUG"] == 'True' -ALLOWED_HOSTS = [".ocp-cluster.reymota.lab", "jugaralpadel.rancher.reymota.lab", "jugaralpadel.es"] -CSRF_TRUSTED_ORIGINS = ["https://*.ocp-cluster.reymota.lab", "http://jugaralpadel.rancher.reymota.lab", "https://jugaralpadel.rancher.reymota.lab", "https://jugaralpadel.es"] +ALLOWED_HOSTS = [".ocp-cluster.reymota.lab", "jugaralpadel.rancher.reymota.lab", "jugaralpadel.es", ".reymota.es"] +CSRF_TRUSTED_ORIGINS = ["https://*.ocp-cluster.reymota.lab", "http://jugaralpadel.rancher.reymota.lab", "https://jugaralpadel.rancher.reymota.lab", "https://jugaralpadel.es", "https://*.reymota.es"] # Application definition diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/views.py b/JugarAlPadel/gestion_reservas/gestion_reservas/views.py index 61f67ae..07741f7 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/views.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/views.py @@ -1,14 +1,18 @@ -from rest_framework.response import Response -from django.utils import timezone -from rest_framework import status +# Imports import os + from django.conf import settings from django.contrib.auth.decorators import user_passes_test -from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseForbidden +from django.shortcuts import render, get_object_or_404 +from django.utils import timezone + +from datetime import date +from rest_framework import status from rest_framework.decorators import api_view +from rest_framework.response import Response from eventos.models import Noticia, Evento from .serializers import AyudaSerializer diff --git a/JugarAlPadel/gestion_reservas/reymotausers/admin.py b/JugarAlPadel/gestion_reservas/reymotausers/admin.py index 98081f8..b1f7015 100644 --- a/JugarAlPadel/gestion_reservas/reymotausers/admin.py +++ b/JugarAlPadel/gestion_reservas/reymotausers/admin.py @@ -56,7 +56,7 @@ class ReyMotaUserAdmin(UserAdmin): ("Personal", {"fields": ("nombre",)}), ("Varios", {"fields": ("foto",)}), ) - search_fields = ("email",) + search_fields = ("email", "nombre",) ordering = ("email",) actions = [enviar_email_prueba] # Añadir la acción a la lista de acciones diff --git a/JugarAlPadel/gestion_reservas/templates/_branding.html b/JugarAlPadel/gestion_reservas/templates/_branding.html index 8e17661..96f56b0 100644 --- a/JugarAlPadel/gestion_reservas/templates/_branding.html +++ b/JugarAlPadel/gestion_reservas/templates/_branding.html @@ -3,6 +3,6 @@ {% load filtros_de_entorno %} diff --git a/JugarAlPadel/gestion_reservas/templates/base.html b/JugarAlPadel/gestion_reservas/templates/base.html index 403368c..bca0323 100644 --- a/JugarAlPadel/gestion_reservas/templates/base.html +++ b/JugarAlPadel/gestion_reservas/templates/base.html @@ -122,6 +122,17 @@ Crear un nuevo evento + + + + + + + + + Estadísticas por usuario + + {% endif %} diff --git a/JugarAlPadel/gestion_reservas/templates/eventos/estadisticas_usuarios.html b/JugarAlPadel/gestion_reservas/templates/eventos/estadisticas_usuarios.html new file mode 100644 index 0000000..aebf936 --- /dev/null +++ b/JugarAlPadel/gestion_reservas/templates/eventos/estadisticas_usuarios.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + +{% block content %} +

Estadísticas de Inscripciones por Usuario

+ + + + + + + + + + {% for usuario in usuarios %} + + + + + {% endfor %} + +
UsuarioEventos inscritos
{{ usuario.get_full_name|default:usuario.nombre }}{{ usuario.num_eventos }}
+{% endblock %}