diff --git a/apps/member/views.py b/apps/member/views.py index 3570f7b230540a626800018645c9f6df31c05d4f..6f982c64f6463a954de664c04640ee20dd7fd9db 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -249,6 +249,9 @@ class ClubAddMemberView(LoginRequiredMixin, CreateView): context = super().get_context_data(**kwargs) context['formset'] = MemberFormSet() context['helper'] = FormSetHelper() + + context['no_cache'] = True + return context def post(self, request, *args, **kwargs): diff --git a/apps/note/views.py b/apps/note/views.py index 61012f34285aa050d1d47edba7408b79cc01890d..167ef4f0d4c4c8a45c251e7e60af2ebb622b98b1 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -28,6 +28,9 @@ class TransactionCreate(LoginRequiredMixin, CreateView): context = super().get_context_data(**kwargs) context['title'] = _('Transfer money from your account ' 'to one or others') + + context['no_cache'] = True + return context def get_form(self, form_class=None): @@ -138,6 +141,10 @@ class ConsoView(LoginRequiredMixin, CreateView): context['transaction_templates'] = TransactionTemplate.objects.all() \ .order_by('template_type') context['title'] = _("Consommations") + + # select2 compatibility + context['no_cache'] = True + return context def get_success_url(self): diff --git a/note_kfet/middlewares.py b/note_kfet/middlewares.py new file mode 100644 index 0000000000000000000000000000000000000000..73b87e363c32faf1d0fa836122fb2a2674347894 --- /dev/null +++ b/note_kfet/middlewares.py @@ -0,0 +1,38 @@ +# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay +# SPDX-License-Identifier: GPL-3.0-or-later + +from django.http import HttpResponseRedirect + +from urllib.parse import urlencode, parse_qs, urlsplit, urlunsplit + + +class TurbolinksMiddleware(object): + """ + Send the `Turbolinks-Location` header in response to a visit that was redirected, + and Turbolinks will replace the browser's topmost history entry. + """ + + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + response = self.get_response(request) + + is_turbolinks = request.META.get('HTTP_TURBOLINKS_REFERRER') + is_response_redirect = response.has_header('Location') + + if is_turbolinks: + if is_response_redirect: + location = response['Location'] + prev_location = request.session.pop('_turbolinks_redirect_to', None) + if prev_location is not None: + # relative subsequent redirect + if location.startswith('.'): + location = prev_location.split('?')[0] + location + request.session['_turbolinks_redirect_to'] = location + else: + if request.session.get('_turbolinks_redirect_to'): + location = request.session.pop('_turbolinks_redirect_to') + response['Turbolinks-Location'] = location + return response + diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index 410f496fe4d7811b90078dea294ab04bd29b2953..9019b4e07c39a3a0588e91bec7c7b580a4d2d4ba 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -75,6 +75,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.sites.middleware.CurrentSiteMiddleware', + 'note_kfet.middlewares.TurbolinksMiddleware', ] ROOT_URLCONF = 'note_kfet.urls' diff --git a/requirements.txt b/requirements.txt index 2899ef61d3fd0d26726d08da3f0c3c0a72d7aa8e..21c24808b0f562f2b0f71ea19a1ed1d2193b7b89 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ chardet==3.0.4 defusedxml==0.6.0 Django~=2.2 django-allauth==0.39.1 -django-autocomplete-light==3.3.0 +django-autocomplete-light==3.5.1 django-crispy-forms==1.7.2 django-extensions==2.1.9 django-filter==2.2.0 @@ -14,6 +14,7 @@ django-rest-polymorphic==0.1.8 django-reversion==3.0.3 django-tables2==2.1.0 docutils==0.14 +psycopg2==2.8.4 idna==2.8 oauthlib==3.1.0 Pillow==6.1.0 diff --git a/templates/base.html b/templates/base.html index ba7b4c9ecded94c0ae55b838050f4eea3c619ab2..4b5f9872d7b52a12eeeabf8ea7500833a522d8f3 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,6 +22,9 @@ SPDX-License-Identifier: GPL-3.0-or-later <meta name="msapplication-TileColor" content="#da532c"> <meta name="msapplication-config" content="{% static "favicon/browserconfig.xml" %}"> <meta name="theme-color" content="#ffffff"> + {% if no_cache %} + <meta name="turbolinks-cache-control" content="no-cache"> + {% endif %} {# Bootstrap CSS #} <link rel="stylesheet" @@ -31,6 +34,19 @@ SPDX-License-Identifier: GPL-3.0-or-later <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> + {# JQuery, Bootstrap and Turbolinks JavaScript #} + <script src="https://code.jquery.com/jquery-3.4.1.min.js" + integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" + crossorigin="anonymous"></script> + <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" + integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" + crossorigin="anonymous"></script> + <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" + integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" + crossorigin="anonymous"></script> + <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js" + crossorigin="anonymous"></script> + {# Si un formulaire requiert des données supplémentaires (notamment JS), les données sont chargées #} {% if form.media %} {{ form.media }} @@ -139,16 +155,6 @@ SPDX-License-Identifier: GPL-3.0-or-later </div> </footer> -{# Bootstrap JavaScript #} -<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" - integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" - crossorigin="anonymous"></script> -<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" - integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" - crossorigin="anonymous"></script> -<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" - integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" - crossorigin="anonymous"></script> {% block extrajavascript %} {% endblock extrajavascript %} </body>