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

@ -7,18 +7,8 @@
{% block interm_content %}
<div class="container hidden-xs espace"></div>
<div class="container">
<div class="home-menu row">
<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">
@ -42,13 +32,13 @@
<li><a href="{% url "bda-tirage-inscription" tirage.id %}">Inscription</a></li>
<li><a href="{% url "bda-etat-places" tirage.id %}">État des demandes</a></li>
{% else %}
<li><a href="{% url "bda-places-attribuees" tirage.id %}">Mes places</a></li>
<li><a href="{% url "bda-revente-manage" tirage.id %}">Gérer les places que je revends</a></li>
<li><a href="{% url "bda-revente-tirages" tirage.id %}">Voir les reventes en cours</a></li>
<li><a href="{% url "bda-places-attribuees" tirage.id %}">Mes places</a></li>
<li><a href="{% url "bda-revente-manage" tirage.id %}">Gérer les places que je revends</a></li>
<li><a href="{% url "bda-revente-tirages" tirage.id %}">Voir les reventes en cours</a></li>
<li><a href="{% url "bda-revente-subscribe" tirage.id %}">Indiquer les spectacles qui m'intéressent</a></li>
<li><a href="{% url "bda-revente-shotgun" tirage.id %}">Places disponibles immédiatement</a></li>
{% endif %}
</ul>
</ul>
{% endfor %}
</div>
{% endif %}
@ -65,14 +55,14 @@
{% endif %}
</ul>
</div>
{% if user.profile.is_cof %}
<h3 class="block-title">Divers<span class="pull-right glyphicon glyphicon-question-sign"></span></h3>
<div class="hm-block">
<ul>
<li><a href="{% url "calendar" %}">Calendrier dynamique</a></li>
{% if user.profile.is_cof %}<li><a href="{% url "petits-cours-inscription" %}">Inscription pour donner des petits cours</a></li>{% endif %}
<li><a href="{% url "profile" %}">Éditer mon profil</a></li>
{% if not user.profile.login_clipper %}<li><a href="{% url "password_change" %}">Changer mon mot de passe</a></li>{% endif %}
</ul>

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):