-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
604 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Module that includes customizations to the search templates | ||
including browser views, viewlets and JS code. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<div id="portal-searchbox" | ||
i18n:domain="brasil.gov.portal" | ||
tal:define="navigation_root_url view/navigation_root_url; | ||
search_input_id view/search_input_id; | ||
title_search_box string:'Search Site'; | ||
expandable_header view/expandable_header" | ||
tal:attributes="class view/klass; | ||
style view/style"> | ||
|
||
<form id="searchGadget_form" | ||
action="@@busca" | ||
tal:attributes="action string:${navigation_root_url}/@@busca; | ||
id string:${search_input_id}_form;"> | ||
<div class="close" tal:condition="expandable_header">+</div> | ||
<fieldset class="LSBox"> | ||
<legend class="hiddenStructure" | ||
i18n:translate="">Search Site</legend> | ||
<label class="hiddenStructure" | ||
tal:attributes="for search_input_id" | ||
i18n:translate="">Search Site</label> | ||
|
||
<input name="SearchableText" | ||
type="text" | ||
size="18" | ||
value="" | ||
title="Search Site" | ||
placeholder="Search Site" | ||
i18n:attributes="title title_search_box; | ||
placeholder title_search_box" | ||
tal:attributes="value request/form/SearchableText|nothing; | ||
id search_input_id" | ||
class="searchField" /> | ||
|
||
<input class="searchButton" | ||
type="submit" | ||
value="Search" | ||
i18n:attributes="value label_search;" /> | ||
|
||
</fieldset> | ||
|
||
<div class="search-suggestions" tal:condition="expandable_header"> | ||
<div class="news" | ||
tal:define="featured_news view/featured_news" | ||
tal:condition="featured_news"> | ||
<div class="news-title"><strong>Notícias</strong> em destaque</div> | ||
<ul class="featured-news"> | ||
<li tal:repeat="article featured_news"> | ||
<a tal:attributes="href article/url" tal:content="article/title" /> | ||
</li> | ||
</ul> | ||
<a class="more-news" tal:attributes="href view/more_news">Mais notícias</a> | ||
</div> | ||
<div class="services" | ||
tal:define="featured_services view/featured_services" | ||
tal:condition="featured_services"> | ||
<div class="services-title"><strong>Serviços</strong> em destaque</div> | ||
<ul class="featured-services"> | ||
<li tal:repeat="service featured_services"> | ||
<a tal:attributes="href service/url" tal:content="service/title" /> | ||
</li> | ||
</ul> | ||
<a class="more-services" tal:attributes="href view/more_services">Mais serviços</a> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<tal:block condition="expandable_header"> | ||
<ul class="top-subjects" | ||
tal:define="top_subjects view/top_subjects" | ||
tal:condition="top_subjects"> | ||
<div class="subjects-title"><h3>Assuntos em alta</h3></div> | ||
<li tal:repeat="subject top_subjects"> | ||
<a tal:attributes="href subject/url" tal:content="subject/title" /> | ||
</li> | ||
</ul> | ||
</tal:block> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# -*- coding: utf-8 -*- | ||
"""SearchBoxViewlet customization. | ||
The new search box includes 2 different versions, one similar to the | ||
default but calling @@busca at form submission. The other is an | ||
expandable version that uses information stored in the registry, and | ||
accessible at the @@portal-settings configlet. | ||
""" | ||
from brasil.gov.portal.controlpanel.portal import ISettingsPortal | ||
from plone.app.layout.viewlets.common import SearchBoxViewlet as SearchBoxViewletBase | ||
from plone.registry.interfaces import IRegistry | ||
from zope.component import getUtility | ||
|
||
|
||
class SearchBoxViewlet(SearchBoxViewletBase): | ||
"""Search box viewlet customization.""" | ||
|
||
def update(self): | ||
super(SearchBoxViewlet, self).update() | ||
registry = getUtility(IRegistry) | ||
self.settings = registry.forInterface(ISettingsPortal) | ||
|
||
try: | ||
self.expandable_header = self.settings.expandable_header | ||
except AttributeError: | ||
self.expandable_header = False | ||
|
||
@staticmethod | ||
def split(iterable): | ||
results = [] | ||
if iterable is None: | ||
return results | ||
|
||
for item in iterable: | ||
title, url = item.split('|') | ||
results.append({'title': title, 'url': url}) | ||
return results | ||
|
||
def featured_news(self): | ||
"""Return the list of defined featured news.""" | ||
return self.split(self.settings.featured_news) | ||
|
||
def more_news(self): | ||
return self.settings.more_news | ||
|
||
def featured_services(self): | ||
"""Return the list of defined featured services.""" | ||
return self.split(self.settings.featured_services) | ||
|
||
def more_services(self): | ||
return self.settings.more_services | ||
|
||
def top_subjects(self): | ||
"""Return the list of defined top subjects.""" | ||
return self.split(self.settings.top_subjects) | ||
|
||
def klass(self): | ||
"""Return a CSS class to let Diazo know which search box is in use.""" | ||
if self.expandable_header: | ||
return 'expandable-header' | ||
|
||
def style(self): | ||
"""Return a CSS style to add a background image to an element. | ||
If the expandable header is not used, or there is no background | ||
image defined, return None to remove the style attribute from | ||
rendering. | ||
""" | ||
if not self.expandable_header: | ||
return None | ||
|
||
if self.settings.background_image is None: | ||
return None | ||
|
||
url = self.site_url + '/@@searchbox-background-image' | ||
return 'background-image: url({0})'.format(url) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Helper view to return the background image used in the site root | ||
when the expandable header is enabled. | ||
""" | ||
from __future__ import absolute_import | ||
from brasil.gov.portal.controlpanel.portal import ISettingsPortal | ||
from plone import api | ||
from plone.formwidget.namedfile.converter import b64decode_file | ||
from plone.namedfile.browser import Download | ||
from plone.namedfile.file import NamedImage | ||
|
||
import hashlib | ||
|
||
|
||
class BackgroundImageView(Download): | ||
"""Helper view to return the background image used in the site root | ||
when the expandable header is enabled. | ||
""" | ||
|
||
def setup(self): | ||
name = ISettingsPortal.__identifier__ + '.background_image' | ||
background_image = api.portal.get_registry_record(name, default=None) | ||
|
||
if background_image is None: | ||
self.data = None | ||
return | ||
|
||
# set background image data for download | ||
filename, data = b64decode_file(background_image) | ||
self.filename = filename | ||
self.data = NamedImage(data=data, filename=filename) | ||
self.checksum = hashlib.sha1(data).hexdigest() | ||
|
||
def _getFile(self): | ||
return self.data | ||
|
||
def __call__(self): | ||
"""Render the background image. | ||
Make use of HTTP caching headers to decrease server usage: | ||
image is not cached on browsers and is cached 120 seconds on | ||
intermediate caches. We use a checksum of the image data as | ||
ETag to return a 304 (Not Modified) status in case the image | ||
has not changed since last time it was accessed. | ||
More information: https://httpwg.org/specs/rfc7234.html | ||
""" | ||
self.setup() | ||
|
||
if self.data is None: | ||
# resource no longer available | ||
self.request.RESPONSE.setStatus(410) # Gone | ||
return '' | ||
|
||
# enable image caching for 2 minutes | ||
self.request.RESPONSE.setHeader('Cache-Control', 'max-age=0, s-maxage=120') | ||
self.request.RESPONSE.setHeader('ETag', self.checksum) | ||
|
||
match = self.request.get_header('If-None-Match', '') | ||
if self.checksum == match: | ||
self.request.response.setStatus(304) # Not Modified | ||
return '' | ||
|
||
return super(BackgroundImageView, self).__call__() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/brasil/gov/portal/browser/viewlets/templates/searchbox.pt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.