Skip to content

Commit

Permalink
Add root object into evaluate parameters to easier be able to acces…
Browse files Browse the repository at this point in the history
…s sibling components
  • Loading branch information
boxed committed Dec 5, 2024
1 parent 7297520 commit 652af4d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sphinx
furo
Django
django-fastdev
-r../test_requirements.txt
4 changes: 2 additions & 2 deletions docs/templates/albums.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{ query }}

<ul>
{% for car in cars %}
<li>{{ car }}</li>
{% for album in albums %}
<li>{{ album }}</li>
{% endfor %}
</ul>
1 change: 1 addition & 0 deletions docs/test_doc_architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class User:
row Artist
cells Cells
bound_cell Cell
root Table
"""
# @test
)
Expand Down
35 changes: 34 additions & 1 deletion docs/test_doc_cookbook_general.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
from tests.helpers import req
from django.template import Template

from docs.models import Album
from iommi import (
Form,
html,
Page,
)
from tests.helpers import (
req,
show_output,
)

request = req('get')

Expand Down Expand Up @@ -75,3 +86,25 @@ def test_how_do_i_find_the_path_to_a_parameter():
"""
# @test
assert True # Until I come up with a nice way to test this
# @end


def test_access_other_component(album):
# language=rst
"""
How do I access a sibling component?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's say we have a `Page` with a form and a custom template, and we want
to access the form, we can do that via the `root` object:
"""

class MyPage(Page):
edit_album = Form.edit(auto__model=Album, instance=album)
view_album = Template('''
{{ root.parts.edit_album.fields.name.value }}
''')

# @test
show_output(MyPage())
# @end
2 changes: 1 addition & 1 deletion iommi/traversable.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def on_bind(self) -> None:
pass

def own_evaluate_parameters(self):
return {}
return dict(root=self.iommi_root())

def iommi_evaluate_parameters(self):
return self._evaluate_parameters
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ filterwarnings =
ignore:'cgi' is deprecated and slated for removal in Python 3.13.*
ignore:Passing unrecognized arguments to super
ignore:.*Reloading models is not advised as it can lead to inconsistencies, most notably with related models.*
ignore:.*FASTDEV_STRICT_IF.*

# Silence warning about pytest 6.0
junit_family=xunit1
Expand Down
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __mod__(self, other):
'iommi',
'tests',
'docs',
'django_fastdev',
]


Expand Down

0 comments on commit 652af4d

Please sign in to comment.