feat: maintain placeholder order from template declaration#91
Closed
metaforx wants to merge 3 commits intodjango-cms:mainfrom
Closed
feat: maintain placeholder order from template declaration#91metaforx wants to merge 3 commits intodjango-cms:mainfrom
metaforx wants to merge 3 commits intodjango-cms:mainfrom
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts PageContentSerializer to preserve the placeholder order as declared in the template instead of relying on queryset ordering, by mapping existing placeholders to the template-declared placeholders and serializing them in that order. Sequence diagram for PageContentSerializer placeholder orderingsequenceDiagram
actor FrontendClient
participant APIView
participant PageContentSerializer
participant PageContent
participant PlaceholderSerializer
FrontendClient->>APIView: GET page_content
APIView->>PageContentSerializer: instantiate with context(request)
APIView->>PageContentSerializer: to_representation(page_content)
PageContentSerializer->>PageContent: placeholders.all()
PageContent-->>PageContentSerializer: placeholders_queryset
PageContentSerializer->>PageContentSerializer: placeholder_map = {slot: placeholder}
PageContentSerializer->>PageContentSerializer: declared_placeholders = get_declared_placeholders_for_obj(page_content)
PageContentSerializer->>PageContentSerializer: placeholders = [placeholder_map[declared.slot] for declared in declared_placeholders if declared.slot in placeholder_map]
PageContentSerializer->>PageContentSerializer: data = get_base_representation(page_content)
PageContentSerializer->>PlaceholderSerializer: serialize(placeholders, many=True)
PlaceholderSerializer-->>PageContentSerializer: placeholders_data
PageContentSerializer-->>APIView: data with ordered placeholders
APIView-->>FrontendClient: JSON response
Class diagram for updated PageContentSerializer placeholder handlingclassDiagram
class BasePageSerializer
class BasePageContentMixin
class PageContentSerializer {
+placeholders PlaceholderSerializer[]
+request any
+to_representation(page_content PageContent) dict
}
class PageContent {
+placeholders Placeholder[]
}
class Placeholder {
+slot str
}
class DeclaredPlaceholder {
+slot str
}
class PlaceholderSerializer {
+many bool
}
PageContentSerializer --|> BasePageSerializer
PageContentSerializer ..|> BasePageContentMixin
PageContent "1" --> "*" Placeholder : placeholders
PageContentSerializer --> PageContent : serializes
PageContentSerializer --> PlaceholderSerializer : uses
PageContentSerializer --> DeclaredPlaceholder : orders_by
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #91 +/- ##
=======================================
Coverage 91.98% 91.98%
=======================================
Files 19 19
Lines 886 886
Branches 100 100
=======================================
Hits 815 815
Misses 44 44
Partials 27 27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
@metaforx This PR seems to be empty? |
Collaborator
Author
This is strange. I see 2 commits. Pages.py contains the changes. I check why containing commit is not respected. |
Member
Member
|
Are these changes contained in #83 ? |
Collaborator
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

I could fix this behavior with the suggested PR. There might be a cleaner solution.
Summary by Sourcery
Enhancements: