forked from ungleich-public/dynamicweb
Add compat shims for removed Django names used by unmaintained packages
This commit is contained in:
parent
f784a61cc7
commit
3b5fcafd3f
2 changed files with 62 additions and 8 deletions
57
dynamicweb/compat.py
Normal file
57
dynamicweb/compat.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
Aliases for helpers that newer Django versions removed.
|
||||
|
||||
The unmaintained aldryn-* packages (and similar) still import them. Imported
|
||||
first thing from the settings, before any app code is loaded.
|
||||
"""
|
||||
import django.utils.encoding
|
||||
import django.utils.translation
|
||||
|
||||
if not hasattr(django.utils.encoding, 'python_2_unicode_compatible'):
|
||||
django.utils.encoding.python_2_unicode_compatible = lambda cls: cls
|
||||
|
||||
for _name in ('gettext', 'gettext_lazy', 'gettext_noop',
|
||||
'ngettext', 'ngettext_lazy'):
|
||||
if not hasattr(django.utils.translation, 'u' + _name):
|
||||
setattr(django.utils.translation, 'u' + _name,
|
||||
getattr(django.utils.translation, _name))
|
||||
|
||||
import sys
|
||||
|
||||
import six
|
||||
from django.conf import urls
|
||||
from django.db import models
|
||||
from django.http import HttpRequest
|
||||
from django.urls import re_path
|
||||
from django.utils import encoding
|
||||
|
||||
for _name, _target in (('force_text', 'force_str'), ('smart_text', 'smart_str'),
|
||||
('force_unicode', 'force_str')):
|
||||
if not hasattr(encoding, _name):
|
||||
setattr(encoding, _name, getattr(encoding, _target))
|
||||
|
||||
if not hasattr(urls, 'url'):
|
||||
urls.url = re_path
|
||||
|
||||
if 'django.utils.six' not in sys.modules:
|
||||
import django.utils
|
||||
django.utils.six = six
|
||||
sys.modules['django.utils.six'] = six
|
||||
sys.modules['django.utils.six.moves'] = six.moves
|
||||
|
||||
if not hasattr(models, 'NullBooleanField'):
|
||||
class NullBooleanField(models.BooleanField):
|
||||
def __init__(self, *args, **kwargs):
|
||||
kwargs['null'] = True
|
||||
kwargs['blank'] = True
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def deconstruct(self):
|
||||
name, path, args, kwargs = super().deconstruct()
|
||||
del kwargs['null'], kwargs['blank']
|
||||
return name, path, args, kwargs
|
||||
|
||||
models.NullBooleanField = NullBooleanField
|
||||
|
||||
if not hasattr(HttpRequest, 'is_ajax'):
|
||||
HttpRequest.is_ajax = lambda self: self.headers.get('x-requested-with') == 'XMLHttpRequest'
|
||||
|
|
@ -10,13 +10,9 @@ import os
|
|||
|
||||
# dotenv
|
||||
import dotenv
|
||||
import django.utils.encoding
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
# The unmaintained aldryn-* packages still import this Django 2 helper
|
||||
# (removed in Django 3.0); on Python 3 it is a no-op.
|
||||
if not hasattr(django.utils.encoding, 'python_2_unicode_compatible'):
|
||||
django.utils.encoding.python_2_unicode_compatible = lambda cls: cls
|
||||
import dynamicweb.compat # noqa: F401, shims for packages Django 4 broke
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -527,8 +523,9 @@ META_INCLUDE_KEYWORDS = ["ungleich", "hosting", "switzerland",
|
|||
"Schweiz", "Swiss", "cdist"]
|
||||
META_USE_SITES = True
|
||||
|
||||
# django-multisite's SiteID is a lazy object, not an int
|
||||
SILENCED_SYSTEM_CHECKS = ['sites.E101']
|
||||
# sites.E101: django-multisite's SiteID is a lazy object, not an int
|
||||
# fields.E903: django-multisite still uses NullBooleanField
|
||||
SILENCED_SYSTEM_CHECKS = ['sites.E101', 'fields.E903']
|
||||
|
||||
PARLER_LANGUAGES = {SITE_ID: ({'code': 'en-us'}, {'code': 'de'},)}
|
||||
AUTH_USER_MODEL = 'membership.CustomUser'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue