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 = [ urlpatterns = [
# Page d'accueil # Page d'accueil
path("", gestioncof_views.home, name="home"), path("", gestioncof_views.HomeView.as_view(), name="home"),
# Le BdA # Le BdA
path("bda/", include("bda.urls")), path("bda/", include("bda.urls")),
# Les exports # Les exports

View file

@ -7,18 +7,8 @@
{% block interm_content %} {% block interm_content %}
<div class="container hidden-xs espace"></div> <div class="container hidden-xs espace"></div>
<div class="container"> <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"> <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 %} {% if open_surveys %}
<h3 class="block-title">Sondages en cours<span class="pull-right glyphicon glyphicon-stats"></span></h3> <h3 class="block-title">Sondages en cours<span class="pull-right glyphicon glyphicon-stats"></span></h3>
<div class="hm-block"> <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-tirage-inscription" tirage.id %}">Inscription</a></li>
<li><a href="{% url "bda-etat-places" tirage.id %}">État des demandes</a></li> <li><a href="{% url "bda-etat-places" tirage.id %}">État des demandes</a></li>
{% else %} {% else %}
<li><a href="{% url "bda-places-attribuees" tirage.id %}">Mes places</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-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-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-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> <li><a href="{% url "bda-revente-shotgun" tirage.id %}">Places disponibles immédiatement</a></li>
{% endif %} {% endif %}
</ul> </ul>
{% endfor %} {% endfor %}
</div> </div>
{% endif %} {% endif %}
@ -65,14 +55,14 @@
{% endif %} {% endif %}
</ul> </ul>
</div> </div>
{% if user.profile.is_cof %} {% if user.profile.is_cof %}
<h3 class="block-title">Divers<span class="pull-right glyphicon glyphicon-question-sign"></span></h3> <h3 class="block-title">Divers<span class="pull-right glyphicon glyphicon-question-sign"></span></h3>
<div class="hm-block"> <div class="hm-block">
<ul> <ul>
<li><a href="{% url "calendar" %}">Calendrier dynamique</a></li> <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 %} {% 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> <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 %} {% if not user.profile.login_clipper %}<li><a href="{% url "password_change" %}">Changer mon mot de passe</a></li>{% endif %}
</ul> </ul>

View file

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