Skip to content

Conversation

@robertatakenaka
Copy link
Member

@robertatakenaka robertatakenaka commented Feb 1, 2026

Descrição

Este PR introduz melhorias significativas na manutenibilidade e legibilidade do módulo institution, preparando o terreno para a transição completa para o novo sistema de organizações (version 2).

As alterações focam em três pilares:

  1. Documentação de Dependências: Adição de docstrings detalhadas em classes legado, mapeando onde cada modelo é referenciado em outros módulos (tasks, migrations, scripts).
  2. Encapsulamento e Robustez: Implementação de @property para facilitar o acesso a atributos profundamente aninhados (ex: nome da instituição, dados de localização).
  3. Prevenção de Erros: Tratamento de AttributeError e TypeError em métodos de acesso para garantir que instâncias com relações nulas não causem exceções em tempo de execução.

Alterações Principais

1. Modelos de Instituição (Institution, InstitutionHistory, BaseInstitution)

  • Adição da property institution_name para abstrair o acesso via InstitutionIdentification.
  • Melhoria no tratamento de erros ao acessar objetos relacionados.
  • Documentação detalhada sobre o papel de cada classe como "Versão 1 - Legado".

2. BaseHistoryItem

  • Refatoração profunda dos getters de localização (cidade, estado, país).
  • Adição dos métodos initial_date_isoformat e final_date_isoformat para facilitar a serialização de datas.

3. Modelos de Papéis (Sponsor, Publisher, CopyrightHolder, Owner)

  • Inclusão de mapeamento de uso em sistemas externos (article.sources, journal.models, etc.).
  • Garantia de que herdam as novas propriedades de acesso facilitado de BaseInstitution.

Checklist

  • Docstrings atualizadas com referências de uso.
  • Tratamento de exceções para campos nulos/vazios.
  • Propriedades adicionadas para simplificar chamadas em templates e serializers.
  • Código formatado seguindo os padrões do projeto.

…ution

- Adição de docstrings detalhando o uso de modelos legado (v1).
- Implementação de propriedades getter para acesso simplificado a nomes e locais.
- Padronização de métodos de data e strings para evitar AttributeError.
Copilot AI review requested due to automatic review settings February 1, 2026 18:27
@robertatakenaka robertatakenaka changed the title Melhora documentação e adiciona atalhos para acesso a dados de Instit… refactor: documentação de modelos legado e melhoria no acesso a dados em institution Feb 1, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves documentation and adds convenience properties for legacy (v1) institution models that are being gradually replaced by version 2 organization models.

Changes:

  • Added comprehensive docstrings to Institution, InstitutionHistory, BaseHistoryItem, BaseInstitution, and related models documenting their usage and legacy status
  • Implemented getter properties for simplified access to institution names and location data
  • Added date ISO format properties for easier date serialization
  • Refactored the __str__ method in BaseHistoryItem to use the new institution_name property

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 519 to 520
@property
def instition_state_acronym(self):
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The property name "instition_state_acronym" contains a typo (missing 't' in "institution"). While this maintains backward compatibility with existing usage in journal/formats/articlemeta_format.py:199, consider adding a correctly-spelled alias property "institution_state_acronym" and deprecating the misspelled version to allow for eventual migration.

Suggested change
@property
def instition_state_acronym(self):
@property
def institution_state_acronym(self):
"""
Alias for the deprecated `instition_state_acronym` property.
Prefer using this correctly spelled name in new code.
"""
return self.instition_state_acronym
@property
def instition_state_acronym(self):
# Deprecated: use `institution_state_acronym` instead. Kept for backward compatibility.

Copilot uses AI. Check for mistakes.
Comment on lines 605 to 606
@property
def instition_state_acronym(self):
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The property name "instition_state_acronym" contains a typo (missing 't' in "institution"). While this maintains backward compatibility with existing usage in journal/formats/articlemeta_format.py:199, consider adding a correctly-spelled alias property "institution_state_acronym" and deprecating the misspelled version to allow for eventual migration.

Suggested change
@property
def instition_state_acronym(self):
@property
def institution_state_acronym(self):
"""
Preferred alias for `instition_state_acronym`.
"""
return self.instition_state_acronym
@property
def instition_state_acronym(self):
"""
Deprecated: use `institution_state_acronym` instead.
"""

Copilot uses AI. Check for mistakes.
Comment on lines 488 to 525
def institution_city_name(self):
try:
return self.institution.institution.location.city.name
# self.institution é instância de (Sponsor | Publisher | CopyrightHolder | Owner | EditorialManager)
return self.institution.location.city.name
except AttributeError:
return None

@property
def institution_country_name(self):
try:
return self.institution.institution.location.country.name
# self.institution é instância de (Sponsor | Publisher | CopyrightHolder | Owner | EditorialManager)
return self.institution.location.country.name
except AttributeError:
return None

@property
def institution_country_acronym(self):
try:
return self.institution.institution.location.country.acronym
# self.institution é instância de (Sponsor | Publisher | CopyrightHolder | Owner | EditorialManager)
return self.institution.location.country.acronym
except AttributeError:
return None

@property
def institution_state_name(self):
try:
return self.institution.institution.location.state.name
# self.institution é instância de (Sponsor | Publisher | CopyrightHolder | Owner | EditorialManager)
return self.institution.location.state.name
except AttributeError:
return None

@property
def instition_state_acronym(self):
try:
return self.institution.institution.location.state.acronym
# self.institution é instância de (Sponsor | Publisher | CopyrightHolder | Owner | EditorialManager)
return self.institution.location.state.acronym
except AttributeError:
return None
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

Critical bug: These properties attempt to access location data directly from self.institution.location, but self.institution is an instance of Sponsor/Publisher/CopyrightHolder/Owner/EditorialManager (which inherit from BaseInstitution), not Institution. The correct access path should be self.institution.institution.location since BaseInstitution has an 'institution' field that is a ForeignKey to Institution. This will cause AttributeError when these properties are called, as Publisher/Sponsor/etc. don't have a 'location' attribute directly.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@property
def institution_country_acronym(self):
try:
return self.institution.location.country.acron3
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

Inconsistent property implementation: The property returns country.acron3 (3-character code) while the same property name institution_country_acronym in BaseHistoryItem (line 510) returns country.acronym (2-character code). This creates an inconsistency where the same property name returns different country code formats depending on which class is being used. Consider either using the same attribute for both (likely country.acronym for consistency) or renaming this property to institution_country_acron3 to clearly differentiate it from the 2-character version.

Suggested change
return self.institution.location.country.acron3
return self.institution.location.country.acronym

Copilot uses AI. Check for mistakes.
Comment on lines 473 to 477
def __str__(self):
try:
return self.institution.institution.institution_identification.name
return self.institution_name
except AttributeError:
return ''
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The str method may return None when institution_name property returns None. The try-except block catches AttributeError, but the property itself handles exceptions and returns None instead of raising them. This means that when institution_name is None, str will return None rather than an empty string as intended by the except clause. Consider changing line 475 to use 'return self.institution_name or ""' to ensure a string is always returned.

Copilot uses AI. Check for mistakes.
return None

@property
def instition_state_acronym(self):
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

The property name has a typo: "instition_state_acronym" should be "institution_state_acronym" (missing "u" in "institution"). This is currently being used in journal/formats/articlemeta_format.py line 199, so fixing this will require updating that reference as well.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@robertatakenaka robertatakenaka merged commit 74233d2 into scieloorg:main Feb 1, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant