Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change _validate_layout to accept functions that return layouts. #336

Merged
merged 7 commits into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,12 @@ def _validate_layout(self):
'Make sure to set the `layout` attribute of your application '
'before running the server.')

to_validate = self._layout_value()

layout_id = getattr(self.layout, 'id', None)

component_ids = {layout_id} if layout_id else set()
for component in self.layout.traverse():
for component in to_validate.traverse():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use self._layout_value() ? it basically does the same check.

component_id = getattr(component, 'id', None)
if component_id and component_id in component_ids:
raise exceptions.DuplicateIdError(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,14 @@ def test_external_files_init(self):
(("//script[@src='{}']", x) for x in js_urls),
(("//link[@href='{}']", x) for x in css_urls)):
self.driver.find_element_by_xpath(fmt.format(url))

def test_func_layout_accepted(self):

app = dash.Dash()

def create_layout():
return html.Div('Hello World')
app.layout = create_layout

self.startServer(app)
time.sleep(0.5)