@@ -132,3 +132,69 @@ def to_representation(self, page_content: PageContent) -> Dict:
132132 "is_home" : page_content .page .is_home ,
133133 "languages" : page_content .page .languages .split ("," ),
134134 }
135+
136+
137+ class PreviewPageContentSerializer (PageContentSerializer ):
138+ """Serializer specifically for preview/draft page content"""
139+
140+ def to_representation (self , page_content : PageContent ) -> Dict :
141+ # Get placeholders directly from the page_content
142+ # This avoids the extra query to get_declared_placeholders
143+ placeholders = page_content .placeholders .all ()
144+
145+ placeholders_data = [
146+ {
147+ "content_type_id" : placeholder .content_type_id ,
148+ "object_id" : placeholder .object_id ,
149+ "slot" : placeholder .slot ,
150+ }
151+ for placeholder in placeholders
152+ ]
153+
154+ relative_url = page_content .page .get_absolute_url (page_content .language )
155+
156+ return {
157+ "title" : page_content .title ,
158+ "page_title" : page_content .page_title or page_content .title ,
159+ "menu_title" : page_content .menu_title or page_content .title ,
160+ "meta_description" : page_content .meta_description ,
161+ "redirect" : page_content .redirect ,
162+ "placeholders" : PlaceholderRelationSerializer (placeholders_data , many = True , context = self .context ).data ,
163+ "in_navigation" : page_content .in_navigation ,
164+ "soft_root" : page_content .soft_root ,
165+ "template" : page_content .template ,
166+ "xframe_options" : page_content .xframe_options ,
167+ "limit_visibility_in_menu" : page_content .limit_visibility_in_menu ,
168+ "language" : page_content .language ,
169+ "path" : relative_url ,
170+ "is_home" : page_content .page .is_home ,
171+ "languages" : page_content .page .languages .split ("," ),
172+ "is_preview" : True ,
173+ "creation_date" : page_content .creation_date ,
174+ }
175+
176+
177+ class PageListSerializer (BasePageSerializer ):
178+ def __init__ (self , * args , ** kwargs ):
179+ super ().__init__ (* args , ** kwargs )
180+ self .request = self .context .get ("request" )
181+
182+ def to_representation (self , page_content : PageContent ) -> Dict :
183+ relative_url = page_content .page .get_absolute_url (page_content .language )
184+
185+ return {
186+ "title" : page_content .title ,
187+ "page_title" : page_content .page_title or page_content .title ,
188+ "menu_title" : page_content .menu_title or page_content .title ,
189+ "meta_description" : page_content .meta_description ,
190+ "redirect" : page_content .redirect ,
191+ "in_navigation" : page_content .in_navigation ,
192+ "soft_root" : page_content .soft_root ,
193+ "template" : page_content .template ,
194+ "xframe_options" : page_content .xframe_options ,
195+ "limit_visibility_in_menu" : page_content .limit_visibility_in_menu ,
196+ "language" : page_content .language ,
197+ "path" : relative_url ,
198+ "is_home" : page_content .page .is_home ,
199+ "languages" : page_content .page .languages .split ("," ),
200+ }
0 commit comments