From 24e374aa569ac364b5ca977977017c42c4398e30 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:47:29 +0000 Subject: [PATCH 1/3] Initial plan From 6c28584585a8282e681e19ceff798d2acad69ab1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:51:04 +0000 Subject: [PATCH 2/3] Add get_absolute_url filter and update logo URL in meta templates Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> --- opac/webapp/__init__.py | 1 + opac/webapp/main/custom_filters.py | 25 +++++++++++++++++++ .../templates/article/includes/meta.html | 2 +- .../webapp/templates/issue/includes/meta.html | 2 +- .../templates/journal/includes/meta.html | 2 +- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/opac/webapp/__init__.py b/opac/webapp/__init__.py index e25bd0505..633d3e790 100644 --- a/opac/webapp/__init__.py +++ b/opac/webapp/__init__.py @@ -150,6 +150,7 @@ def create_app(): # Registrando os filtros app.jinja_env.filters["trans_alpha2"] = custom_filters.trans_alpha2 app.jinja_env.filters["datetimefilter"] = custom_filters.datetimefilter + app.jinja_env.filters["get_absolute_url"] = custom_filters.get_absolute_url # i18n babel.init_app(app) diff --git a/opac/webapp/main/custom_filters.py b/opac/webapp/main/custom_filters.py index 5a5aca914..0da9f3163 100644 --- a/opac/webapp/main/custom_filters.py +++ b/opac/webapp/main/custom_filters.py @@ -17,3 +17,28 @@ def trans_alpha2(value): def datetimefilter(value, format="%Y-%m-%d %H:%M"): return utc_to_local(value).strftime(format) + + +def get_absolute_url(url, base_url=""): + """ + Returns an absolute URL. If the URL already starts with http:// or https://, + returns it as-is. Otherwise, concatenates base_url with url. + + Args: + url: The URL to process (may be relative or absolute) + base_url: The base URL to prepend if url is relative (default: "") + + Returns: + An absolute URL string + """ + if not url: + return "" + + # Check if URL is already absolute + if url.startswith("http://") or url.startswith("https://"): + return url + + # URL is relative, concatenate with base_url + # Remove leading slash from url if present, as base_url should handle it + url_cleaned = url.lstrip("/") + return f"{base_url}{url_cleaned}" diff --git a/opac/webapp/templates/article/includes/meta.html b/opac/webapp/templates/article/includes/meta.html index b77476482..767bbfea4 100644 --- a/opac/webapp/templates/article/includes/meta.html +++ b/opac/webapp/templates/article/includes/meta.html @@ -4,7 +4,7 @@ - + {% if article.authors_meta -%} diff --git a/opac/webapp/templates/issue/includes/meta.html b/opac/webapp/templates/issue/includes/meta.html index 2c7255ef2..5f9d68c27 100644 --- a/opac/webapp/templates/issue/includes/meta.html +++ b/opac/webapp/templates/issue/includes/meta.html @@ -5,5 +5,5 @@ - + diff --git a/opac/webapp/templates/journal/includes/meta.html b/opac/webapp/templates/journal/includes/meta.html index 87dc17c0c..0fbc95f99 100644 --- a/opac/webapp/templates/journal/includes/meta.html +++ b/opac/webapp/templates/journal/includes/meta.html @@ -4,5 +4,5 @@ - + From 67610c7d74f58e47041ed80be152150c777810d1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:53:06 +0000 Subject: [PATCH 3/3] Add tests for get_absolute_url custom filter Co-authored-by: robertatakenaka <505143+robertatakenaka@users.noreply.github.com> --- opac/tests/test_main_custom_filters.py | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 opac/tests/test_main_custom_filters.py diff --git a/opac/tests/test_main_custom_filters.py b/opac/tests/test_main_custom_filters.py new file mode 100644 index 000000000..1552acaf6 --- /dev/null +++ b/opac/tests/test_main_custom_filters.py @@ -0,0 +1,57 @@ +# coding: utf-8 +from webapp.main.custom_filters import get_absolute_url + +from .base import BaseTestCase + + +class CustomFiltersTestCase(BaseTestCase): + """Test cases for custom Jinja2 filters in webapp.main.custom_filters""" + + def test_get_absolute_url_with_absolute_http_url(self): + """Test that absolute HTTP URLs are returned as-is""" + url = "http://example.com/logo.png" + base_url = "http://scielo.do/" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "http://example.com/logo.png") + + def test_get_absolute_url_with_absolute_https_url(self): + """Test that absolute HTTPS URLs are returned as-is""" + url = "https://example.com/logo.png" + base_url = "http://scielo.do/" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "https://example.com/logo.png") + + def test_get_absolute_url_with_relative_url_with_slash(self): + """Test that relative URLs with leading slash are concatenated correctly""" + url = "/media/logo.png" + base_url = "http://scielo.do/" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "http://scielo.do/media/logo.png") + + def test_get_absolute_url_with_relative_url_without_slash(self): + """Test that relative URLs without leading slash are concatenated correctly""" + url = "media/logo.png" + base_url = "http://scielo.do/" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "http://scielo.do/media/logo.png") + + def test_get_absolute_url_with_empty_url(self): + """Test that empty URLs return empty string""" + url = "" + base_url = "http://scielo.do/" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "") + + def test_get_absolute_url_with_none_url(self): + """Test that None URLs return empty string""" + url = None + base_url = "http://scielo.do/" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "") + + def test_get_absolute_url_with_empty_base_url(self): + """Test that relative URLs with empty base_url work""" + url = "/media/logo.png" + base_url = "" + result = get_absolute_url(url, base_url) + self.assertEqual(result, "media/logo.png")