beesgospel/beesgospel/views.py

51 lines
1.3 KiB
Python

from datetime import date, timedelta
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import ListView, TemplateView
from .models import Agenda, Document, Membre
class HomeView(TemplateView):
template_name="index.html"
def get_context_data(self, **kwargs):
return {
**super().get_context_data(**kwargs),
"items": Agenda.objects.filter(
date_heure__date__gte=date.today(), prive=False,
).order_by("date_heure")[:2],
}
class AgendaView(ListView):
model = Agenda
template_name = "agenda.html"
def get_queryset(self):
qs = Agenda.objects.filter(
date_heure__gt=date.today() - timedelta(days=3),
).order_by("date_heure")
if not self.request.user.is_authenticated:
qs = qs.filter(prive=False)
return qs
class MediaView(ListView):
model = Document
template_name = "media.html"
def get_queryset(self):
qs = Document.objects.all().order_by("-quand")
if not self.request.user.is_authenticated:
qs = qs.filter(prive=False)
return qs
class EspaceMembresView(LoginRequiredMixin, TemplateView):
template_name = "membres/index.html"
class ListeMembresView(LoginRequiredMixin, ListView):
model = Membre
template_name = "membres/liste.html"