Projet

Général

Profil

0003-django4-replaced-deprecated-request.is_ajax-call-686.patch

A. Berriot, 01 septembre 2022 12:22

Télécharger (4,62 ko)

Voir les différences:

Subject: [PATCH 3/6] django4: replaced deprecated request.is_ajax() call
 (#68607)

 .../manager/templates/authentic2/manager/form.html         | 6 +++---
 src/authentic2/manager/user_views.py                       | 5 +++--
 src/authentic2/manager/views.py                            | 3 ++-
 src/authentic2/templatetags/__init__.py                    | 0
 src/authentic2/templatetags/is_ajax.py                     | 7 +++++++
 src/authentic2/utils/request.py                            | 2 ++
 6 files changed, 17 insertions(+), 6 deletions(-)
 create mode 100644 src/authentic2/templatetags/__init__.py
 create mode 100644 src/authentic2/templatetags/is_ajax.py
 create mode 100644 src/authentic2/utils/request.py
src/authentic2/manager/templates/authentic2/manager/form.html
1 1
{% extends "authentic2/manager/base.html" %}
2
{% load gadjo i18n %}
2
{% load gadjo i18n is_ajax %}
3 3

  
4 4
{% block messages %}
5
  {% if not request.is_ajax %}
5
  {% if not request|is_ajax %}
6 6
    {{ block.super }}
7 7
  {% endif %}
8 8
{% endblock %}
......
14 14
    class="{{ form.css_class }}" method="post">
15 15
    <div class="form-inner-container">
16 16
      {% if messages %}
17
        {% if request.is_ajax %}
17
        {% if request|is_ajax %}
18 18
          <ul class="messages">
19 19
              {% for message in messages %}
20 20
              <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
src/authentic2/manager/user_views.py
44 44
from authentic2.models import Attribute, PasswordReset
45 45
from authentic2.utils import spooler, switch_user
46 46
from authentic2.utils.misc import make_url, redirect, select_next_url, send_password_reset_mail
47
from authentic2.utils.request import is_ajax
47 48
from authentic2_idp_oidc.models import OIDCAuthorization, OIDCClient
48 49

  
49 50
from . import app_settings
......
539 540
        if not export.exists:
540 541
            raise Http404()
541 542

  
542
        if request.is_ajax():
543
        if is_ajax(request):
543 544
            return HttpResponse(export.progress)
544 545

  
545 546
        return super().get(request, *args, **kwargs)
......
891 892
        return ctx
892 893

  
893 894
    def get_template_names(self):
894
        if self.request.is_ajax():
895
        if is_ajax(self.request):
895 896
            return ['authentic2/manager/user_import_report_row.html']
896 897
        return ['authentic2/manager/user_import_report.html']
897 898

  
src/authentic2/manager/views.py
47 47
from authentic2.forms.profile import modelform_factory
48 48
from authentic2.utils import crypto
49 49
from authentic2.utils.misc import batch_queryset, redirect
50
from authentic2.utils.request import is_ajax
50 51

  
51 52
from . import app_settings, forms, utils, widgets
52 53

  
......
250 251
        return self.return_ajax_response(request, response)
251 252

  
252 253
    def return_ajax_response(self, request, response):
253
        if not request.is_ajax():
254
        if not is_ajax(request):
254 255
            return response
255 256
        data = {}
256 257
        if 'Location' in response:
src/authentic2/templatetags/is_ajax.py
1
from django import template
2

  
3
from authentic2.utils import request
4

  
5
register = template.Library()
6

  
7
register.filter('is_ajax', request.is_ajax)
src/authentic2/utils/request.py
1
def is_ajax(request):
2
    return request.headers.get('x-requested-with') == 'XMLHttpRequest'
0
-