Browse Source

Páginas protegidas por login

politica
Celestino Rey 1 year ago
parent
commit
0a5f53fe4b
20 changed files with 182 additions and 64 deletions
  1. BIN
      Libros/biblioteca/autores/220px-Yuval_Noah_Harari_cropped.jpg
  2. BIN
      Libros/biblioteca/autores/220px-Yuval_Noah_Harari_cropped_LijFJPx.jpg
  3. BIN
      Libros/biblioteca/autores/daniel_Tk9mZbV.jpg
  4. +4
    -0
      Libros/biblioteca/biblioteca/settings.py
  5. +4
    -0
      Libros/biblioteca/biblioteca/urls.py
  6. BIN
      Libros/biblioteca/db.sqlite3
  7. +15
    -0
      Libros/biblioteca/gestion/forms.py
  8. +1
    -0
      Libros/biblioteca/gestion/models.py
  9. +64
    -14
      Libros/biblioteca/gestion/templates/gestion/detalle_autor.html
  10. +34
    -18
      Libros/biblioteca/gestion/templates/gestion/detalle_libro.html
  11. +18
    -15
      Libros/biblioteca/gestion/templates/gestion/form_autor.html
  12. +16
    -15
      Libros/biblioteca/gestion/templates/gestion/form_libro.html
  13. +1
    -1
      Libros/biblioteca/gestion/templates/gestion/lista_autores.html
  14. +14
    -0
      Libros/biblioteca/gestion/templates/registration/login.html
  15. +11
    -1
      Libros/biblioteca/gestion/views.py
  16. BIN
      Libros/biblioteca/libros/21_lecciones_para_el_siglo_XXI_-_Yuval_Noah_Harari_234.epub
  17. BIN
      Libros/biblioteca/libros/Palacio_de_la_Luna_El_-_Auster_Paul_99.epub
  18. BIN
      Libros/biblioteca/portadas/invisible.jpeg
  19. BIN
      Libros/biblioteca/portadas/lecciones.jpeg
  20. BIN
      Libros/biblioteca/portadas/palacio.jpeg

BIN
Libros/biblioteca/autores/220px-Yuval_Noah_Harari_cropped.jpg View File

Before After
Width: 220  |  Height: 259  |  Size: 13 KiB

BIN
Libros/biblioteca/autores/220px-Yuval_Noah_Harari_cropped_LijFJPx.jpg View File

Before After
Width: 220  |  Height: 259  |  Size: 13 KiB

BIN
Libros/biblioteca/autores/daniel_Tk9mZbV.jpg View File

Before After
Width: 959  |  Height: 1280  |  Size: 65 KiB

+ 4
- 0
Libros/biblioteca/biblioteca/settings.py View File

@ -122,3 +122,7 @@ STATIC_URL = 'static/'
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
LOGIN_URL = '/accounts/login/'
LOGIN_REDIRECT_URL = '/gestion/'
LOGOUT_REDIRECT_URL = '/accounts/login/'

+ 4
- 0
Libros/biblioteca/biblioteca/urls.py View File

@ -18,10 +18,14 @@ from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
urlpatterns = [
path('obreros/', admin.site.urls),
path('gestion/', include('gestion.urls')),
path('accounts/login/', auth_views.LoginView.as_view(), name='login'),
path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'),
]


BIN
Libros/biblioteca/db.sqlite3 View File


+ 15
- 0
Libros/biblioteca/gestion/forms.py View File

@ -6,7 +6,22 @@ class AutorForm(forms.ModelForm):
model = Autor
fields = ['nombre', 'biografia', 'foto']
nombre = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
biografia = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
# foto = forms.FileField(widget=forms.TextInput(attrs={'class': 'form-control', 'type': 'file'}))
class LibroForm(forms.ModelForm):
class Meta:
model = Libro
fields = ['titulo', 'autor', 'fecha_publicacion', 'descripcion', 'archivo', 'portada']
titulo = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
# fecha_publicacion = forms.DateField(widget=forms.TextInput(attrs={'class': 'form-control'}))
descripcion = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control'}))
# archivo = forms.FileField(widget=forms.TextInput(attrs={'class': 'form-control', 'type': 'file'}))
# portada = forms.FileField(widget=forms.TextInput(attrs={'class': 'form-control', 'type': 'file'}))
autor = forms.ModelChoiceField(
queryset=Autor.objects.all(),
widget=forms.Select(attrs={'class': 'form-control'}))

+ 1
- 0
Libros/biblioteca/gestion/models.py View File

@ -1,4 +1,5 @@
from django.db import models
import datetime
from django.core.validators import MaxValueValidator, MinValueValidator


+ 64
- 14
Libros/biblioteca/gestion/templates/gestion/detalle_autor.html View File

@ -1,14 +1,64 @@
<!DOCTYPE html>
<html>
<head>
<title>Detalle del Autor</title>
</head>
<body>
<h1>{{ autor.nombre }}</h1>
<p>{{ autor.biografia }}</p>
{% if autor.foto %}
<img src="{{ autor.foto.url }}" alt="Foto del autor" width="200">
{% endif %}
<a href="{% url 'lista_autores' %}">Volver a la lista de autores</a>
</body>
</html>
{% extends 'base.html' %}
{% block content %}
<div class="container-xl">
<div class="app-card app-card-notification shadow-sm mb-4">
<div class="app-card-header px-4 py-3">
<div class="row g-3 align-items-center">
<div class="col-12 col-lg-auto text-center text-lg-start">
{% if autor.foto %}
<p><img src="{{ autor.foto.url }}" alt="{{ autor.nombre}}" style="width:200px;height:200px;"></p>
{% else %}
<p>No hay imágen disponible</p>
{% endif %}
</div>
<div class="col-12 col-lg-auto text-center text-lg-start">
<h4>{{ autor.nombre }}</h4>
<ul class="notification-meta list-inline mb-0">
<li class="list-inline-item">{{ autor.nombre }}</li>
</ul>
</div>
</div>
</div>
<div class="app-card-body p-4">
{% if libros %}
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th class="cell">Título</th>
<th class="cell">Portada</th>
</tr>
</thead>
<tbody>
{% for libro in libros %}
<tr>
<td class="cell"><a href="{% url 'detalle_libro' libro.id %}">{{ libro.titulo }}</a></td>
{% if libro.portada %}
<td class="cell"><img src="{{ libro.portada.url }}" alt="Portada del libro" width="200"></td>
{% else %}
<p>Sin imagen</p>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No se han encontrado libros para este autor</p>
{% endif %}
</div>
</div>
<div class="row g-3 mb-4 align-items-center justify-content-between">
<div class="col-auto">
<a class="btn app-btn-secondary" href="{% url 'lista_libros' %}">Volver al inicio</a>
</div>
<div class="col-auto">
<a class="btn app-btn-primary" href="{% url 'nuevo_libro' %}">Añadir libro</a> <!-- Faltaría poner el id del autor-->
</div>
</div>
</div>
{% endblock %}

+ 34
- 18
Libros/biblioteca/gestion/templates/gestion/detalle_libro.html View File

@ -1,18 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<title>Detalle del Libro</title>
</head>
<body>
<h1>{{ libro.titulo }}</h1>
<p>{{ libro.descripcion }}</p>
<p><strong>Autor:</strong> {{ libro.autor.nombre }}</p>
<p><strong>Fecha de Publicación:</strong> {{ libro.fecha_publicacion }}</p>
{% if libro.portada %}
<img src="{{ libro.portada.url }}" alt="Portada del libro" width="200">
{% endif %}
{% if libro.archivo %}
<p><a href="{{ libro.archivo.url }}">Descargar</a></p>
{% endif %} <a href="{% url 'lista_libros' %}">Volver a la lista de libros</a>
</body>
</html>
{% extends 'base.html' %}
{% block content %}
<div class="container-xl">
<div class="app-card app-card-notification shadow-sm mb-4">
<div class="app-card-header px-4 py-3">
<div class="row g-3 align-items-center">
<div class="col-12 col-lg-auto text-center text-lg-start">
{% if libro.portada %}
<p><img src="{{ libro.portada.url }}" alt="{{ libro.titulo }}" style="width:200px;height:200px;"></p>
{% else %}
<p>No hay imágen disponible</p>
{% endif %}
{% if libro.archivo %}
<p><a href="{{ libro.archivo.url }}">Descargar</a></p>
{% endif %}
</div><!--//col-->
<div class="col-12 col-lg-auto text-center text-lg-start">
<h4 class="notification-title mb-1">{{ libro.titulo }}</h4>
<ul class="notification-meta list-inline mb-0">
<li class="list-inline-item">{{ libro.autor.nombre }}</li>
<li class="list-inline-item">|</li>
<li class="list-inline-item">{{ libro.fecha_publicacion }}</li>
<li class="list-inline-item">|</li>
<li class="list-inline-item"><a href="{% url 'detalle_autor' libro.autor_id %}">{{ libro.autor.nombre }}</a></li>
</ul>
</div><!--//col-->
</tr>
</div><!--//row-->
</div><!--//app-card-header-->
</div><!--//app-card-->
{% endblock %}

+ 18
- 15
Libros/biblioteca/gestion/templates/gestion/form_autor.html View File

@ -1,15 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<title>Formulario de Autor</title>
</head>
<body>
<h1>{% if form.instance.pk %}Editar Autor{% else %}Nuevo Autor{% endif %}</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Guardar</button>
</form>
<a href="{% url 'lista_autores' %}">Cancelar</a>
</body>
</html>
{% extends 'base.html' %}
{% block content %}
<div class="column is-4 is-offset-4">
<h3>{% if form.instance.pk %}Editar Autor{% else %}Nuevo Autor{% endif %}</h3>
<div class="box">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<div class="text mb-3">
<button type="submit" class="btn app-btn-primary w-100 theme-btn mx-auto">Guardar</button>
</div>
</form>
</div>
</div>
{% endblock %}

+ 16
- 15
Libros/biblioteca/gestion/templates/gestion/form_libro.html View File

@ -1,15 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Formulario de Libro</title>
</head>
<body>
<h1>{% if form.instance.pk %}Editar Libro{% else %}Nuevo Libro{% endif %}</h1>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Guardar</button>
</form>
<a href="{% url 'lista_libros' %}">Cancelar</a>
</body>
</html>
{% extends 'base.html' %}
{% block content %}
<div class="column is-4 is-offset-4">
<h3>{% if form.instance.pk %}Editar Libro{% else %}Nuevo Libro{% endif %}</h3>
<div class="box">
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<div class="text mb-3">
<button type="submit" class="btn app-btn-primary w-100 theme-btn mx-auto">Guardar</button>
</div>
</form>
</div>
</div>
{% endblock %}

+ 1
- 1
Libros/biblioteca/gestion/templates/gestion/lista_autores.html View File

@ -25,7 +25,7 @@
<div class="app-card-body p-3 has-card-actions">
{% if autor.foto %}
<img src="{{ autor.foto.url }}" alt="Foto del autor" width="200">
<img src="{{ autor.foto.url }}" alt="Foto del autor" style="width:200px;height:200px;">
{% else %}
Sin imágen
{% endif %}


+ 14
- 0
Libros/biblioteca/gestion/templates/registration/login.html View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Iniciar Sesión</title>
</head>
<body>
<h2>Iniciar Sesión</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Ingresar</button>
</form>
</body>
</html>

+ 11
- 1
Libros/biblioteca/gestion/views.py View File

@ -1,4 +1,5 @@
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from .models import Autor, Libro
from .forms import AutorForm, LibroForm
@ -12,8 +13,12 @@ def lista_autores(request):
def detalle_autor(request, autor_id):
autor = get_object_or_404(Autor, pk=autor_id)
return render(request, 'gestion/detalle_autor.html', {'autor': autor})
libros = Libro.objects.filter(autor=autor_id)
return render(request, 'gestion/detalle_autor.html', {'autor': autor, 'libros': libros})
@login_required
def nuevo_autor(request):
if request.method == 'POST':
form = AutorForm(request.POST, request.FILES)
@ -24,6 +29,7 @@ def nuevo_autor(request):
form = AutorForm()
return render(request, 'gestion/form_autor.html', {'form': form})
@login_required
def editar_autor(request, autor_id):
autor = get_object_or_404(Autor, pk=autor_id)
if request.method == 'POST':
@ -35,6 +41,7 @@ def editar_autor(request, autor_id):
form = AutorForm(instance=autor)
return render(request, 'gestion/form_autor.html', {'form': form})
@login_required
def eliminar_autor(request, autor_id):
autor = get_object_or_404(Autor, pk=autor_id)
autor.delete()
@ -49,6 +56,7 @@ def detalle_libro(request, libro_id):
libro = get_object_or_404(Libro, pk=libro_id)
return render(request, 'gestion/detalle_libro.html', {'libro': libro})
@login_required
def nuevo_libro(request):
if request.method == 'POST':
form = LibroForm(request.POST, request.FILES)
@ -59,6 +67,7 @@ def nuevo_libro(request):
form = LibroForm()
return render(request, 'gestion/form_libro.html', {'form': form})
@login_required
def editar_libro(request, libro_id):
libro = get_object_or_404(Libro, pk=libro_id)
if request.method == 'POST':
@ -70,6 +79,7 @@ def editar_libro(request, libro_id):
form = LibroForm(instance=libro)
return render(request, 'gestion/form_libro.html', {'form': form})
@login_required
def eliminar_libro(request, libro_id):
libro = get_object_or_404(Libro, pk=libro_id)
libro.delete()


BIN
Libros/biblioteca/libros/21_lecciones_para_el_siglo_XXI_-_Yuval_Noah_Harari_234.epub View File


BIN
Libros/biblioteca/libros/Palacio_de_la_Luna_El_-_Auster_Paul_99.epub View File


BIN
Libros/biblioteca/portadas/invisible.jpeg View File

Before After
Width: 250  |  Height: 394  |  Size: 16 KiB

BIN
Libros/biblioteca/portadas/lecciones.jpeg View File

Before After
Width: 488  |  Height: 751  |  Size: 32 KiB

BIN
Libros/biblioteca/portadas/palacio.jpeg View File

Before After
Width: 337  |  Height: 500  |  Size: 36 KiB

Loading…
Cancel
Save