2023-05-20 22:42:45 +02:00
|
|
|
from django.shortcuts import render
|
2023-05-21 18:50:15 +02:00
|
|
|
from django.views.generic.list import ListView
|
2023-05-21 19:21:17 +02:00
|
|
|
from django.views.generic.detail import DetailView
|
2023-05-22 20:52:18 +02:00
|
|
|
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
2023-05-23 23:55:18 +02:00
|
|
|
from django.contrib.auth.views import LoginView
|
2023-05-24 00:15:01 +02:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
2023-05-21 21:33:13 +02:00
|
|
|
from django.urls import reverse_lazy
|
2023-05-21 18:50:15 +02:00
|
|
|
from .models import Tarea
|
2023-05-20 22:42:45 +02:00
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
2023-05-23 23:55:18 +02:00
|
|
|
class Logueo(LoginView):
|
|
|
|
template_name = "base/login.html"
|
|
|
|
field = '__all__'
|
|
|
|
redirect_authenticated_user = True
|
|
|
|
|
|
|
|
def get_success_url(self):
|
|
|
|
return reverse_lazy('tareas')
|
|
|
|
|
|
|
|
|
2023-05-24 00:15:01 +02:00
|
|
|
class ListaPendientes(LoginRequiredMixin, ListView):
|
2023-05-21 18:50:15 +02:00
|
|
|
model = Tarea
|
|
|
|
context_object_name = 'tareas'
|
2023-05-21 19:21:17 +02:00
|
|
|
|
2023-05-24 00:36:13 +02:00
|
|
|
def get_context_data(self, **kwarg):
|
|
|
|
context = super().get_context_data(**kwarg)
|
|
|
|
context['tareas'] = context['tareas'].filter(usuario=self.request.user)
|
|
|
|
context['count'] = context['tareas'].filter(completo=False).count()
|
|
|
|
|
|
|
|
return context
|
|
|
|
|
2023-05-21 19:21:17 +02:00
|
|
|
|
2023-05-24 00:15:01 +02:00
|
|
|
class DetalleTarea(LoginRequiredMixin, DetailView):
|
2023-05-21 19:21:17 +02:00
|
|
|
model = Tarea
|
|
|
|
context_object_name = 'tarea'
|
|
|
|
template_name = 'base/tarea.html'
|
2023-05-21 21:33:13 +02:00
|
|
|
|
|
|
|
|
2023-05-24 00:15:01 +02:00
|
|
|
class CrearTarea(LoginRequiredMixin, CreateView):
|
2023-05-21 21:33:13 +02:00
|
|
|
model = Tarea
|
2023-05-24 00:36:13 +02:00
|
|
|
fields = ['titulo', 'descripcion', 'completo']
|
2023-05-21 21:33:13 +02:00
|
|
|
success_url = reverse_lazy('tareas')
|
2023-05-22 20:35:48 +02:00
|
|
|
|
2023-05-24 00:36:13 +02:00
|
|
|
def form_valid(self, form):
|
|
|
|
form.instance.usuario = self.request.user
|
|
|
|
|
|
|
|
return super(CrearTarea, self).form_valid(form)
|
|
|
|
|
2023-05-22 20:35:48 +02:00
|
|
|
|
2023-05-24 00:15:01 +02:00
|
|
|
class EditarTarea(LoginRequiredMixin, UpdateView):
|
2023-05-22 20:35:48 +02:00
|
|
|
model = Tarea
|
2023-05-24 00:36:13 +02:00
|
|
|
fields = ['titulo', 'descripcion', 'completo']
|
2023-05-22 20:35:48 +02:00
|
|
|
success_url = reverse_lazy('tareas')
|
2023-05-22 20:52:18 +02:00
|
|
|
|
|
|
|
|
2023-05-24 00:15:01 +02:00
|
|
|
class EliminarTarea(LoginRequiredMixin, DeleteView):
|
2023-05-22 20:52:18 +02:00
|
|
|
model = Tarea
|
|
|
|
context_object_name = 'tarea'
|
|
|
|
success_url = reverse_lazy('tareas')
|