Adiciona campos page_type, order, parent_page e child_pages#116
Adiciona campos page_type, order, parent_page e child_pages#116samuelveigarangel wants to merge 6 commits intoscieloorg:masterfrom
Conversation
|
Oi @samuelveigarangel, tudo bem? Esse pull request possui alguma issue onde eu possa ler sobre a finalidade do PR? Obrigado. |
There was a problem hiding this comment.
Pull Request Overview
This PR adds hierarchical page structure capabilities to the Pages model by introducing parent-child relationships and page ordering. The changes enable pages to be organized in a tree-like structure with different page types.
- Adds
page_typefield with predefined choices for categorizing pages - Introduces
orderfield for page sequencing and parent/child page references - Implements automatic parent-child relationship management in the save method
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
opac_schema/v1/models.py
Outdated
|
|
||
| # garante que ela esteja em child_pages do pai | ||
| if self.parent_page: | ||
| parent = self.page_type |
There was a problem hiding this comment.
Variable assignment is incorrect. Should be parent = self.parent_page instead of parent = self.page_type. The code is trying to get the parent page object but is incorrectly assigning the page type string.
| parent = self.page_type | |
| parent = self.parent_page |
opac_schema/v1/models.py
Outdated
| parent = self.page_type | ||
| # evita referência a si mesmo e duplicação | ||
| if parent.id != self.id and self not in (parent.child_pages or []): | ||
| parent.child_pages = (parent.child_pages or []) + [self] | ||
| super(Pages, self).save() |
There was a problem hiding this comment.
This save call will cause infinite recursion. When saving the parent page, it will trigger its own save method, which may lead to a stack overflow. Consider using update() method or adding a flag to prevent recursive saves.
| parent = self.page_type | |
| # evita referência a si mesmo e duplicação | |
| if parent.id != self.id and self not in (parent.child_pages or []): | |
| parent.child_pages = (parent.child_pages or []) + [self] | |
| super(Pages, self).save() | |
| parent = self.parent_page | |
| # evita referência a si mesmo e duplicação | |
| if parent.id != self.id and self not in (parent.child_pages or []): | |
| parent.update(push__child_pages=self) |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| # garante que ela esteja em child_pages do pai | ||
| if self.parent_page: | ||
| parent = self.parent_page | ||
| if parent.id != self.id and self not in (parent.child_pages or []): |
There was a problem hiding this comment.
The condition self not in (parent.child_pages or []) will always be True because self is a Pages instance while parent.child_pages contains ObjectId references. This comparison should use self.id instead of self.
| if parent.id != self.id and self not in (parent.child_pages or []): | |
| if parent.id != self.id and self.id not in (parent.child_pages or []): |
| result = super(Pages, self).save(*args, **kwargs) | ||
|
|
||
| # garante que ela esteja em child_pages do pai | ||
| if self.parent_page: |
There was a problem hiding this comment.
The parent-child relationship update logic executes on every save operation, even when parent_page hasn't changed. Consider checking if parent_page is dirty before performing the update to avoid unnecessary database operations.
| if self.parent_page: | |
| # Só atualiza se parent_page foi alterado ou se o documento é novo | |
| parent_page_dirty = ( | |
| not self.pk or # documento novo | |
| hasattr(self, '_changed_fields') and 'parent_page' in self._changed_fields | |
| ) | |
| if self.parent_page and parent_page_dirty: |
O que esse PR faz?
Adiciona campo page_type para tipo da página
Adiciona campo order
Adiciona campos parent_page e child_pages para referencias página pai e subpáginas.
Onde a revisão poderia começar?
pelos commits
Como este poderia ser testado manualmente?
referênciar no requirements.txt no projeto opac_5:
git+https://github.com/samuelveigarangel/opac_schema.git@issue-115#egg=opac_schemaAcessar a interface administrativa -> Pages
Algum cenário de contexto que queira dar?
N/A
Screenshots
Quais são tickets relevantes?
#115
Referências
N/A