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

Move add_url function definition out of Dash.__init__() #377

Merged
merged 11 commits into from
Oct 8, 2018
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
42 changes: 23 additions & 19 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
'/<string:package_name>'
'/<path:path_in_package_dist>').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(
'{}<path:path>'.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
})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dash/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.28.1'
__version__ = '0.28.2'