mirror of
https://github.com/wrabit/django-cotton.git
synced 2025-07-07 17:45:01 +00:00
fixes first issue
This commit is contained in:
parent
a703ee3558
commit
3ec0fbbac3
2 changed files with 64 additions and 6 deletions
|
@ -22,8 +22,10 @@ class CottonVarsNode(Node):
|
||||||
if cotton_data["stack"]:
|
if cotton_data["stack"]:
|
||||||
current_component = cotton_data["stack"][-1]
|
current_component = cotton_data["stack"][-1]
|
||||||
attrs = current_component["attrs"]
|
attrs = current_component["attrs"]
|
||||||
|
slots = current_component.get("slots", {})
|
||||||
else:
|
else:
|
||||||
attrs = Attrs({})
|
attrs = Attrs({})
|
||||||
|
slots = {}
|
||||||
|
|
||||||
vars = {}
|
vars = {}
|
||||||
|
|
||||||
|
@ -31,13 +33,15 @@ class CottonVarsNode(Node):
|
||||||
key_to_exclude = key
|
key_to_exclude = key
|
||||||
if key not in attrs.exclude_unprocessable():
|
if key not in attrs.exclude_unprocessable():
|
||||||
if key.startswith(":"):
|
if key.startswith(":"):
|
||||||
try:
|
key_to_exclude = key[1:]
|
||||||
key_to_exclude = key[1:]
|
if key_to_exclude not in slots:
|
||||||
vars[key_to_exclude] = DynamicAttr(value, is_cvar=True).resolve(context)
|
try:
|
||||||
except UnprocessableDynamicAttr:
|
vars[key_to_exclude] = DynamicAttr(value, is_cvar=True).resolve(context)
|
||||||
pass
|
except UnprocessableDynamicAttr:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
attrs[key] = value
|
if key not in slots:
|
||||||
|
attrs[key] = value
|
||||||
attrs.exclude_from_string_output(key_to_exclude)
|
attrs.exclude_from_string_output(key_to_exclude)
|
||||||
|
|
||||||
# Process cvars without values
|
# Process cvars without values
|
||||||
|
|
|
@ -444,3 +444,57 @@ class CvarTests(CottonTestCase):
|
||||||
|
|
||||||
self.assertTrue("Attrs: ''" in content)
|
self.assertTrue("Attrs: ''" in content)
|
||||||
self.assertTrue("Action: 'something completely different'" in content)
|
self.assertTrue("Action: 'something completely different'" in content)
|
||||||
|
|
||||||
|
def test_dynamic_cvars_can_be_overridden_by_named_slots(self):
|
||||||
|
self.create_template(
|
||||||
|
"cotton/cvars_named_slots.html",
|
||||||
|
"""
|
||||||
|
<c-vars :action="{'do': 'it'}" />
|
||||||
|
|
||||||
|
Action: '{{ action }}'
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
# View template that uses the proxy component
|
||||||
|
self.create_template(
|
||||||
|
"cvars_named_slots_view.html",
|
||||||
|
"""
|
||||||
|
<c-cvars-named-slots>
|
||||||
|
<c-slot name="action">overridden action</c-slot>
|
||||||
|
</c-cvars-named-slots>
|
||||||
|
""",
|
||||||
|
"view/",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Override URLconf
|
||||||
|
with self.settings(ROOT_URLCONF=self.url_conf()):
|
||||||
|
response = self.client.get("/view/")
|
||||||
|
content = response.content.decode().strip()
|
||||||
|
|
||||||
|
self.assertTrue("Action: 'overridden action'" in content)
|
||||||
|
|
||||||
|
def test_dynamic_cvars_are_not_present_in_attrs_string(self):
|
||||||
|
self.create_template(
|
||||||
|
"cotton/cvars_dynamic_attrs.html",
|
||||||
|
"""
|
||||||
|
<c-vars :disabled />
|
||||||
|
|
||||||
|
Attrs: '{{ attrs }}'
|
||||||
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
# View template that uses the proxy component
|
||||||
|
self.create_template(
|
||||||
|
"cvars_dynamic_attrs_view.html",
|
||||||
|
"""
|
||||||
|
<c-cvars-dynamic-attrs />
|
||||||
|
""",
|
||||||
|
"view/",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Override URLconf
|
||||||
|
with self.settings(ROOT_URLCONF=self.url_conf()):
|
||||||
|
response = self.client.get("/view/")
|
||||||
|
content = response.content.decode().strip()
|
||||||
|
|
||||||
|
self.assertTrue("Attrs: ''" in content)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue