@@ -83,7 +83,7 @@ def template_renderer(template_name, local_context=default_context, /):
83
83
_subregion = 2
84
84
_marks = 3
85
85
_fetch = 4
86
- CLOSE_SECTION = "__close_section__ "
86
+ _CLOSE_SECTION = "_close_section "
87
87
88
88
89
89
class RegionRenderer :
@@ -184,13 +184,17 @@ def register(
184
184
f"The renderer function { renderer } has less than the two required arguments."
185
185
)
186
186
187
- if plugin in self ._plugins :
188
- warnings .warn (
189
- f"The plugin { plugin } has already been registered with { self .__class__ } before." ,
190
- stacklevel = 2 ,
191
- )
187
+ if not isinstance (plugin , (list , tuple )):
188
+ plugin = [plugin ]
189
+
190
+ for p in plugin :
191
+ if p in self ._plugins :
192
+ warnings .warn (
193
+ f"The plugin { p } has already been registered with { self .__class__ } before." ,
194
+ stacklevel = 2 ,
195
+ )
192
196
193
- self ._plugins [plugin ] = (plugin , renderer , subregion , marks , fetch )
197
+ self ._plugins [p ] = (p , renderer , subregion , marks , fetch )
194
198
195
199
def plugins (self , * , fetch = True ):
196
200
"""
@@ -295,9 +299,6 @@ def handle_default(self, plugins, context):
295
299
for plugin in self .takewhile_subregion (plugins , "default" ):
296
300
yield self .render_plugin (plugin , context )
297
301
298
- def handle___close_section__ (self , plugins , context ):
299
- yield self .render_plugin (plugins .popleft (), context )
300
-
301
302
def render_region (self , * , region , contents , context ):
302
303
"""
303
304
Render one region.
@@ -334,7 +335,7 @@ def render_section_plugins(self, section, plugins, context):
334
335
.. code-block:: python
335
336
336
337
from django.utils.html import mark_safe
337
- from feincms3.renderer import CLOSE_SECTION, render_in_context
338
+ from feincms3.renderer import render_in_context
338
339
339
340
class SectionRenderer(RegionRenderer):
340
341
def handle_section(self, plugins, context):
@@ -348,22 +349,22 @@ def handle_section(self, plugins, context):
348
349
)
349
350
350
351
renderer = SectionRenderer()
351
- renderer.register (models.CloseSection, "", subregion=CLOSE_SECTION )
352
+ renderer.register_section_close (models.CloseSection)
352
353
renderer.register(models.Accordion, "", subregion="section")
353
354
354
355
This code automatically determines the template name from the class
355
356
name, making it easier to reuse for different section types.
356
357
357
358
Subregions are automatically closed when subregions change. Sections
358
- only end when encountering an explicit ``CLOSE_SECTION`` subregion or
359
- when there are no more plugins in the current region at all. Sections
360
- can contain other sections and subregions making them quite powerful
361
- when for organizing and grouping content.
359
+ only end when encountering an explicit section closing plugin or when
360
+ there are no more plugins in the current region at all. Sections can
361
+ contain other sections and subregions making them quite powerful when
362
+ for organizing and grouping content.
362
363
"""
363
364
out = []
364
365
while plugins :
365
366
subregion = self .subregion (plugins [0 ])
366
- if subregion == CLOSE_SECTION :
367
+ if subregion is _CLOSE_SECTION :
367
368
plugins .popleft ()
368
369
break
369
370
elif subregion is not None :
@@ -372,6 +373,14 @@ def handle_section(self, plugins, context):
372
373
out .append (self .render_plugin (plugins .popleft (), context ))
373
374
return out
374
375
376
+ def register_section_close (self , plugin , renderer = "" , ** kwargs ):
377
+ kwargs ["subregion" ] = _CLOSE_SECTION
378
+ self .register (plugin , renderer , ** kwargs )
379
+
380
+ def handle__close_section (self , plugins , context ):
381
+ plugins .popleft ()
382
+ yield from ()
383
+
375
384
# Main external rendering API
376
385
377
386
def regions_from_contents (self , contents , ** kwargs ):
0 commit comments