Skip to content

Comments

Adiciona campos page_type, order, parent_page e child_pages#116

Open
samuelveigarangel wants to merge 6 commits intoscieloorg:masterfrom
samuelveigarangel:issue-115
Open

Adiciona campos page_type, order, parent_page e child_pages#116
samuelveigarangel wants to merge 6 commits intoscieloorg:masterfrom
samuelveigarangel:issue-115

Conversation

@samuelveigarangel
Copy link
Contributor

@samuelveigarangel samuelveigarangel commented Oct 7, 2025

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_schema

Acessar a interface administrativa -> Pages

Algum cenário de contexto que queira dar?

N/A

Screenshots

image

Quais são tickets relevantes?

#115

Referências

N/A

@joffilyfe
Copy link

Oi @samuelveigarangel, tudo bem? Esse pull request possui alguma issue onde eu possa ler sobre a finalidade do PR? Obrigado.

@samuelveigarangel samuelveigarangel changed the title diciona campos page_tpe, order, parent_page e child_pages Adiciona campos page_type, order, parent_page e child_pages Oct 7, 2025
@samuelveigarangel
Copy link
Contributor Author

@joffilyfe #115

Copy link

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 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_type field with predefined choices for categorizing pages
  • Introduces order field 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.


# garante que ela esteja em child_pages do pai
if self.parent_page:
parent = self.page_type
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
parent = self.page_type
parent = self.parent_page

Copilot uses AI. Check for mistakes.
Comment on lines 89 to 93
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()
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Copy link

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 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 []):
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
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 []):

Copilot uses AI. Check for mistakes.
result = super(Pages, self).save(*args, **kwargs)

# garante que ela esteja em child_pages do pai
if self.parent_page:
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
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:

Copilot uses AI. Check for mistakes.
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.

2 participants