Skip to content

Commit

Permalink
Merge pull request #195 from samuelveigarangel/issue-192
Browse files Browse the repository at this point in the history
Habilita acesso à página informativa com base na coleção configurada na interface administrativa
  • Loading branch information
gitnnolabs authored Nov 4, 2024
2 parents b6bba4c + 2692c5a commit 08fc1d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
12 changes: 8 additions & 4 deletions opac/webapp/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ def add_filter_without_embargo(kwargs={}):
def get_current_collection():
"""
Retorna o objeto coleção filtrando pela coleção cadastrada no arquivo de
configuração ``OPAC_COLLECTION``.
configuração ``OPAC_COLLECTION``. Se não encontrar a configuração, tenta
retornar a primeira coleção disponível.
"""
current_collection_acronym = current_app.config["OPAC_COLLECTION"]
collection = Collection.objects.get(acronym=current_collection_acronym)
return collection
try:
current_acronym_collection = Collection.objects.get(acronym=current_app.config["OPAC_COLLECTION"])
except (KeyError, Collection.DoesNotExist):
current_acronym_collection = Collection.objects.first()

return current_acronym_collection


def get_collection_tweets():
Expand Down
18 changes: 12 additions & 6 deletions opac/webapp/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from webapp.config.lang_names import display_original_lang_name
from webapp.utils import utils
from webapp.utils.caching import cache_key_with_lang, cache_key_with_lang_with_qs
from webapp.main.errors import page_not_found, internal_server_error

from . import helper

Expand Down Expand Up @@ -639,10 +640,15 @@ def about_journal(url_seg):
else:
latest_issue_legend = None

section_journal_content = utils.fetch_and_extract_section(
collection_acronym, journal.acronym, language
)

try:
section_journal_content = utils.fetch_and_extract_section(
collection_acronym, journal.acronym, language
)
except utils.NonRetryableError as e:
return page_not_found(e)
except utils.RetryableError as e:
return internal_server_error(e)

context = {
"journal": journal,
"latest_issue_legend": latest_issue_legend,
Expand Down Expand Up @@ -1345,9 +1351,9 @@ def _handle_html():
citation_pdf_url = "{}{}".format(website, citation_pdf_url)
try:
html, text_languages = render_html(article, qs_lang, gs_abstract)
except (ValueError, NonRetryableError):
except (ValueError, utils.NonRetryableError):
abort(404, _("HTML do Artigo não encontrado ou indisponível"))
except RetryableError:
except utils.RetryableError:
abort(500, _("Erro inesperado"))

text_versions = sorted(
Expand Down
7 changes: 1 addition & 6 deletions opac/webapp/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,7 @@ def fetch_and_extract_section(collection_acronym, journal_acronym, language):
f"http://core.scielo.org/{lang}/journal/{collection_acronym}/{journal_acronym}/"
)

try:
content = fetch_data(url=url)
except NonRetryableError as e:
page_not_found(e)
except RetryableError as e:
internal_server_error(e)
content = fetch_data(url=url)

return extract_section(content, class_name)

0 comments on commit 08fc1d3

Please sign in to comment.