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

Use assets_url_path in get_asset_url. #374

Merged
merged 2 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all 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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.26.5 - 2018-09-10
## Fixed
- Fix `get_asset_url` with a different `assets_url_path`. [#374](https://github.com/plotly/dash/pull/374)

## 0.26.4 - 2018-08-28
## Fixed
- Set `url_base_pathname` to `None` in `Dash.__init__`. Fix [#364](https://github.com/plotly/dash/issues/364)
Expand Down
9 changes: 7 additions & 2 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ def format_tag(tag_name, attributes, inner='', closed=False, opened=False):
'{}="{}"'.format(k, v) for k, v in attributes.items()]))


def get_asset_path(requests_pathname, routes_pathname, asset_path):
def get_asset_path(
requests_pathname,
routes_pathname,
asset_path,
asset_url_path):

i = requests_pathname.rfind(routes_pathname)
req = requests_pathname[:i]

return '/'.join([
# Only take the first part of the pathname
req,
'assets',
asset_url_path,
asset_path
])

Expand Down
9 changes: 7 additions & 2 deletions dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def __init__(
self._assets_folder = assets_folder or os.path.join(
flask.helpers.get_root_path(name), 'assets'
)
self._assets_url_path = assets_url_path

# allow users to supply their own flask server
self.server = server or Flask(name, static_folder=static_folder)
Expand Down Expand Up @@ -944,10 +945,14 @@ def add_resource(p, filepath):
self._favicon = path

def get_asset_url(self, path):
return _get_asset_path(
asset = _get_asset_path(
self.config.requests_pathname_prefix,
self.config.routes_pathname_prefix,
path)
path,
self._assets_url_path.lstrip('/')
)

return asset

def run_server(self,
port=8050,
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.26.4'
__version__ = '0.26.5'
6 changes: 3 additions & 3 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ def test_pathname_prefix_environ_requests(self):
def test_pathname_prefix_assets(self):
req = '/'
routes = '/'
path = get_asset_path(req, routes, 'reset.css')
path = get_asset_path(req, routes, 'reset.css', 'assets')
self.assertEqual('/assets/reset.css', path)

req = '/requests/'
path = get_asset_path(req, routes, 'reset.css')
path = get_asset_path(req, routes, 'reset.css', 'assets')
self.assertEqual('/requests/assets/reset.css', path)

req = '/requests/routes/'
routes = '/routes/'
path = get_asset_path(req, routes, 'reset.css')
path = get_asset_path(req, routes, 'reset.css', 'assets')
self.assertEqual('/requests/assets/reset.css', path)


Expand Down
4 changes: 3 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,9 @@ def test_index_customization(self):
self.percy_snapshot('custom-index')

def test_assets(self):
app = dash.Dash(assets_folder='tests/assets',
app = dash.Dash(__name__,
assets_folder='tests/assets',
assets_url_path='/test-assets',
assets_ignore='.*ignored.*')
app.index_string = '''
<!DOCTYPE html>
Expand Down