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
72 changes: 72 additions & 0 deletions packtools/sps/models/article_doi_with_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def data(self):
fullname = f'{contrib_name["surname"]}, {contrib_name["given-names"]}'
xml_authors.append(fullname)
except KeyError:
# Ignore authors that do not have complete name information
pass

try:
Expand Down Expand Up @@ -97,3 +98,74 @@ def data(self):
}
)
return _data

@property
def all_data(self):
"""
Similar a data(), mas captura TODOS os sub-articles,
não apenas translations.

Usado para validações que precisam verificar todos os tipos
de sub-article (reviewer-report, correction, addendum, etc.)

Returns:
list of dict: Lista de dicionários contendo:
- lang: idioma do artigo/sub-article
- value: valor do DOI
- parent: 'article' ou 'sub-article'
- parent_article_type: tipo do artigo
- parent_id: id do sub-article (se aplicável)
- article_title: título do artigo
- authors: lista de autores
"""
xml_authors = []
for author in self.authors:
try:
contrib_name = author["contrib_name"]
fullname = f'{contrib_name["surname"]}, {contrib_name["given-names"]}'
xml_authors.append(fullname)
except KeyError:
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

'except' clause does nothing but pass and there is no explanatory comment.

Suggested change
except KeyError:
except KeyError:
# Ignore authors that do not have complete name information

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Corrigido. Adicionado comentário "# Ignore authors that do not have complete name information" nos blocos except KeyError para documentar comportamento intencional de ignorar autores com dados incompletos.

# Ignore authors that do not have complete name information
pass

try:
article_titles = self.titles.get(self.main_lang).get("plain_text")
except AttributeError:
article_titles = None

_data = [
{
"lang": self.main_lang,
"value": self.main_doi,
"parent": "article",
"parent_article_type": self._xmltree.get("article-type"),
"article_title": article_titles,
"authors": xml_authors,
}
]

# Captura TODOS os sub-articles, não apenas translations
for sub_article in self._xmltree.xpath(".//sub-article"):
lang = sub_article.get("{http://www.w3.org/XML/1998/namespace}lang")
value = self._get_node_text(
'.//article-id[@pub-id-type="doi"]', sub_article
)
article_type = sub_article.get("article-type")

try:
article_titles = self.titles.get(lang).get("plain_text")
except AttributeError:
article_titles = None

_data.append(
{
"lang": lang,
"value": value,
"parent": "sub-article",
"parent_article_type": article_type,
"parent_id": sub_article.get("id"),
"article_title": article_titles,
"authors": xml_authors,
}
)
return _data
Loading