Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Websites UFRPE
django-dsgov
Commits
f61a9c6a
Commit
f61a9c6a
authored
Sep 03, 2025
by
Eduardo Silva
Browse files
ajustes na tag de link do menu e na tag de busca do header
parent
76cc7295
Changes
2
Hide whitespace changes
Inline
Side-by-side
dsgov/templatetags/br_header_tags.py
View file @
f61a9c6a
from
django
import
template
from
django.utils.safestring
import
mark_safe
from
django.utils.html
import
format_html
from
django.
template.base
import
Variable
,
VariableDoesNotExist
from
django.
urls
import
reverse
,
NoReverseMatch
register
=
template
.
Library
()
...
...
@@ -443,31 +443,48 @@ class BRFunctionItemNode(template.Node):
# =========================
@
register
.
simple_tag
(
takes_context
=
True
)
def
br_header_search
(
context
,
placeholder
=
"O que você procura?"
,
icon_style
=
""
):
icon_style_attr
=
''
if
icon_style
:
resolved_style
=
resolve_variable
(
icon_style
,
context
)
icon_style_attr
=
format_html
(
' style="{}"'
,
resolved_style
)
def
br_header_search
(
context
,
placeholder
=
"O que você procura?"
,
icon_style
=
""
,
action_url
=
None
):
"""
Renderiza um campo de busca genérico para o header.
- placeholder: texto exibido no input
- icon_style: CSS inline opcional para o ícone
- action_url: para onde enviar a busca (se None, tenta resolver 'search', senão usa '/search/')
"""
# Resolve estilos
icon_style_attr
=
f
' style="
{
icon_style
}
"'
if
icon_style
else
""
# Resolve URL de destino da busca
if
action_url
is
None
:
try
:
action_url
=
reverse
(
"search"
)
except
NoReverseMatch
:
action_url
=
"/search/"
# Monta o HTML
search_html
=
format_html
(
'''<div class="header-search">
<div class="br-input has-icon">
<label for="searchbox-header">Texto da pesquisa</label>
<input id="searchbox-header" type="text" placeholder="{}"/>
<button class="br-button circle small" type="button" aria-label="Pesquisar">
<i class="fas fa-search" aria-hidden="true"></i>
</button>
</div>
'''
<div class="header-search">
<form method="get" action="{}">
<div class="br-input has-icon">
<label for="searchbox-header">Texto da pesquisa</label>
<input id="searchbox-header" type="text" name="query" placeholder="{}"/>
<button class="br-button circle small" type="submit" aria-label="Pesquisar">
<i class="fas fa-search" aria-hidden="true"></i>
</button>
</div>
</form>
<button class="br-button circle search-close ml-1" type="button" aria-label="Fechar Busca" data-dismiss="search">
<i class="fas fa-times" aria-hidden="true"{}></i>
</button>
</div>'''
,
resolve_variable
(
placeholder
,
context
),
icon_style_attr
</div>
'''
,
action_url
,
placeholder
,
icon_style_attr
,
)
# A lógica continua a mesma: popular o contexto.
context
[
'br_header_search_html'
]
=
search_html
return
''
return
search_html
@
register
.
simple_tag
(
takes_context
=
True
)
def
br_header_search_trigger
(
context
,
icon_style
=
""
):
...
...
dsgov/templatetags/br_menu_tags.py
View file @
f61a9c6a
...
...
@@ -504,12 +504,14 @@ class BRMenuLinkNode(template.Node):
if
self
.
icon_expr
:
try
:
icon_class
=
self
.
icon_expr
.
resolve
(
context
)
resolved_icon
=
self
.
icon_expr
.
resolve
(
context
)
if
resolved_icon
:
icon_class
=
f
"fas fa-
{
resolved_icon
}
"
except
template
.
VariableDoesNotExist
:
pass
return
format_html
(
'<a href="{}"><span class="mr-1">{}</span><i class="
fas
{}" aria-hidden="true"></i></a>'
,
'<a href="{}"><span class="mr-1">{}</span><i class="{}" aria-hidden="true"></i></a>'
,
href
,
content
,
icon_class
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment