From 79c0a14d76276012c8e26b2d04a08f14da79a79f Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Fri, 8 Nov 2024 09:45:11 +0000 Subject: [PATCH] =?UTF-8?q?P=C3=A1gina=20con=20noticias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JugarAlPadel/K8S/Makefile.local | 2 +- JugarAlPadel/gestion_reservas/entornoPruebas.sh | 2 +- JugarAlPadel/gestion_reservas/eventos/admin.py | 9 ++++++++- JugarAlPadel/gestion_reservas/eventos/models.py | 14 ++++++++++++++ JugarAlPadel/gestion_reservas/eventos/urls.py | 2 ++ JugarAlPadel/gestion_reservas/eventos/views.py | 9 ++++----- .../gestion_reservas/settings.py | 1 + .../gestion_reservas/gestion_reservas/urls.py | 3 +-- .../gestion_reservas/gestion_reservas/views.py | 13 ++++++++++++- .../gestion_reservas/templates/_branding.html | 2 +- .../gestion_reservas/templates/base.html | 13 ------------- .../templates/detalle_noticia.html | 14 ++++++++++++++ .../gestion_reservas/templates/index.html | 16 +++++++++++++--- 13 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 JugarAlPadel/gestion_reservas/templates/detalle_noticia.html diff --git a/JugarAlPadel/K8S/Makefile.local b/JugarAlPadel/K8S/Makefile.local index a20f70e..79ef9f8 100644 --- a/JugarAlPadel/K8S/Makefile.local +++ b/JugarAlPadel/K8S/Makefile.local @@ -2,7 +2,7 @@ export ARQUITECTURA := $(shell lscpu |grep itectur | tr -d ' '| cut -f2 -d':') export REGISTRY=localhost:30500 #export REGISTRY=registry.reymota.es -export IMG_VERSION = 1.0 +export IMG_VERSION = 1.19 export IMG_NGINX_VERSION = 2.4 # limpia todo diff --git a/JugarAlPadel/gestion_reservas/entornoPruebas.sh b/JugarAlPadel/gestion_reservas/entornoPruebas.sh index 61cd4df..a75688f 100644 --- a/JugarAlPadel/gestion_reservas/entornoPruebas.sh +++ b/JugarAlPadel/gestion_reservas/entornoPruebas.sh @@ -1,6 +1,6 @@ export CSRF_TRUSTED_ORIGINS="http://localhost" export DEBUG="True" export SECRET_KEY="hola" -export DJANGO_ALLOWED_HOSTS="localhost" +export DJANGO_ALLOWED_HOSTS="vmcluster localhost" diff --git a/JugarAlPadel/gestion_reservas/eventos/admin.py b/JugarAlPadel/gestion_reservas/eventos/admin.py index d9523ee..5ba2434 100644 --- a/JugarAlPadel/gestion_reservas/eventos/admin.py +++ b/JugarAlPadel/gestion_reservas/eventos/admin.py @@ -1,5 +1,12 @@ from django.contrib import admin -from .models import Evento, Reserva, ListaEspera +from .models import Evento, Reserva, ListaEspera, Noticia + + +class NoticiaAdmin(admin.ModelAdmin): + list_display = ['titulo', 'fecha_publicacion', 'autor'] + + +admin.site.register(Noticia, NoticiaAdmin) class EventoAdmin(admin.ModelAdmin): diff --git a/JugarAlPadel/gestion_reservas/eventos/models.py b/JugarAlPadel/gestion_reservas/eventos/models.py index ab45278..a4d80a1 100644 --- a/JugarAlPadel/gestion_reservas/eventos/models.py +++ b/JugarAlPadel/gestion_reservas/eventos/models.py @@ -36,3 +36,17 @@ class ListaEspera(models.Model): def __str__(self): return f'{self.usuario.nombre} en lista de espera para {self.evento.nombre}. Solicitada plaza el: {self.fecha_apuntado}' + + +class Noticia(models.Model): + titulo = models.CharField(max_length=200) + contenido = models.TextField() + fecha_publicacion = models.DateTimeField(auto_now_add=True) + autor = models.ForeignKey(ReyMotaUser, on_delete=models.SET_NULL, null=True) + publicado = models.BooleanField(default=False) + + class Meta: + ordering = ['-fecha_publicacion'] # Ordena por fecha de publicación, de la más reciente a la más antigua + + def __str__(self): + return self.titulo diff --git a/JugarAlPadel/gestion_reservas/eventos/urls.py b/JugarAlPadel/gestion_reservas/eventos/urls.py index 0d6fa22..47686eb 100644 --- a/JugarAlPadel/gestion_reservas/eventos/urls.py +++ b/JugarAlPadel/gestion_reservas/eventos/urls.py @@ -11,6 +11,8 @@ urlpatterns = [ path('eventos/crear/', views.crear_evento, name='crear_evento'), # URL para crear un evento path('eventos/editar/', views.editar_evento, name='editar_evento'), # URL para crear un evento + path('noticias//', views.detalle_noticia, name='detalle_noticia'), + path('publicar//', views.publicar_evento, name='publicar_evento'), path('reservar//', diff --git a/JugarAlPadel/gestion_reservas/eventos/views.py b/JugarAlPadel/gestion_reservas/eventos/views.py index 6195300..4ffcb9e 100644 --- a/JugarAlPadel/gestion_reservas/eventos/views.py +++ b/JugarAlPadel/gestion_reservas/eventos/views.py @@ -5,7 +5,7 @@ from django.core.mail import EmailMultiAlternatives from django.conf import settings from django.template.loader import render_to_string -from .models import Evento, Reserva, ListaEspera +from .models import Evento, Reserva, ListaEspera, Noticia from .forms import ListaEsperaForm, EventoForm @@ -106,10 +106,9 @@ def lista_eventos(request): return render(request, 'eventos/lista_eventos.html', {'eventos_con_reserva': eventos_con_reserva}) -def principal(request): - eventos = Evento.objects.all() - - return render(request, 'eventos/lista_eventos.html', {'eventos': eventos}) +def detalle_noticia(request, noticia_id): + noticia = get_object_or_404(Noticia, id=noticia_id, publicado=True) + return render(request, 'detalle_noticia.html', {'noticia': noticia}) def ayuda(request): diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py b/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py index d5eba7d..a84528f 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/settings.py @@ -28,6 +28,7 @@ DEBUG = os.environ["DEBUG"] == 'True' ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ") +print("ALLOWD_HOSTS: ", ALLOWED_HOSTS) # Application definition diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py b/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py index b4bdd22..c616eb1 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/urls.py @@ -31,8 +31,7 @@ urlpatterns = [ path("accounts/", include("accounts.urls")), # new path("accounts/", include("django.contrib.auth.urls")), - path("", TemplateView.as_view(template_name="index.html"), - name="principal"), # new + path('', views.principal, name='principal'), path('entorno/', views.ver_variables_entorno, name='ver_variables_entorno'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/JugarAlPadel/gestion_reservas/gestion_reservas/views.py b/JugarAlPadel/gestion_reservas/gestion_reservas/views.py index 621798e..e51be5c 100644 --- a/JugarAlPadel/gestion_reservas/gestion_reservas/views.py +++ b/JugarAlPadel/gestion_reservas/gestion_reservas/views.py @@ -1,9 +1,10 @@ import os from django.conf import settings from django.contrib.auth.decorators import user_passes_test -from django.shortcuts import render +from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseForbidden +from eventos.models import Noticia @user_passes_test(lambda u: u.is_staff) def ver_variables_entorno(request): @@ -29,3 +30,13 @@ def ver_variables_entorno(request): } 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}) diff --git a/JugarAlPadel/gestion_reservas/templates/_branding.html b/JugarAlPadel/gestion_reservas/templates/_branding.html index 47d77c4..382697c 100644 --- a/JugarAlPadel/gestion_reservas/templates/_branding.html +++ b/JugarAlPadel/gestion_reservas/templates/_branding.html @@ -3,7 +3,7 @@ {% load filtros_de_entorno %}
-