File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
djangocms_rest/serializers Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -131,17 +131,27 @@ def to_representation(self, page_content: PageContent) -> dict:
131131
132132
133133class PageContentSerializer (BasePageSerializer , BasePageContentMixin ):
134+ """
135+ Serialize the page content with the placeholders in the order they are declared in the template.
136+ """
134137 placeholders = PlaceholderSerializer (many = True , required = False )
135138
136139 def __init__ (self , * args , ** kwargs ):
137140 super ().__init__ (* args , ** kwargs )
138141 self .request = self .context .get ("request" )
139142
140143 def to_representation (self , page_content : PageContent ) -> dict :
141- declared_slots = [placeholder .slot for placeholder in get_declared_placeholders_for_obj (page_content )]
144+ declared_placeholders = get_declared_placeholders_for_obj (page_content )
145+ placeholder_map = {
146+ placeholder .slot : placeholder
147+ for placeholder in page_content .placeholders .all ()
148+ }
142149 placeholders = [
143- placeholder for placeholder in page_content .placeholders .all () if placeholder .slot in declared_slots
150+ placeholder_map [declared .slot ]
151+ for declared in declared_placeholders
152+ if declared .slot in placeholder_map
144153 ]
154+
145155 data = self .get_base_representation (page_content )
146156 data ["placeholders" ] = PlaceholderSerializer (
147157 placeholders ,
You can’t perform that action at this time.
0 commit comments