-
Notifications
You must be signed in to change notification settings - Fork 24
feat: implementa validações completas para elemento <article-id> conforme especificação SPS #1069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rossi-Luciano
wants to merge
7
commits into
scieloorg:master
Choose a base branch
from
Rossi-Luciano:feature/article-id-validation-i18n
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+963
−198
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ccd42e
feat: implementa validações completas para elemento <article-id>
Rossi-Luciano 6e27a7c
feat: adiciona propriedade all_data ao modelo ArticleDOIWithLang
Rossi-Luciano cb2e40a
feat: cria classe ArticleOtherValidation para validações de other
Rossi-Luciano e4f19bd
fix: corrige regex de validação de formato DOI
Rossi-Luciano e858e94
test: expande testes para validações de <article-id>
Rossi-Luciano 1b03ab0
test: adiciona testes para propriedade all_data
Rossi-Luciano 71df3f6
test: cria suite completa de testes para ArticleOtherValidation
Rossi-Luciano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| class OtherWithLang: | ||
| """ | ||
| Extrai dados de <article-id pub-id-type="other"> | ||
|
|
||
| Similar a DoiWithLang, mas para o elemento 'other'. | ||
| Usado para validações de publicação contínua (PC) e ordenação. | ||
|
|
||
| Example: | ||
| <article-id pub-id-type="other">00123</article-id> | ||
|
|
||
| O elemento 'other' é obrigatório para: | ||
| - Periódicos em modalidade de Publicação Contínua (PC) | ||
| - Periódicos em modalidade regular com paginação irregular | ||
|
|
||
| O formato deve ser exatamente 5 dígitos numéricos (00001-99999) | ||
| """ | ||
|
|
||
| def __init__(self, xmltree): | ||
| self._xmltree = xmltree | ||
|
|
||
| def _get_node(self, xpath, node=None): | ||
| if node is None: | ||
| node = self._xmltree | ||
| try: | ||
| return node.xpath(xpath)[0] | ||
| except IndexError: | ||
| return None | ||
|
|
||
| def _get_node_text(self, xpath, node=None): | ||
| if node is None: | ||
| node = self._xmltree | ||
| try: | ||
| return self._get_node(xpath, node).text | ||
| except AttributeError: | ||
| return None | ||
|
|
||
| @property | ||
| def main_other(self): | ||
| """ | ||
| Retorna o valor de other do artigo principal. | ||
|
|
||
| Returns: | ||
| str or None: Valor do other (ex: "00123") ou None se não existir | ||
| """ | ||
| return self._get_node_text('.//front//article-id[@pub-id-type="other"]') | ||
|
|
||
| @property | ||
| def main_lang(self): | ||
| """ | ||
| Retorna o idioma do artigo principal. | ||
|
|
||
| Returns: | ||
| str: Código do idioma (ex: "en", "pt", "es") | ||
| """ | ||
| return self._xmltree.find(".").get("{http://www.w3.org/XML/1998/namespace}lang") | ||
|
|
||
| @property | ||
| def data(self): | ||
| """ | ||
| Retorna lista de dicionários com informações sobre other | ||
| em article e todos os sub-articles. | ||
|
|
||
| Returns: | ||
| list of dict: Lista de dicionários contendo: | ||
| - lang: idioma do artigo/sub-article | ||
| - value: valor do other (ex: "00123") | ||
| - parent: 'article' ou 'sub-article' | ||
| - parent_article_type: tipo do artigo | ||
| - parent_id: id do sub-article (se aplicável) | ||
|
|
||
| Example: | ||
| [ | ||
| { | ||
| 'lang': 'en', | ||
| 'value': '00123', | ||
| 'parent': 'article', | ||
| 'parent_article_type': 'research-article' | ||
| }, | ||
| { | ||
| 'lang': 'pt', | ||
| 'value': '00124', | ||
| 'parent': 'sub-article', | ||
| 'parent_article_type': 'translation', | ||
| 'parent_id': 's1' | ||
| } | ||
| ] | ||
| """ | ||
| _data = [ | ||
| { | ||
| "lang": self.main_lang, | ||
| "value": self.main_other, | ||
| "parent": "article", | ||
| "parent_article_type": self._xmltree.get("article-type"), | ||
| } | ||
| ] | ||
|
|
||
| # Captura todos os sub-articles | ||
| 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="other"]', sub_article | ||
| ) | ||
|
|
||
| _data.append({ | ||
| "lang": lang, | ||
| "value": value, | ||
| "parent": "sub-article", | ||
| "parent_article_type": sub_article.get("article-type"), | ||
| "parent_id": sub_article.get("id"), | ||
| }) | ||
| return _data |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.