From 45c2b596475711659c992dc8bd5a7386729200ac Mon Sep 17 00:00:00 2001 From: Leo Alves Date: Wed, 11 Feb 2026 12:17:54 -0300 Subject: [PATCH] AJUSTADO PRA NAO USAR DEBUG DO ENVIRONMENT, SEMPRE ADICIONAR DJANGO_DEBUG=False NO INICIO DO .ENV --- sapl/base/templatetags/common_tags.py | 48 +++++++++++++-------------- sapl/settings.py | 11 +++--- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index a5c36b66d..58a87e394 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -257,36 +257,36 @@ def str2intabs(value): except: return '' + @register.filter -def has_iframe(obj): - """ - Espera receber HttpRequest. - Se vier string/None/outro tipo, não quebra template. - """ - session = getattr(obj, "session", None) - if not session: +#def has_iframe(request): +# +# iframe = request.session.get('iframe', False) +# if not iframe and 'iframe' in request.GET: +# ival = request.GET['iframe'] +# if ival and int(ival) == 1: +# request.session['iframe'] = True +# return True +# elif 'iframe' in request.GET: + # ival = request.GET['iframe'] + # if ival and int(ival) == 0: + # del request.session['iframe'] + # return False +# +# return iframe +def has_iframe(request): + # Em alguns templates essa tag pode receber string (ex.: request.path), + # então protegemos pra não derrubar a página. + if not hasattr(request, "session"): return False - - iframe = session.get('iframe', False) - if not iframe and hasattr(obj, 'GET') and 'iframe' in obj.GET: - ival = obj.GET['iframe'] - if ival and int(ival) == 1: - session['iframe'] = True - return True - elif hasattr(obj, 'GET') and 'iframe' in obj.GET: - ival = obj.GET['iframe'] - if ival and int(ival) == 0: - del session['iframe'] - return False - - return iframe + return request.session.get("iframe", False) @register.filter def url(value): - if not isinstance(value, str): - return False - return value.startswith(('http://', 'https://')) + if value.startswith('http://') or value.startswith('https://'): + return True + return False @register.filter diff --git a/sapl/settings.py b/sapl/settings.py index 8172ad554..2771bbffa 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -34,7 +34,9 @@ PROJECT_DIR = Path(__file__).ancestor(2) # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = config('SECRET_KEY', default='32jk1h412l3kjh421lkj4hlkj234') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = config('DEBUG', default=False, cast=bool) +#DEBUG = config('DEBUG', default=False, cast=bool) +DEBUG = config('DJANGO_DEBUG', default=False, cast=bool) + MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage' @@ -154,10 +156,11 @@ MIDDLEWARE = [ 'sapl.middleware.CheckWeakPasswordMiddleware', 'django_prometheus.middleware.PrometheusAfterMiddleware', ] -if DEBUG: +if DEBUG and 'runserver' in sys.argv: INSTALLED_APPS += ('debug_toolbar',) - MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ] - INTERNAL_IPS = ('127.0.0.1') + MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware'] + INTERNAL_IPS = ('127.0.0.1',) + SITE_URL = config('SITE_URL', cast=str, default='')