From c0a5e915a1407c8b79dfbd5a27d2841eadb6931a Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Sat, 8 Sep 2018 15:39:17 -0500 Subject: [PATCH 1/8] Move add_url function definition out of Dash.__init__() --- dash/dash.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index a8414203cc..1b58c8e635 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -168,46 +168,38 @@ def _handle_error(error): # urls - def add_url(name, view_func, methods=('GET',)): - self.server.add_url_rule( - name, - view_func=view_func, - endpoint=name, - methods=list(methods) - ) - - add_url( + self.add_url( '{}_dash-layout'.format(self.config['routes_pathname_prefix']), self.serve_layout) - add_url( + self.add_url( '{}_dash-dependencies'.format( self.config['routes_pathname_prefix']), self.dependencies) - add_url( + self.add_url( '{}_dash-update-component'.format( self.config['routes_pathname_prefix']), self.dispatch, ['POST']) - add_url(( + self.add_url(( '{}_dash-component-suites' '/' '/').format( self.config['routes_pathname_prefix']), self.serve_component_suites) - add_url( + self.add_url( '{}_dash-routes'.format(self.config['routes_pathname_prefix']), self.serve_routes) - add_url( + self.add_url( self.config['routes_pathname_prefix'], self.index) # catch-all for front-end routes - add_url( + self.add_url( '{}'.format(self.config['routes_pathname_prefix']), self.index) @@ -217,6 +209,14 @@ def add_url(name, view_func, methods=('GET',)): self._cached_layout = None self.routes = [] + def add_url(self, name, view_func, methods=('GET',)): + self.server.add_url_rule( + name, + view_func=view_func, + endpoint=name, + methods=list(methods) + ) + @property def layout(self): return self._layout From f13a98918fd9919b705fe5f717875a8ab6ad2767 Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Sat, 8 Sep 2018 16:00:57 -0500 Subject: [PATCH 2/8] Fix indentation for pylint --- dash/dash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 1b58c8e635..8b95642ffc 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -188,7 +188,7 @@ def _handle_error(error): '/' '/').format( self.config['routes_pathname_prefix']), - self.serve_component_suites) + self.serve_component_suites) self.add_url( '{}_dash-routes'.format(self.config['routes_pathname_prefix']), From d94eb9a3d3e77fd14d1c79e0f4150a8ef5b477aa Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Wed, 19 Sep 2018 19:59:28 -0500 Subject: [PATCH 3/8] Make Dash.add_url() private as Dash._add_url() --- dash/dash.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 8b95642ffc..5515dc4078 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -168,38 +168,38 @@ def _handle_error(error): # urls - self.add_url( + self._add_url( '{}_dash-layout'.format(self.config['routes_pathname_prefix']), self.serve_layout) - self.add_url( + self._add_url( '{}_dash-dependencies'.format( self.config['routes_pathname_prefix']), self.dependencies) - self.add_url( + self._add_url( '{}_dash-update-component'.format( self.config['routes_pathname_prefix']), self.dispatch, ['POST']) - self.add_url(( + self._add_url(( '{}_dash-component-suites' '/' '/').format( self.config['routes_pathname_prefix']), self.serve_component_suites) - self.add_url( + self._add_url( '{}_dash-routes'.format(self.config['routes_pathname_prefix']), self.serve_routes) - self.add_url( + self._add_url( self.config['routes_pathname_prefix'], self.index) # catch-all for front-end routes - self.add_url( + self._add_url( '{}'.format(self.config['routes_pathname_prefix']), self.index) @@ -209,7 +209,7 @@ def _handle_error(error): self._cached_layout = None self.routes = [] - def add_url(self, name, view_func, methods=('GET',)): + def _add_url(self, name, view_func, methods=('GET',)): self.server.add_url_rule( name, view_func=view_func, From 8bb367cc285d3028136a95701dc01f9424c74a43 Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Wed, 19 Sep 2018 20:11:16 -0500 Subject: [PATCH 4/8] Fix indentation for pylint --- dash/dash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/dash.py b/dash/dash.py index 9dd77d9473..cb07a4a9bb 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -193,7 +193,7 @@ def _handle_error(error): '/' '/').format( self.config['routes_pathname_prefix']), - self.serve_component_suites) + self.serve_component_suites) self._add_url( '{}_dash-routes'.format(self.config['routes_pathname_prefix']), From 1ceece8191369072f42d31f2bba4721e0f3a04e4 Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Thu, 20 Sep 2018 21:21:03 -0500 Subject: [PATCH 5/8] Move misplaced lines from merging master --- dash/dash.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index cb07a4a9bb..1040866dec 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -214,6 +214,10 @@ def _handle_error(error): self._cached_layout = None self.routes = [] + # add a handler for components suites errors to return 404 + self.server.errorhandler(exceptions.InvalidResourceError)( + self._invalid_resources_handler) + def _add_url(self, name, view_func, methods=('GET',)): self.server.add_url_rule( name, @@ -222,10 +226,6 @@ def _add_url(self, name, view_func, methods=('GET',)): methods=list(methods) ) - # add a handler for components suites errors to return 404 - self.server.errorhandler(exceptions.InvalidResourceError)( - self._invalid_resources_handler) - @property def layout(self): return self._layout From b91fbcbfee1d95e04defecf4c0afeb0187f36581 Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Tue, 2 Oct 2018 09:31:00 -0500 Subject: [PATCH 6/8] Make Dash._add_url record urls in Dash.routes --- dash/dash.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 52442cf1fa..a97333fd26 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -172,6 +172,7 @@ def _handle_error(error): self.registered_paths = {} # urls + self.routes = [] self._add_url( '{}_dash-layout'.format(self.config['routes_pathname_prefix']), @@ -212,7 +213,6 @@ def _handle_error(error): self._layout = None self._cached_layout = None - self.routes = [] self._dev_tools = _AttributeDict({ 'serve_dev_bundles': False }) @@ -226,8 +226,11 @@ def _add_url(self, name, view_func, methods=('GET',)): name, view_func=view_func, endpoint=name, - methods=list(methods) - ) + methods=list(methods)) + + # record the url in Dash.routes so that it can be accessed later + # e.g. for adding authentication with flask_login + self.routes.append(name) @property def layout(self): From 617e074a2d4fb0a2e1e3d244c4e06fa7bd80bd8e Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Fri, 5 Oct 2018 21:40:42 -0500 Subject: [PATCH 7/8] Update CHANGELOG.md and bump version.py --- CHANGELOG.md | 4 ++++ dash/version.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7a43d2851..54e35d4e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.28.2 - 2018-10-05 +## Added +- Moved `add_url` function definition out of `Dash.__init__` [#377](https://github.com/plotly/dash/pull/377) + ## 0.28.1 - 2018-09-26 ## Fixed - Missing favicon package_data from setup.py [#407](https://github.com/plotly/dash/pull/407) diff --git a/dash/version.py b/dash/version.py index 84b55cbb0a..873054ed2e 100644 --- a/dash/version.py +++ b/dash/version.py @@ -1 +1 @@ -__version__ = '0.28.1' +__version__ = '0.28.2' From 72cc1f202b88dc2e44876f30bed7c890c9e9c2f1 Mon Sep 17 00:00:00 2001 From: hinnefe2 Date: Fri, 5 Oct 2018 22:07:29 -0500 Subject: [PATCH 8/8] Update favicon route to use new _add_url function --- dash/dash.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dash/dash.py b/dash/dash.py index 6255ab7838..e398dbcd42 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -207,8 +207,9 @@ def _handle_error(error): '{}'.format(self.config['routes_pathname_prefix']), self.index) - add_url('{}_favicon.ico'.format(self.config['routes_pathname_prefix']), - self._serve_default_favicon) + self._add_url( + '{}_favicon.ico'.format(self.config['routes_pathname_prefix']), + self._serve_default_favicon) self.server.before_first_request(self._setup_server)