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:
commit
51e8058f97
3 changed files with 23 additions and 32 deletions
|
@ -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
|
||||||
|
|
|
@ -9,16 +9,6 @@
|
||||||
<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">
|
|
@ -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):
|
||||||
|
|
Loading…
Reference in a new issue