@@ -82,6 +82,11 @@ def render_cms_plugin(
82
82
'<div class="indent">{value}</div></details>{close}<span class="sep">,</span>'
83
83
)
84
84
85
+ # Tempalte for a non-collasable object/list
86
+ FIXED_TEMPLATE = (
87
+ '{open}<div class="indent">{value}</div>{close}<span class="sep">,</span>'
88
+ )
89
+
85
90
# Tempalte for a single line key-value pair
86
91
SIMPLE_TEMPLATE = (
87
92
'<span class="key">"{key}"</span>: {value}<span class="sep">,</span>'
@@ -137,13 +142,14 @@ def highlight_json(
137
142
for key , value in json_data .items ()
138
143
]
139
144
if has_children :
140
- rendered_children = DETAILS_TEMPLATE .format (
141
- key = escape (field ),
142
- value = '' .join (children ),
143
- open = '[' ,
144
- close = ']' ,
145
+ items .append (
146
+ DETAILS_TEMPLATE .format (
147
+ key = escape (field ),
148
+ value = '' .join (children ),
149
+ open = '[' ,
150
+ close = ']' ,
151
+ )
145
152
)
146
- items .append (rendered_children )
147
153
return {
148
154
"open" : '{' ,
149
155
"close" : '}' ,
@@ -165,6 +171,7 @@ class RESTRenderer(ContentRenderer):
165
171
A custom renderer that uses the render_cms_plugin function to render
166
172
CMS plugins in a RESTful way.
167
173
"""
174
+ placeholder_edit_template = "{content}{plugin_js}{placeholder_js}"
168
175
169
176
def render_plugin (
170
177
self , instance , context , placeholder = None , editable : bool = False
@@ -208,13 +215,22 @@ def render_plugins(
208
215
render_plugins = False ,
209
216
).data
210
217
211
- yield OBJ_TEMPLATE .format (
218
+ yield FIXED_TEMPLATE .format (
219
+ placeholder_id = placeholder .pk ,
212
220
** highlight_json (
213
221
placeholder_data ,
214
- children = super (). render_plugins (
222
+ children = self . get_plugins_and_placeholder_lot (
215
223
placeholder , language , context , editable = editable , template = template
216
224
),
217
225
field = "content" ,
218
226
)
219
227
)
220
228
yield "</div>"
229
+
230
+ def get_plugins_and_placeholder_lot (
231
+ self , placeholder , language , context , editable = False , template = None
232
+ ) -> Iterable [str ]:
233
+ yield from super ().render_plugins (
234
+ placeholder , language , context , editable = editable , template = template
235
+ )
236
+ yield f'<div class="cms-placeholder cms-placeholder-{ placeholder .pk } "></div>'
0 commit comments