Browse Source

Fix(404/iframe): Página 404 customizada, proteção resolver_match e has_iframe com querystring

- Redesign da página 404 com layout responsivo e navegação
- Redireciona usuários não autenticados para /login/ no 404
- Protege nav_run contra resolver_match None
- Mescla has_iframe: getattr seguro + leitura/gravação do parâmetro ?iframe= na sessão
pull/3858/head
rangelbruno 7 months ago
parent
commit
51712dd07f
  1. 15
      sapl/base/templatetags/common_tags.py
  2. 2
      sapl/base/templatetags/menus.py
  3. 149
      sapl/templates/404.html
  4. 12
      sapl/urls.py

15
sapl/base/templatetags/common_tags.py

@ -266,7 +266,20 @@ def has_iframe(obj):
session = getattr(obj, "session", None)
if not session:
return False
return bool(session.get("iframe", 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
@register.filter

2
sapl/base/templatetags/menus.py

@ -64,6 +64,8 @@ def nav_run(context, path=None):
"""
rm = request.resolver_match
if rm is None:
return {}
app_template = rm.app_name.rsplit('.', 1)[-1]
if path:

149
sapl/templates/404.html

@ -1,12 +1,149 @@
{% extends "base.html" %}
{% load i18n %}
{% block head_title %}{% trans 'Página não encontrada! Erro 404' %}{% endblock %}
{% block head_title %}{% trans 'Página não encontrada' %} - 404{% endblock %}
{% block base_content %}
<div class="container text-center" style="margin-top: 50px; margin-bottom: 50px;">
<h1><big>{% trans 'Página não encontrada! Erro 404' %}</big></h1>
<p>{% trans 'A página que você está procurando não foi encontrada.' %}</p>
<a href="/" class="btn btn-primary">{% trans 'Voltar para a página inicial' %}</a>
<style>
.error-container {
text-align: center;
padding: 60px 20px;
min-height: 60vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.error-icon {
font-size: 120px;
color: #f39c12;
margin-bottom: 30px;
animation: float 2s ease-in-out infinite;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
.error-code {
font-size: 72px;
font-weight: bold;
color: #34495e;
margin: 0;
line-height: 1;
}
.error-title {
font-size: 32px;
color: #2c3e50;
margin: 20px 0;
font-weight: 600;
}
.error-message {
font-size: 18px;
color: #7f8c8d;
max-width: 600px;
margin: 20px auto;
line-height: 1.6;
}
.error-actions {
margin-top: 40px;
display: flex;
gap: 15px;
justify-content: center;
flex-wrap: wrap;
}
.btn-error {
padding: 12px 30px;
font-size: 16px;
border-radius: 5px;
text-decoration: none;
transition: all 0.3s;
display: inline-flex;
align-items: center;
gap: 10px;
}
.btn-back {
background: #3498db;
color: white;
border: 2px solid #3498db;
}
.btn-back:hover {
background: #2980b9;
border-color: #2980b9;
color: white;
text-decoration: none;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.btn-home {
background: white;
color: #3498db;
border: 2px solid #3498db;
}
.btn-home:hover {
background: #3498db;
color: white;
text-decoration: none;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
@media (max-width: 768px) {
.error-code {
font-size: 48px;
}
.error-title {
font-size: 24px;
}
.error-icon {
font-size: 80px;
}
.error-actions {
flex-direction: column;
align-items: center;
}
.btn-error {
width: 100%;
max-width: 300px;
justify-content: center;
}
}
</style>
<div class="error-container">
<div class="error-icon">
<i class="fas fa-search"></i>
</div>
{% endblock %}
<h1 class="error-code">404</h1>
<h2 class="error-title">{% trans 'Página não encontrada' %}</h2>
<p class="error-message">
{% trans 'A página que você está procurando não existe ou foi movida.' %}
</p>
<div class="error-actions">
<a href="javascript:history.back()" class="btn-error btn-back">
<i class="fas fa-arrow-left"></i> {% trans 'Voltar' %}
</a>
<a href="/" class="btn-error btn-home">
<i class="fas fa-home"></i> {% trans 'Página Inicial' %}
</a>
</div>
</div>
{% endblock base_content %}

12
sapl/urls.py

@ -122,3 +122,15 @@ def custom_permission_denied_view(request, exception=None):
handler403 = custom_permission_denied_view
def custom_page_not_found_view(request, exception=None):
from django.shortcuts import redirect, render
if not request.user.is_authenticated:
return redirect('/login/')
return render(request, '404.html', status=404)
handler404 = custom_page_not_found_view

Loading…
Cancel
Save