Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 23 additions & 30 deletions opac/webapp/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def add_collection_to_g():

@main.before_app_request
def add_langs():
session["langs"] = current_app.config.get("LANGUAGES")
g.langs = current_app.config.get("LANGUAGES")
g.lang = get_locale()


@main.after_request
Expand All @@ -82,13 +83,7 @@ def add_header(response):
"CACHE_CONTROL_MAX_AGE_HEADER"
)
response.headers["x-content-type-options"] = "nosniff"
return response


@main.after_request
def add_language_code(response):
language = session.get("lang", get_locale())
response.set_cookie("language", language)
response.vary.add("Accept-Language")
return response


Expand All @@ -101,7 +96,7 @@ def add_forms_to_g():

@main.before_app_request
def add_scielo_org_config_to_g():
language = session.get("lang", get_locale())
language = get_locale()
scielo_org_links = {
# if language doesnt exists set the 'en' to SciELO ORG links.
key: url.get(language, "en")
Expand All @@ -113,17 +108,18 @@ def add_scielo_org_config_to_g():
@babel.localeselector
def get_locale():
langs = current_app.config.get("LANGUAGES")
lang_from_headers = request.accept_languages.best_match(list(langs.keys()))

if "lang" not in list(session.keys()):
session["lang"] = lang_from_headers
# If user explicitly set language via set_locale, use that
if "lang" in session:
return session["lang"]

if not lang_from_headers and not session["lang"]:
# Caso não seja possível detectar o idioma e não tenhamos a chave lang
# no seção, fixamos o idioma padrão.
session["lang"] = current_app.config.get("BABEL_DEFAULT_LOCALE")
# Otherwise, use Accept-Language header
lang_from_headers = request.accept_languages.best_match(list(langs.keys()))
if lang_from_headers:
Comment on lines 109 to +118
return lang_from_headers

return session["lang"]
# Default locale
return current_app.config.get("BABEL_DEFAULT_LOCALE")
Comment on lines 108 to +122


@main.route("/set_locale/<string:lang_code>/")
Expand Down Expand Up @@ -151,16 +147,13 @@ def get_lang_from_session():
Tenta retornar o idioma da seção, caso não consiga retorna
BABEL_DEFAULT_LOCALE.
"""
try:
return session["lang"]
except KeyError:
return current_app.config.get("BABEL_DEFAULT_LOCALE")
return get_locale()


@main.route("/")
@cache.cached(key_prefix=cache_key_with_lang)
def index():
language = session.get("lang", get_locale())
language = get_locale()
news = controllers.get_latest_news_by_lang(language)

tweets = controllers.get_collection_tweets()
Expand Down Expand Up @@ -261,7 +254,7 @@ def collection_list_thematic():
@main.route("/journals/feed/")
@cache.cached(key_prefix=cache_key_with_lang)
def collection_list_feed():
language = session.get("lang", get_locale())
language = get_locale()
collection = controllers.get_current_collection()

title = "SciELO - %s - %s" % (
Expand Down Expand Up @@ -327,7 +320,7 @@ def collection_list_feed():
@main.route("/about/<string:slug_name>", methods=["GET"])
@cache.cached(key_prefix=cache_key_with_lang_with_qs)
def about_collection(slug_name=None):
language = session.get("lang", get_locale())
language = get_locale()

context = {}
page = None
Expand Down Expand Up @@ -486,7 +479,7 @@ def journal_detail(url_seg):
abort(404, JOURNAL_UNPUBLISH + _(journal.unpublish_reason))

# todo: ajustar para que seja só noticias relacionadas ao periódico
language = session.get("lang", get_locale())
language = get_locale()
news = controllers.get_latest_news_by_lang(language)

# Press releases
Expand Down Expand Up @@ -576,7 +569,7 @@ def journal_feed(url_seg):
subtitle=utils.get_label_issue(last_issue),
)

feed_language = session.get("lang", get_locale())
feed_language = get_locale()
feed_language = feed_language[:2].lower()

for article in articles:
Expand Down Expand Up @@ -607,7 +600,7 @@ def journal_feed(url_seg):
@main.route("/journal/<string:url_seg>/about/", methods=["GET"])
@cache.cached(key_prefix=cache_key_with_lang)
def about_journal(url_seg):
language = session.get("lang", get_locale())
language = get_locale()
journal = controllers.get_journal_by_url_seg(url_seg)
content = None

Expand Down Expand Up @@ -834,7 +827,7 @@ def issue_grid(url_seg):
abort(404, JOURNAL_UNPUBLISH + _(journal.unpublish_reason))

# idioma da sessão
language = session.get("lang", get_locale())
language = get_locale()

# A ordenação padrão da função ``get_issues_by_jid``: "-year", "-volume", "-order"
issues_data = controllers.get_issues_for_grid_by_jid(journal.id, is_public=True)
Expand Down Expand Up @@ -881,7 +874,7 @@ def issue_toc(url_seg, url_seg_issue):
filter_section_enable = bool(current_app.config["FILTER_SECTION_ENABLE"])

# idioma da sessão
language = session.get("lang", get_locale())
language = get_locale()

# obtém o issue
issue = controllers.get_issue_by_url_seg(url_seg, url_seg_issue)
Expand Down Expand Up @@ -1045,7 +1038,7 @@ def issue_feed(url_seg, url_seg_issue):
subtitle=utils.get_label_issue(issue),
)

feed_language = session.get("lang", get_locale())
feed_language = get_locale()

for article in articles:
# ######### TODO: Revisar #########
Expand Down
2 changes: 1 addition & 1 deletion opac/webapp/templates/admin/opac_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<small>
{% for k,v in config.LANGUAGES.items() %}
<a href="{{ url_for('main.set_locale', lang_code=k) }}">
{% if k == session['lang'] %}
{% if k == g.lang %}
<strong>{{ v }}</strong>
{% else %}
{{ v }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h2 class="logo-svg">
<div class="scielo__mainMenu" id="mainMenu">
<div class="row">
<div class="col text-center">
{%- set menu_logo_url = cimages.get_menu_logo(g.collection, session.lang)|default('')|trim -%}
{%- set menu_logo_url = cimages.get_menu_logo(g.collection, g.lang)|default('')|trim -%}
{%- if menu_logo_url -%}
{{ cimages.render_logo(menu_logo_url, coll_macro.get_collection_name(), img_class='img-fluid') }}
{%- else -%}
Expand All @@ -72,7 +72,7 @@ <h2 class="logo-svg">
</a>
</li>
<li>
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if session.lang %}{{ session.lang[:2] }}{% endif %}&filter[in][]={{config.OPAC_COLLECTION}}">
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if g.lang %}{{ g.lang[:2] }}{% endif %}&filter[in][]={{config.OPAC_COLLECTION}}">
Busca
Comment on lines 74 to 76
</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion opac/webapp/templates/article/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{% include "collection/includes/nav.html" %}
</div>
<div class="col col-md-3">
{%- set header_logo_url = cimages.get_header_logo(g.collection, session.lang)|default('')|trim -%}
{%- set header_logo_url = cimages.get_header_logo(g.collection, g.lang)|default('')|trim -%}
{%- if header_logo_url -%}
{{ cimages.render_logo(header_logo_url, coll_macro.get_collection_name(), img_class='img-fluid scielo__logo-img mt-1 ms-5') }}
{%- else -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<div class="card-body">
<div class="h6 card-subtitle mb-1">{% trans%}Volume{% endtrans %}: {{ article.issue.volume }} - {% trans%}Publicado em{% endtrans %}: {{ article.publication_date }}</div>

{% if session.lang %}
{% if g.lang %}

<strong class="card-title text-primary">
{{ article.get_title_by_lang(session.lang[:2])|default(_('Documento sem título'), true)|striptags|capitalize }}
{{ article.get_title_by_lang(g.lang[:2])|default(_('Documento sem título'), true)|striptags|capitalize }}
</strong>

{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion opac/webapp/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2 class="h4 modal-title">{% trans %}Mensagem{% endtrans %}</h2>
// Garante que o valor do campo share_url é a URL corrente.
$('#share_url').val(window.location.href);

//moment.locale('{{ session.lang }}');
//moment.locale('{{ g.lang }}');

Comment on lines 146 to 150
//$("#date").text(moment().format("L HH:mm:ss ZZ"));

Expand Down
2 changes: 1 addition & 1 deletion opac/webapp/templates/collection/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</div>
<div class="row">
<div class="col text-center">
{%- set logo_url = img_macro.get_home_logo(g.collection, session.lang)|default('')|trim -%}
{%- set logo_url = img_macro.get_home_logo(g.collection, g.lang)|default('')|trim -%}
{%- if logo_url -%}
{{ img_macro.render_logo(logo_url, coll_macro.get_collection_name()) }}
{%- else -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="container">
<form class="visually-hidden" method="get" action="{{ config.URL_SEARCH }}" id="searchForm" name="searchForm">
<input type="hidden" name="q" id="q" value="">
<input type="hidden" name="lang" id="lang" value="{% if session.lang %}{{ session.lang[:2] }}{% endif %}">
<input type="hidden" name="lang" id="lang" value="{% if g.lang %}{{ g.lang[:2] }}{% endif %}">
<input type="hidden" name="filter[in][]" value="{{ config.OPAC_COLLECTION }}">
<button type="submit">Enviar</button>
</form>
Expand Down
8 changes: 4 additions & 4 deletions opac/webapp/templates/collection/includes/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<nav style="max-height: 780px;">
<ul>
<li class="logo">
{%- set menu_logo_url = img_macro.get_menu_logo(g.collection, session.lang)|default('')|trim -%}
{%- set menu_logo_url = img_macro.get_menu_logo(g.collection, g.lang)|default('')|trim -%}
{%- if menu_logo_url -%}
{{ img_macro.render_logo(menu_logo_url, coll_macro.get_collection_name(), img_class='img-fluid') }}
{%- else -%}
Expand All @@ -32,7 +32,7 @@
</a>
</li>
<li>
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if session.lang %}{{ session.lang[:2] }}{% endif %}&filter[in][]={{config.OPAC_COLLECTION}}">
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if g.lang %}{{ g.lang[:2] }}{% endif %}&filter[in][]={{config.OPAC_COLLECTION}}">
{% trans %}Busca{% endtrans %}
</a>
</li>
Expand Down Expand Up @@ -123,10 +123,10 @@
</ul>
</li>
<li>
{% if session.lang == 'pt_BR' %}
{% if g.lang == 'pt_BR' %}
<a target="_blank" href="{{ config.URL_BLOG_SCIELO }}">
{% else %}
<a target="_blank" href="{{ config.URL_BLOG_SCIELO }}/{{ session.lang }}/">
<a target="_blank" href="{{ config.URL_BLOG_SCIELO }}/{{ g.lang }}/">
{% endif %}
<strong>{% trans %}Blog SciELO em Perspectiva{% endtrans %}</strong>
</a>
Expand Down
8 changes: 4 additions & 4 deletions opac/webapp/templates/includes/language.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<div class="dropdown">
<button type="button" class="btn btn-sm btn-secondary scielo__btn-with-icon--left dropdown-toggle mb-0 float-end mt-1" data-bs-toggle="dropdown" aria-expanded="false">
<span class="material-icons-outlined">language</span>
{% for lang_code, lang_name in session.langs.items() %}
{% for lang_code, lang_name in g.langs.items() %}

{% if session.lang == lang_code %}
{% if g.lang == lang_code %}
<span class="d-lg-none">{{lang_code}}</span>
<span class="d-none d-lg-block">{{lang_name}}</span>
{% endif %}
Expand All @@ -15,9 +15,9 @@
</button>
<ul class="dropdown-menu dropdown-menu-end">

{% for lang_code, lang_name in session.langs.items() %}
{% for lang_code, lang_name in g.langs.items() %}

{% if session.lang != lang_code %}
{% if g.lang != lang_code %}
<li><a class="dropdown-item" href="{{ url_for('.set_locale', lang_code=lang_code) }}" lang="{{lang_code}}">{{lang_name}}</a></li>
{% endif %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h2 class="logo-svg-mini">
</ul>
</li>
<li>
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if session.lang %}{{ session.lang[:2] }}{% endif %}&filter[journal_title][]={% if journal.title %}{{ journal.title }}{% endif %}" class="showTooltip" data-placement="bottom" title="{% trans %}Buscar{% endtrans %}">
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if g.lang %}{{ g.lang[:2] }}{% endif %}&filter[journal_title][]={% if journal.title %}{{ journal.title }}{% endif %}" class="showTooltip" data-placement="bottom" title="{% trans %}Buscar{% endtrans %}">
<span class="glyphBtn search"></span>
</a>
</li>
Expand Down
10 changes: 5 additions & 5 deletions opac/webapp/templates/issue/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,23 @@ <h2 class="h4 d-none">
<tr>
<td class="pt-4 pb-4" data-date="{% if article.publication_date %}{{ article.publication_date.replace('-', '') }}{% endif %}">

{% if session.lang %}
{% with nova_variavel=article.get_section_by_lang(session.lang[:2])%}
{% if g.lang %}
{% with nova_variavel=article.get_section_by_lang(g.lang[:2])%}
<!-- Aqui você pode usar 'nova_variavel' -->
{% if nova_variavel %}
<span class="badge badge-info d-inline px-2 py-1 border-0">{{ nova_variavel | safe }}</span><br>
{% endif %}
{% endwith %}
<strong class="d-block mt-2">{{ article.get_title_by_lang(session.lang[:2])|default(_('Documento sem título'), true) | safe }}</strong>
<strong class="d-block mt-2">{{ article.get_title_by_lang(g.lang[:2])|default(_('Documento sem título'), true) | safe }}</strong>
<!-- publication_date: {{article.publication_date}} -->
<!-- PID: {{article.pid}} -->
{% endif %}

<!-- Autores --->
{%- for author in article.authors_meta or article.authors %}
{% set author_name = author.name|default(author) %}
{% if session.lang %}
<a class="me-2" href="{{config['URL_SEARCH']}}?lang={{session.lang[:2]}}&q={% if author.orcid is defined and author.orcid %}orcid:{{ author.orcid }} OR au:({{ author_name }}){% else %}au:{{ author_name }}{% endif %}" target="_blank">{{- author_name|striptags -}}</a>
{% if g.lang %}
<a class="me-2" href="{{config['URL_SEARCH']}}?lang={{g.lang[:2]}}&q={% if author.orcid is defined and author.orcid %}orcid:{{ author.orcid }} OR au:({{ author_name }}){% else %}au:{{ author_name }}{% endif %}" target="_blank">{{- author_name|striptags -}}</a>
{% else %}
<a class="me-2" href="{{config['URL_SEARCH']}}?q={% if author.orcid is defined and author.orcid %}orcid:{{ author.orcid }} OR au:({{ author_name }}){% else %}au:{{ author_name }}{% endif %}" target="_blank">{{- author_name|striptags -}}</a>
{% if not loop.last %};{% endif %}
Expand Down
16 changes: 8 additions & 8 deletions opac/webapp/templates/journal/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
{# mission #}
{% if journal.mission %}
<h2 class="scielo__text-title--4">{% trans %}Nossa Missão{% endtrans %}</h2>
{% if session.lang %}
<p>{{ journal.get_mission_by_lang(session.lang[:2])|safe|default(_("Periódico sem missão cadastrada"), true) }}</p>
{% if g.lang %}
<p>{{ journal.get_mission_by_lang(g.lang[:2])|safe|default(_("Periódico sem missão cadastrada"), true) }}</p>
{% endif %}
{% endif %}
{# mission #}
Expand Down Expand Up @@ -107,8 +107,8 @@ <h3>{% trans %}Sumário{% endtrans %}</h3>

<h2 class="scielo__text-title--4">
Press-releases
{% if session.lang != "pt_BR" %}
<a href="{{ config.URL_BLOG_PRESSRELEASE }}/{{ session.lang }}/blog/category/press-releases/{{ journal.acronym }}/feed/" target="_blank" data-toggle="tooltip" data-original-title="{% trans %}RSS dos Press Releases mais recentes desse periódico{% endtrans %}"><span class="material-icons-outlined">rss_feed</span></a>
{% if g.lang != "pt_BR" %}
<a href="{{ config.URL_BLOG_PRESSRELEASE }}/{{ g.lang }}/blog/category/press-releases/{{ journal.acronym }}/feed/" target="_blank" data-toggle="tooltip" data-original-title="{% trans %}RSS dos Press Releases mais recentes desse periódico{% endtrans %}"><span class="material-icons-outlined">rss_feed</span></a>
{% else %}
<a href="{{ config.URL_BLOG_PRESSRELEASE }}/blog/category/press-releases/{{ journal.acronym }}/feed/" target="_blank" data-toggle="tooltip" data-original-title="{% trans %}RSS dos Press Releases mais recentes desse periódico{% endtrans %}"><span class="material-icons-outlined">rss_feed</span></a>
{% endif %}
Expand Down Expand Up @@ -229,8 +229,8 @@ <h2 class="scielo__text-title--4">{% trans %}Notícias{% endtrans %}</h2>
{% if journal.mission %}
<div class="col-12 col-sm-6">
<h2 class="scielo__text-title--4">{% trans %}Nossa Missão{% endtrans %}</h2>
{% if session.lang %}
<p>{{ journal.get_mission_by_lang(session.lang[:2])|safe|default(_("Periódico sem missão cadastrada"), true) }}</p>
{% if g.lang %}
<p>{{ journal.get_mission_by_lang(g.lang[:2])|safe|default(_("Periódico sem missão cadastrada"), true) }}</p>
{% endif %}
</div>
{% endif %}
Expand Down Expand Up @@ -290,8 +290,8 @@ <h3>{% trans %}Sumário{% endtrans %}</h3>
-->
<h2 class="scielo__text-title--4">
Press-releases
{% if session.lang != "pt_BR" %}
<a href="{{ config.URL_BLOG_PRESSRELEASE }}/{{ session.lang }}/blog/category/press-releases/{{ journal.acronym }}/feed/" target="_blank" data-toggle="tooltip" data-original-title="{% trans %}RSS dos Press Releases mais recentes desse periódico{% endtrans %}"><span class="material-icons-outlined">rss_feed</span></a>
{% if g.lang != "pt_BR" %}
<a href="{{ config.URL_BLOG_PRESSRELEASE }}/{{ g.lang }}/blog/category/press-releases/{{ journal.acronym }}/feed/" target="_blank" data-toggle="tooltip" data-original-title="{% trans %}RSS dos Press Releases mais recentes desse periódico{% endtrans %}"><span class="material-icons-outlined">rss_feed</span></a>
{% else %}
<a href="{{ config.URL_BLOG_PRESSRELEASE }}/blog/category/press-releases/{{ journal.acronym }}/feed/" target="_blank" data-toggle="tooltip" data-original-title="{% trans %}RSS dos Press Releases mais recentes desse periódico{% endtrans %}"><span class="material-icons-outlined">rss_feed</span></a>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h2 class="logo-svg-mini">
</ul>
</li>
<li>
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if session.lang %}{{ session.lang[:2] }}{% endif %}&filter[in][]={{config.OPAC_COLLECTION}}" class="showTooltip" data-placement="bottom" title="{% trans %}Buscar{% endtrans %}"><span class="material-icons-outlined">search</span></a>
<a href="{{ config.URL_SEARCH }}?q=*&lang={% if g.lang %}{{ g.lang[:2] }}{% endif %}&filter[in][]={{config.OPAC_COLLECTION}}" class="showTooltip" data-placement="bottom" title="{% trans %}Buscar{% endtrans %}"><span class="material-icons-outlined">search</span></a>
</li>
<li>
{% if journal.scielo_issn or journal.eletronic_issn or journal.print_issn %}
Expand Down
2 changes: 1 addition & 1 deletion opac/webapp/templates/journal/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% include "collection/includes/nav.html" %}
</div>
<div class="col col-md-3">
{%- set header_logo_url = cimages.get_header_logo(g.collection, session.lang)|default('')|trim -%}
{%- set header_logo_url = cimages.get_header_logo(g.collection, g.lang)|default('')|trim -%}
{%- if header_logo_url -%}
{{ cimages.render_logo(header_logo_url, coll_macro.get_collection_name(), img_class='img-fluid scielo__logo-img my-1 ms-5') }}
{%- else -%}
Expand Down
Loading
Loading