Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .envs/.local/.django
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ USE_OPENSEARCH_LOGGING=no
# OPENSEARCH_LOGGING_HOSTS=http://opensearch:9200
# OPENSEARCH_LOGGING_ENVIRONMENT=dev
# OPENSEARCH_LOGGING_LEVEL=INFO

# Link para o site antigo (old.scielo.org) no cabeçalho
SCIELO_OLD_URL_ENABLED=False
3 changes: 3 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,9 @@


# LINK TO OLD SCIELO
# Habilita/desabilita a exibição do link para o site antigo no cabeçalho
SCIELO_OLD_URL_ENABLED = env.bool("SCIELO_OLD_URL_ENABLED", default=False)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Com default=False, o link deixa de aparecer em produção no próximo deploy, a menos que alguém defina a variável. A descrição avisa, mas .envs/.production/.django (versionado) não foi atualizado, então o aviso depende de alguém lê-lo na hora do deploy.

Duas opções: manter o comportamento atual com default=True e deixar a desativação como escolha explícita; ou incluir SCIELO_OLD_URL_ENABLED=True em .envs/.production/.django neste PR.

# Deve começar com http:// ou https://; o texto do link é a URL sem o protocolo
SCIELO_OLD_URL = env.str("SCIELO_OLD_URL", default="http://old.scielo.org/")

# Score mínimo (percentual_score) para considerar um candidato de PidProviderXML como aprovado
Expand Down
23 changes: 22 additions & 1 deletion core/home/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from urllib.parse import urlparse

from django.conf import settings
from django.db import models
from django.db.models import Prefetch, Q
Expand Down Expand Up @@ -74,10 +76,29 @@ def default_journal_filter(search_term, starts_with_letter, active_or_discontinu

def _default_context(context):
context["social_networks"] = get_social_networks("scl")
context["old_scielo_url"] = settings.SCIELO_OLD_URL
context["old_scielo_link"] = get_old_scielo_link()
context["page_about"] = get_page_about()


def get_old_scielo_link():
"""
Retorna o link para o site antigo como {"url": ..., "label": ...},
ou None se o link estiver desabilitado (SCIELO_OLD_URL_ENABLED=False).
SCIELO_OLD_URL deve começar com http:// ou https://; caso contrário,
usa o valor padrão. O label é a URL sem o protocolo.
"""
if not getattr(settings, "SCIELO_OLD_URL_ENABLED", True):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O fallback do getattr é True, mas o settings define False. Na prática o True nunca é usado, porque base.py sempre define a variável, mas quem lê a função entende o contrário. Como o settings sempre existe, dá para simplificar:

Suggested change
if not getattr(settings, "SCIELO_OLD_URL_ENABLED", True):
if not settings.SCIELO_OLD_URL_ENABLED:

return None

default_url = "http://old.scielo.org/"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "http://old.scielo.org/" está repetido aqui e no default de base.py:733. Se um mudar, o outro fica para trás. Uma opção é uma constante única, por exemplo SCIELO_OLD_URL_DEFAULT no settings.

url = (getattr(settings, "SCIELO_OLD_URL", None) or "").strip()
if urlparse(url).scheme not in ("http", "https"):
url = default_url
Comment on lines +95 to +96

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uma URL com esquema válido mas sem host (http://, https:///) passa na checagem e gera {"url": "http://", "label": ""}. Confirmei na interface: o cabeçalho renderiza <a href="http://" target="_blank"></a>, vazio, com o link "habilitado" e sem voltar ao padrão. Checar também o netloc resolve:

Suggested change
if urlparse(url).scheme not in ("http", "https"):
url = default_url
parsed = urlparse(url)
if parsed.scheme not in ("http", "https") or not parsed.netloc:
url = default_url


label = url.split("://", 1)[1].rstrip("/")
return {"url": url, "label": label}


def get_page_about():
try:
locale = _get_current_locale()
Expand Down
6 changes: 4 additions & 2 deletions core/templates/home/scieloorg/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<div class="container">
<div class="row p-4">
<div class="col d-flex align-items-center">
{% if old_scielo_link %}
<ul class="list-unstyled d-flex align-items-center gap-2 mb-0">
<li>
<a href="{{old_scielo_url}}" target="_blank">
old.scielo.org
<a href="{{ old_scielo_link.url }}" target="_blank">
{{ old_scielo_link.label }}
</a>
</li>
</ul>
{% endif %}
</div>
<div class="col d-flex justify-content-end align-items-center">
<ul class="list-unstyled d-flex align-items-center gap-2 mb-0">
Expand Down
Loading