-
Notifications
You must be signed in to change notification settings - Fork 10
refactor: documentação de modelos legado e melhoria no acesso a dados em institution #1265
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
refactor: documentação de modelos legado e melhoria no acesso a dados em institution #1265
Conversation
…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.
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.
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 newinstitution_nameproperty
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
institution/models.py
Outdated
| @property | ||
| def instition_state_acronym(self): |
Copilot
AI
Feb 1, 2026
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.
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.
| @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. |
institution/models.py
Outdated
| @property | ||
| def instition_state_acronym(self): |
Copilot
AI
Feb 1, 2026
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.
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.
| @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. | |
| """ |
| 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 |
Copilot
AI
Feb 1, 2026
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.
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.
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.
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.
institution/models.py
Outdated
| @property | ||
| def institution_country_acronym(self): | ||
| try: | ||
| return self.institution.location.country.acron3 |
Copilot
AI
Feb 1, 2026
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.
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.
| return self.institution.location.country.acron3 | |
| return self.institution.location.country.acronym |
institution/models.py
Outdated
| def __str__(self): | ||
| try: | ||
| return self.institution.institution.institution_identification.name | ||
| return self.institution_name | ||
| except AttributeError: | ||
| return '' |
Copilot
AI
Feb 1, 2026
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.
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.
institution/models.py
Outdated
| return None | ||
|
|
||
| @property | ||
| def instition_state_acronym(self): |
Copilot
AI
Feb 1, 2026
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.
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.
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.
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.
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:
@propertypara facilitar o acesso a atributos profundamente aninhados (ex: nome da instituição, dados de localização).AttributeErroreTypeErrorem 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)institution_namepara abstrair o acesso viaInstitutionIdentification.2. BaseHistoryItem
initial_date_isoformatefinal_date_isoformatpara facilitar a serialização de datas.3. Modelos de Papéis (
Sponsor,Publisher,CopyrightHolder,Owner)article.sources,journal.models, etc.).BaseInstitution.Checklist