mirror of
https://github.com/django-components/django-components.git
synced 2025-07-16 04:54:59 +00:00
Create cloned template for rendering so test instrumentation works.
Co-authored-by: rbeard0330 <@dul2k3BKW6m>
This commit is contained in:
parent
8c784f3a4c
commit
1ea86fc50d
2 changed files with 57 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
|||
import warnings
|
||||
from copy import copy
|
||||
from itertools import chain
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -73,12 +74,17 @@ class Component(with_metaclass(MediaDefiningClass)):
|
|||
del slots_filled[unexpected_slot]
|
||||
|
||||
combined_slots = dict(slots_in_template, **slots_filled)
|
||||
# Replace slot nodes with their nodelists, then combine into a single, flat nodelist
|
||||
node_iterator = ([node] if not is_slot_node(node) else combined_slots[node.name]
|
||||
for node in template.template.nodelist)
|
||||
flattened_nodelist = NodeList(chain.from_iterable(node_iterator))
|
||||
if combined_slots:
|
||||
# Replace slot nodes with their nodelists, then combine into a single, flat nodelist
|
||||
node_iterator = ([node] if not is_slot_node(node) else combined_slots[node.name]
|
||||
for node in template.template.nodelist)
|
||||
|
||||
return flattened_nodelist.render(context)
|
||||
template = copy(template.template)
|
||||
template.nodelist = NodeList(chain.from_iterable(node_iterator))
|
||||
else:
|
||||
template = template.template
|
||||
|
||||
return template.render(context)
|
||||
|
||||
class Media:
|
||||
css = {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue