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/dash.py b/dash/dash.py index 5c70884e2f..e398dbcd42 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -170,58 +170,51 @@ def _handle_error(error): self.registered_paths = {} # urls + self.routes = [] - 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) + 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, used by dcc.Location - add_url( + self._add_url( '{}'.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) self._layout = None self._cached_layout = None - self.routes = [] self._dev_tools = _AttributeDict({ 'serve_dev_bundles': False }) @@ -230,6 +223,17 @@ def add_url(name, view_func, methods=('GET',)): self.server.errorhandler(exceptions.InvalidResourceError)( self._invalid_resources_handler) + def _add_url(self, name, view_func, methods=('GET',)): + self.server.add_url_rule( + name, + view_func=view_func, + endpoint=name, + 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): return self._layout 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'