|
|
|
@ -5,18 +5,20 @@ from django.views.generic import CreateView |
|
|
|
from django.contrib.auth.forms import UserCreationForm |
|
|
|
from django.urls import reverse_lazy |
|
|
|
|
|
|
|
|
|
|
|
from .models import Autor, Libro |
|
|
|
from .forms import AutorForm, LibroForm |
|
|
|
|
|
|
|
|
|
|
|
def principal(request): |
|
|
|
return render(request, 'gestion/index.html') |
|
|
|
|
|
|
|
|
|
|
|
# Vistas para los autores |
|
|
|
def lista_autores(request): |
|
|
|
autores = Autor.objects.all() |
|
|
|
return render(request, 'gestion/lista_autores.html', {'autores': autores}) |
|
|
|
|
|
|
|
|
|
|
|
def detalle_autor(request, autor_id): |
|
|
|
autor = get_object_or_404(Autor, pk=autor_id) |
|
|
|
|
|
|
|
@ -24,6 +26,7 @@ def detalle_autor(request, autor_id): |
|
|
|
|
|
|
|
return render(request, 'gestion/detalle_autor.html', {'autor': autor, 'libros': libros}) |
|
|
|
|
|
|
|
|
|
|
|
@login_required |
|
|
|
def nuevo_autor(request): |
|
|
|
if request.method == 'POST': |
|
|
|
@ -35,6 +38,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) |
|
|
|
@ -47,21 +51,25 @@ 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() |
|
|
|
return redirect('lista_autores') |
|
|
|
|
|
|
|
|
|
|
|
# Vistas para los libros |
|
|
|
def lista_libros(request): |
|
|
|
libros = Libro.objects.all() |
|
|
|
return render(request, 'gestion/lista_libros.html', {'libros': libros}) |
|
|
|
|
|
|
|
|
|
|
|
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': |
|
|
|
@ -73,6 +81,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) |
|
|
|
@ -85,6 +94,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) |
|
|
|
@ -95,4 +105,4 @@ def eliminar_libro(request, libro_id): |
|
|
|
class SignUpView(CreateView): |
|
|
|
form_class = UserCreationForm |
|
|
|
success_url = reverse_lazy("login") |
|
|
|
template_name = "registration/signup.html" |
|
|
|
template_name = "registration/signup.html" |