Browse Source

AJUSTADO PRA NAO USAR DEBUG DO ENVIRONMENT, SEMPRE ADICIONAR DJANGO_DEBUG=False NO INICIO DO .ENV

pull/3858/head
Leo Alves 7 months ago
parent
commit
45c2b59647
  1. 46
      sapl/base/templatetags/common_tags.py
  2. 11
      sapl/settings.py

46
sapl/base/templatetags/common_tags.py

@ -257,36 +257,36 @@ def str2intabs(value):
except: except:
return '' 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:
return False
iframe = session.get('iframe', False) @register.filter
if not iframe and hasattr(obj, 'GET') and 'iframe' in obj.GET: #def has_iframe(request):
ival = obj.GET['iframe'] #
if ival and int(ival) == 1: # iframe = request.session.get('iframe', False)
session['iframe'] = True # if not iframe and 'iframe' in request.GET:
return True # ival = request.GET['iframe']
elif hasattr(obj, 'GET') and 'iframe' in obj.GET: # if ival and int(ival) == 1:
ival = obj.GET['iframe'] # request.session['iframe'] = True
if ival and int(ival) == 0: # return True
del session['iframe'] # 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 return False
return request.session.get("iframe", False)
return iframe
@register.filter @register.filter
def url(value): def url(value):
if not isinstance(value, str): if value.startswith('http://') or value.startswith('https://'):
return True
return False return False
return value.startswith(('http://', 'https://'))
@register.filter @register.filter

11
sapl/settings.py

@ -34,7 +34,9 @@ PROJECT_DIR = Path(__file__).ancestor(2)
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = config('SECRET_KEY', default='32jk1h412l3kjh421lkj4hlkj234') SECRET_KEY = config('SECRET_KEY', default='32jk1h412l3kjh421lkj4hlkj234')
# SECURITY WARNING: don't run with debug turned on in production! # 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' MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
@ -154,10 +156,11 @@ MIDDLEWARE = [
'sapl.middleware.CheckWeakPasswordMiddleware', 'sapl.middleware.CheckWeakPasswordMiddleware',
'django_prometheus.middleware.PrometheusAfterMiddleware', 'django_prometheus.middleware.PrometheusAfterMiddleware',
] ]
if DEBUG: if DEBUG and 'runserver' in sys.argv:
INSTALLED_APPS += ('debug_toolbar',) INSTALLED_APPS += ('debug_toolbar',)
MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware', ] MIDDLEWARE += ['debug_toolbar.middleware.DebugToolbarMiddleware']
INTERNAL_IPS = ('127.0.0.1') INTERNAL_IPS = ('127.0.0.1',)
SITE_URL = config('SITE_URL', cast=str, default='') SITE_URL = config('SITE_URL', cast=str, default='')

Loading…
Cancel
Save