File python-django-waliki-django40-compat.patch of Package python-django-waliki
From fcabf1f537e55691cb5202b16879546df20aacf1 Mon Sep 17 00:00:00 2001
From: Oleg Girko <ol@infoserver.lv>
Date: Sun, 14 Aug 2022 19:14:12 +0300
Subject: [PATCH] Compatibility fixes for Django 4.0.
Import gettext_lazy instead of deprecated ugettext_lazy from
django.utils.translation.
Import force_str instead of deprecated force_text from
django.utils.encoding.
Import smart_str instead of deprecated smart_text from
django.utils.encoding.
Remove providing_args from django.dispatch.Signal() constructors.
It was purely documentational anyway.
Import re_path from django.urls instead of
deprecated url from django.conf.urls.
Add wrkaround for missing is_ajax() method of WSGIRequest.
Also, adapt to newer markups package that changed signature of
MarkdownMarkup._apply_extensions() method.
Signed-off-by: Oleg Girko <ol@infoserver.lv>
---
waliki/_markups.py | 4 ++--
waliki/attachments/models.py | 2 +-
waliki/attachments/urls.py | 5 ++++-
waliki/attachments/views.py | 3 ++-
waliki/attachments/waliki_plugin.py | 2 +-
waliki/forms.py | 2 +-
waliki/git/models.py | 2 +-
waliki/git/urls.py | 5 ++++-
waliki/git/views.py | 7 +++++--
waliki/git/waliki_plugin.py | 2 +-
.../commands/moin_migration_cleanup.py | 2 +-
waliki/models.py | 2 +-
waliki/pdf/urls.py | 5 ++++-
waliki/pdf/waliki_plugin.py | 2 +-
waliki/search/urls.py | 5 ++++-
waliki/search/waliki_plugin.py | 2 +-
waliki/signals.py | 6 +++---
waliki/slides/urls.py | 5 ++++-
waliki/slides/waliki_plugin.py | 2 +-
waliki/urls.py | 6 +++++-
waliki/utils.py | 12 +++++++++++-
waliki/views.py | 17 +++++++++--------
waliki_project/waliki_project/urls.py | 6 +++++-
23 files changed, 72 insertions(+), 34 deletions(-)
diff --git a/waliki/_markups.py b/waliki/_markups.py
index a26f846..5167226 100644
--- a/waliki/_markups.py
+++ b/waliki/_markups.py
@@ -18,8 +18,8 @@ class MarkdownMarkup(MarkdownMarkupBase):
self.extension_configs_ = extension_configs
super(MarkdownMarkup, self).__init__(filename)
- def _apply_extensions(self):
- super(MarkdownMarkup, self)._apply_extensions()
+ def _apply_extensions(self, *args, **kwargs):
+ super(MarkdownMarkup, self)._apply_extensions(*args, **kwargs)
self.md.set_output_format('html5')
self.md.registerExtensions(self.extensions_, self.extension_configs_)
diff --git a/waliki/attachments/models.py b/waliki/attachments/models.py
index adf5bef..1f7930e 100644
--- a/waliki/attachments/models.py
+++ b/waliki/attachments/models.py
@@ -2,7 +2,7 @@
import os.path
from django import VERSION
from django.db import models
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from django.db.models.signals import pre_delete
from django.dispatch.dispatcher import receiver
from six import python_2_unicode_compatible
diff --git a/waliki/attachments/urls.py b/waliki/attachments/urls.py
index 113c6d4..980a30b 100644
--- a/waliki/attachments/urls.py
+++ b/waliki/attachments/urls.py
@@ -2,7 +2,10 @@ import django
try:
from django.conf.urls import patterns, url # django 1.8, 1.9
except ImportError:
- from django.conf.urls import url
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from waliki.settings import WALIKI_SLUG_PATTERN
from waliki.attachments.views import attachments, delete_attachment, get_file
diff --git a/waliki/attachments/views.py b/waliki/attachments/views.py
index 78e35ed..a7d482e 100644
--- a/waliki/attachments/views.py
+++ b/waliki/attachments/views.py
@@ -8,6 +8,7 @@ from django.http import HttpResponse
from sendfile import sendfile
from waliki.models import Page
from waliki.acl import permission_required
+from waliki.utils import is_ajax
from .models import Attachment
@@ -29,7 +30,7 @@ def delete_attachment(request, slug, attachment_id_or_filename):
else:
attachment = get_object_or_404(Attachment, file__endswith=attachment_id_or_filename, page__slug=slug)
name = text_type(attachment)
- if request.is_ajax() and request.method in ('POST', 'DELETE'):
+ if is_ajax(request) and request.method in ('POST', 'DELETE'):
attachment.delete()
return HttpResponse(json.dumps({'removed': name}), content_type="application/json")
return HttpResponse(json.dumps({'removed': None}), content_type="application/json")
diff --git a/waliki/attachments/waliki_plugin.py b/waliki/attachments/waliki_plugin.py
index ba3f9d2..fe4dc8b 100644
--- a/waliki/attachments/waliki_plugin.py
+++ b/waliki/attachments/waliki_plugin.py
@@ -1,4 +1,4 @@
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from waliki.plugins import BasePlugin, register
diff --git a/waliki/forms.py b/waliki/forms.py
index 29bc5e9..00ed59b 100644
--- a/waliki/forms.py
+++ b/waliki/forms.py
@@ -1,6 +1,6 @@
from django import VERSION
from django import forms
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from .models import Page
from ._markups import get_all_markups
from .settings import WALIKI_CODEMIRROR_SETTINGS as CM_SETTINGS, get_slug
diff --git a/waliki/git/models.py b/waliki/git/models.py
index 6410249..3f3e45f 100644
--- a/waliki/git/models.py
+++ b/waliki/git/models.py
@@ -3,7 +3,7 @@ import re
from django.contrib.auth import get_user_model
from django.dispatch import receiver
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
import six
_
from sh import git, ErrorReturnCode, Command
diff --git a/waliki/git/urls.py b/waliki/git/urls.py
index 981365d..417f7e8 100644
--- a/waliki/git/urls.py
+++ b/waliki/git/urls.py
@@ -2,7 +2,10 @@ import django
try:
from django.conf.urls import patterns, url # django 1.8, 1.9
except ImportError:
- from django.conf.urls import url
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from waliki.settings import WALIKI_SLUG_PATTERN
from waliki.git.views import whatchanged, WhatchangedFeed, webhook_pull, history, version, diff
diff --git a/waliki/git/views.py b/waliki/git/views.py
index b68ee7d..44b6b5b 100644
--- a/waliki/git/views.py
+++ b/waliki/git/views.py
@@ -5,7 +5,7 @@ from datetime import datetime
from django import VERSION
from django.templatetags.tz import localtime
from django.shortcuts import render, get_object_or_404, redirect
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from django.http import Http404
from django.core.management import call_command
from django.http import HttpResponse
@@ -13,7 +13,10 @@ if VERSION[:2] >= (1, 10):
from django.urls import reverse, reverse_lazy
else:
from django.core.urlresolvers import reverse, reverse_lazy
-from django.utils.encoding import smart_text
+try:
+ from django.utils.encoding import smart_text
+except ImportError:
+ from django.utils.encoding import smart_str as smart_text
from six import StringIO, text_type
from django.views.decorators.csrf import csrf_exempt
from waliki.models import Page
diff --git a/waliki/git/waliki_plugin.py b/waliki/git/waliki_plugin.py
index cdf73bd..c4e8409 100644
--- a/waliki/git/waliki_plugin.py
+++ b/waliki/git/waliki_plugin.py
@@ -1,4 +1,4 @@
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from waliki.plugins import BasePlugin, register
diff --git a/waliki/management/commands/moin_migration_cleanup.py b/waliki/management/commands/moin_migration_cleanup.py
index 4f78754..3bdf90a 100644
--- a/waliki/management/commands/moin_migration_cleanup.py
+++ b/waliki/management/commands/moin_migration_cleanup.py
@@ -3,7 +3,7 @@ from waliki.signals import page_saved
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from waliki.models import Page
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from django.utils.text import get_text_list
try:
from waliki.attachments.models import Attachment
diff --git a/waliki/models.py b/waliki/models.py
index 1a6ad8d..e790ab5 100644
--- a/waliki/models.py
+++ b/waliki/models.py
@@ -14,7 +14,7 @@ else:
from django.core.urlresolvers import reverse
from django.dispatch import receiver
from six import string_types
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from django.contrib.auth.models import Permission, Group, AnonymousUser
from django.contrib.auth import get_user_model
from django.core.cache import cache
diff --git a/waliki/pdf/urls.py b/waliki/pdf/urls.py
index d14eab9..60a06c5 100644
--- a/waliki/pdf/urls.py
+++ b/waliki/pdf/urls.py
@@ -2,7 +2,10 @@ import django
try:
from django.conf.urls import patterns, url # django 1.8, 1.9
except ImportError:
- from django.conf.urls import url
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from waliki.settings import WALIKI_SLUG_PATTERN
from waliki.pdf.views import pdf
diff --git a/waliki/pdf/waliki_plugin.py b/waliki/pdf/waliki_plugin.py
index 8dfd45e..14ffdb2 100644
--- a/waliki/pdf/waliki_plugin.py
+++ b/waliki/pdf/waliki_plugin.py
@@ -1,4 +1,4 @@
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from waliki.plugins import BasePlugin, register
diff --git a/waliki/search/urls.py b/waliki/search/urls.py
index 0d2f0f1..010e712 100644
--- a/waliki/search/urls.py
+++ b/waliki/search/urls.py
@@ -6,7 +6,10 @@ import django
try:
from django.conf.urls import patterns, url # django 1.8, 1.9
except ImportError:
- from django.conf.urls import url
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from haystack.forms import SearchForm
from waliki.search.views import WalikiSearchView
diff --git a/waliki/search/waliki_plugin.py b/waliki/search/waliki_plugin.py
index 80b458d..b97c487 100644
--- a/waliki/search/waliki_plugin.py
+++ b/waliki/search/waliki_plugin.py
@@ -1,4 +1,4 @@
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from waliki.plugins import BasePlugin, register
diff --git a/waliki/signals.py b/waliki/signals.py
index 43481b4..06999e4 100644
--- a/waliki/signals.py
+++ b/waliki/signals.py
@@ -1,5 +1,5 @@
import django.dispatch
-page_preedit = django.dispatch.Signal(providing_args=["page"])
-page_saved = django.dispatch.Signal(providing_args=["raw", "author", "message"])
-page_moved = django.dispatch.Signal(providing_args=["page", "old_path", "author", "message"])
+page_preedit = django.dispatch.Signal()
+page_saved = django.dispatch.Signal()
+page_moved = django.dispatch.Signal()
diff --git a/waliki/slides/urls.py b/waliki/slides/urls.py
index dc1ddab..3df88ee 100644
--- a/waliki/slides/urls.py
+++ b/waliki/slides/urls.py
@@ -2,7 +2,10 @@ import django
try:
from django.conf.urls import patterns, url # django 1.8, 1.9
except ImportError:
- from django.conf.urls import url
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from waliki.settings import WALIKI_SLUG_PATTERN
from waliki.slides.views import slides
diff --git a/waliki/slides/waliki_plugin.py b/waliki/slides/waliki_plugin.py
index 014cfbd..6e64dca 100644
--- a/waliki/slides/waliki_plugin.py
+++ b/waliki/slides/waliki_plugin.py
@@ -1,4 +1,4 @@
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from waliki.plugins import BasePlugin, register
diff --git a/waliki/urls.py b/waliki/urls.py
index ba6ca49..cf5e8e5 100644
--- a/waliki/urls.py
+++ b/waliki/urls.py
@@ -2,7 +2,11 @@ import django
try:
from django.conf.urls import patterns, url, include # django 1.8, 1.9
except ImportError:
- from django.conf.urls import url, include
+ from django.conf.urls import include
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from django.contrib import admin
from waliki.settings import WALIKI_SLUG_PATTERN
diff --git a/waliki/utils.py b/waliki/utils.py
index c259c2a..2e232f9 100644
--- a/waliki/utils.py
+++ b/waliki/utils.py
@@ -9,8 +9,15 @@ if VERSION[:2] >= (1, 10):
else:
from django.core.urlresolvers import reverse
from six import PY2
-from django.utils.encoding import force_text
+try:
+ from django.utils.encoding import force_text
+except ImportError:
+ from django.utils.encoding import force_str as force_text
from django.utils.safestring import mark_safe
+try:
+ from django.utils.translation import ugettext_lazy as gettext_lazy
+except ImportError:
+ from django.utils.translation import gettext_lazy
def get_slug(text):
def slugify(value):
@@ -60,3 +67,6 @@ if VERSION[:2] >= (1, 10):
else:
def is_authenticated(user):
return user.is_authenticated()
+
+def is_ajax(request):
+ return request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
diff --git a/waliki/views.py b/waliki/views.py
index 2cb8cbc..9a21473 100644
--- a/waliki/views.py
+++ b/waliki/views.py
@@ -4,7 +4,7 @@ from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpRespons
from django.shortcuts import render, redirect, get_object_or_404
from django.template import RequestContext
from django.template.loader import render_to_string
-from django.utils.translation import ugettext_lazy as _
+from waliki.utils import gettext_lazy as _
from django.contrib import messages
if VERSION[:2] >= (1, 10):
from django.urls import reverse
@@ -16,6 +16,7 @@ from .signals import page_saved, page_preedit, page_moved
from ._markups import get_all_markups
from .acl import permission_required
from . import settings
+from .utils import is_ajax
def home(request):
@@ -106,11 +107,11 @@ def move(request, slug):
url = reverse('waliki_detail', args=[new_slug])
messages.success(request, msg)
- if request.is_ajax():
+ if is_ajax(request):
return HttpResponse(json.dumps({'redirect': url}), content_type="application/json")
return redirect(url)
- if request.is_ajax():
+ if is_ajax(request):
data = render_to_string('waliki/generic_form.html', {'page': page, 'form': form},
request=request)
return HttpResponse(json.dumps({'data': data}), content_type="application/json")
@@ -199,7 +200,7 @@ def edit(request, slug):
def preview(request):
data = {}
- if request.is_ajax() and request.method == "POST":
+ if is_ajax(request) and request.method == "POST":
data['html'] = Page.preview(
request.POST['markup'], request.POST['text'])
return HttpResponse(json.dumps(data), content_type="application/json")
@@ -220,11 +221,11 @@ def delete(request, slug):
'slug': slug}
messages.warning(request, msg)
- if request.is_ajax():
+ if is_ajax(request):
return HttpResponse(json.dumps({'redirect': reverse('waliki_home')}), content_type="application/json")
return redirect('waliki_home')
- if request.is_ajax():
+ if is_ajax(request):
data = render_to_string('waliki/delete.html', {'page': page, 'form': form},
request=request)
return HttpResponse(json.dumps({'data': data}), content_type="application/json")
@@ -242,11 +243,11 @@ def new(request):
author=request.user,
message=_("Page created"),
form_extra_data={})
- if request.is_ajax():
+ if is_ajax(request):
return HttpResponse(json.dumps({'redirect': page.get_edit_url()}), content_type="application/json")
return redirect(page.get_edit_url())
- if request.is_ajax():
+ if is_ajax(request):
data = render_to_string('waliki/generic_form.html', {'form': form},
request=request)
return HttpResponse(json.dumps({'data': data}), content_type="application/json")
diff --git a/waliki_project/waliki_project/urls.py b/waliki_project/waliki_project/urls.py
index f174e8a..662dc38 100644
--- a/waliki_project/waliki_project/urls.py
+++ b/waliki_project/waliki_project/urls.py
@@ -3,7 +3,11 @@ try:
from django.conf.urls import patterns, include, url
except ImportError:
patterns = None
- from django.conf.urls import url, include
+ from django.conf.urls import include
+ try:
+ from django.conf.urls import url
+ except ImportError:
+ from django.urls import re_path as url
from django.views.generic import TemplateView
from django.contrib import admin
--
2.37.1