diff --git a/pluginHolder/views.py b/pluginHolder/views.py index 99f4a9a7f..b7394562b 100644 --- a/pluginHolder/views.py +++ b/pluginHolder/views.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- from django.shortcuts import render, redirect -from django.http import JsonResponse +from django.http import JsonResponse, StreamingHttpResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_http_methods from plogical.mailUtilities import mailUtilities @@ -2441,6 +2441,7 @@ def plugin_settings_proxy(request, plugin_name): settings_view = getattr(views_mod, candidate, None) if callable(settings_view): response = settings_view(request) + response = _inject_plugin_settings_back_bar(response) return _inject_activation_store_hook(response, plugin_name) except ModuleNotFoundError as e: last_err = str(e) @@ -2458,6 +2459,53 @@ def plugin_settings_proxy(request, plugin_name): return HttpResponseNotFound('Plugin not found.') +def _inject_plugin_settings_back_bar(response): + """ + Add a consistent 'Back to installed Plugins' link at the top of proxied plugin + settings HTML so users need not use the sidebar. Only touches HTML responses. + """ + try: + if isinstance(response, StreamingHttpResponse): + return response + content_type = (response.get('Content-Type', '') or '').lower() + if 'text/html' not in content_type: + return response + if not getattr(response, 'content', None): + return response + body = response.content.decode('utf-8', errors='ignore') + if not body.strip(): + return response + from django.utils.html import escape + from django.utils.translation import gettext as _ + + if 'cp-plugin-settings-back' in body: + return response + label = escape(str(_('Back to installed Plugins'))) + back_html = ( + '
' + '' + '' + label + '
' + ) + if re.search(r']*>', body, flags=re.IGNORECASE): + body = re.sub( + r'(]*>)', + r'\1' + back_html, + body, + count=1, + flags=re.IGNORECASE, + ) + else: + body = back_html + body + response.content = body.encode('utf-8') + return response + except Exception: + return response + + def _inject_activation_store_hook(response, plugin_name): """ Tiny safety hook for plugin settings pages: