Merge branch 'kerl/home_template_view' into 'master'

Rewrite home as a class-based view

See merge request klub-dev-ens/gestioCOF!369
This commit is contained in:
Ludovic Stephan 2019-10-06 13:47:07 +02:00
commit 51e8058f97
3 changed files with 23 additions and 32 deletions

View file

@ -28,7 +28,7 @@ admin.autodiscover()
urlpatterns = [
# Page d'accueil
path("", gestioncof_views.home, name="home"),
path("", gestioncof_views.HomeView.as_view(), name="home"),
# Le BdA
path("bda/", include("bda.urls")),
# Les exports

View file

@ -9,16 +9,6 @@
<div class="container">
<div class="home-menu row">
<div class="{% if user.profile.is_buro %}col-sm-6 {% else %}col-sm-8 col-sm-offset-2 col-xs-12 {%endif%}normal-user-hm">
<!-- {% if open_events %}
<h3 class="block-title">Événements<span class="pull-right glyphicon glyphicon-calendar"></span></h3>
<div class="hm-block">
<ul>
{% for event in open_events %}
<li><a href="{% url "event.details" event.id %}">{{ event.title }}</a></li>
{% endfor %}
</ul>
</div>
{% endif %} -->
{% if open_surveys %}
<h3 class="block-title">Sondages en cours<span class="pull-right glyphicon glyphicon-stats"></span></h3>
<div class="hm-block">

View file

@ -6,6 +6,7 @@ import unicodecsv
from custommail.shortcuts import send_custom_mail
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
from django.contrib.auth.views import (
LoginView as DjangoLoginView,
@ -18,7 +19,7 @@ from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse_lazy
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView
from django.views.generic import FormView, TemplateView
from django_cas_ng.views import LogoutView as CasLogoutView
from icalendar import Calendar, Event as Vevent
@ -58,20 +59,20 @@ from gestioncof.models import (
from utils.views.autocomplete import Select2QuerySetView
@login_required
def home(request):
data = {
"surveys": Survey.objects.filter(old=False).all(),
"events": Event.objects.filter(old=False).all(),
"open_surveys": Survey.objects.filter(survey_open=True, old=False).all(),
"open_events": Event.objects.filter(registration_open=True, old=False).all(),
"active_tirages": Tirage.objects.filter(active=True).all(),
"open_tirages": Tirage.objects.filter(
class HomeView(LoginRequiredMixin, TemplateView):
template_name = "gestioncof/home.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["surveys"] = Survey.objects.filter(old=False)
context["events"] = Event.objects.filter(old=False)
context["open_surveys"] = Survey.objects.filter(survey_open=True, old=False)
context["active_tirages"] = Tirage.objects.filter(active=True)
context["open_tirages"] = Tirage.objects.filter(
active=True, ouverture__lte=timezone.now()
).all(),
"now": timezone.now(),
}
return render(request, "home.html", data)
)
context["now"] = timezone.now()
return context
def login(request):