Skip to content

Commit

Permalink
Merge pull request #480 from will-moore/django-4-2
Browse files Browse the repository at this point in the history
Compatibility with Django 4.2
  • Loading branch information
knabar authored Jul 25, 2023
2 parents bbc2823 + 77abef8 commit 50d29ed
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 66 deletions.
2 changes: 1 addition & 1 deletion omero/plugins/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def wrapper(self, *args, **kwargs):
import django # NOQA
except Exception:
self.ctx.die(681, "ERROR: Django not installed!")
if django.VERSION < (3, 2) or django.VERSION >= (3, 3):
if django.VERSION < (3, 2) or django.VERSION >= (4, 3):
self.ctx.err(
"ERROR: Django version %s is not "
"supported!" % django.get_version()
Expand Down
10 changes: 8 additions & 2 deletions omeroweb/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@
# Monkeypatch Django development web server to always run in single thread
# even if --nothreading is not specified on command line
def force_nothreading(
addr, port, wsgi_handler, ipv6=False, threading=False, server_cls=WSGIServer
addr,
port,
wsgi_handler,
ipv6=False,
threading=False,
on_bind=None,
server_cls=WSGIServer,
):
django_core_servers_basehttp_run(
addr, port, wsgi_handler, ipv6, False, server_cls
addr, port, wsgi_handler, ipv6, False, on_bind, server_cls
)

import django.core.servers.basehttp
Expand Down
55 changes: 50 additions & 5 deletions omeroweb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,10 +1420,55 @@ def process_custom_settings(
LOGGING["loggers"][""]["level"] = "INFO"


def report_settings(module):
from django.views.debug import SafeExceptionReporterFilter
class CallableSettingWrapper:
"""
Object to wrap callable appearing in settings.
Adapted from:
* `django.views.debug.CallableSettingWrapper()`
"""

def __init__(self, callable_setting):
self._wrapped = callable_setting

def __repr__(self):
return repr(self._wrapped)


def cleanse_setting(key, value):
"""
Cleanse an individual setting key/value of sensitive content. If the
value is a dictionary, recursively cleanse the keys in that dictionary.
setting_filter = SafeExceptionReporterFilter()
Adapted from:
* `django.views.debug.SafeExceptionReporterFilter.cleanse_setting()`
"""
cleansed_substitute = "********************"
hidden_settings = re.compile("API|TOKEN|KEY|SECRET|PASS|SIGNATUREE", flags=re.I)

try:
is_sensitive = hidden_settings.search(key)
except TypeError:
is_sensitive = False

if is_sensitive:
cleansed = cleansed_substitute
elif isinstance(value, dict):
cleansed = {k: cleanse_setting(k, v) for k, v in value.items()}
elif isinstance(value, list):
cleansed = [cleanse_setting("", v) for v in value]
elif isinstance(value, tuple):
cleansed = tuple([cleanse_setting("", v) for v in value])
else:
cleansed = value

if callable(cleansed):
cleansed = CallableSettingWrapper(cleansed)

return cleansed


def report_settings(module):
custom_settings_mappings = getattr(module, "CUSTOM_SETTINGS_MAPPINGS", {})
for key in sorted(custom_settings_mappings):
values = custom_settings_mappings[key]
Expand All @@ -1434,7 +1479,7 @@ def report_settings(module):
logger.debug(
"%s = %r (source:%s)",
global_name,
setting_filter.cleanse_setting(global_name, global_value),
cleanse_setting(global_name, global_value),
source,
)

Expand All @@ -1447,7 +1492,7 @@ def report_settings(module):
logger.debug(
"%s = %r (deprecated:%s, %s)",
global_name,
setting_filter.cleanse_setting(global_name, global_value),
cleanse_setting(global_name, global_value),
key,
description,
)
Expand Down
55 changes: 0 additions & 55 deletions omeroweb/webgateway/middleware.py

This file was deleted.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def read(fname):
"omero-py>=5.7.0",
# minimum requirements for `omero web start`
"concurrent-log-handler>=0.9.20",
"Django>=3.2.19,<4.0",
"django-pipeline==2.0.7",
"Django>=3.2.19,<4.3",
"django-pipeline==2.1.0",
"django-cors-headers==3.7.0",
"whitenoise>=5.3.0",
"gunicorn>=19.3",
Expand All @@ -68,6 +68,6 @@ def read(fname):
include_package_data=True,
tests_require=["pytest"],
extras_require={
"redis": ["django-redis==5.0.0"],
"redis": ["django-redis==5.3.0"],
},
)

0 comments on commit 50d29ed

Please sign in to comment.