update get_asset_url function - #1528
Conversation
- use external asset path if defined
|
Very nice! Could be a little DRYer, as it's only the first arg to Can you add a couple of unit tests of dash/tests/unit/test_configs.py Lines 147 to 179 in 3402cb8 After that, we'll just need a changelog entry and it'll be ready to go! |
|
does this seem more DRY? Not sure exactly what you were referring to. def get_asset_url(self, path):
if self.config.assets_external_path:
prefix = self.config.assets_external_path
else:
prefix = self.config.requests_pathname_prefix
asset = get_asset_path(
prefix,
path,
self.config.assets_url_path.lstrip("/"),
)
return asset |
|
Yep, that's about what I had in mind. But again, not a big deal. |
- changed assets_external_path doc string to be more descriptive - revised _add_assets_resource to join assets_external_path with assets_url_path so that it is cogruent with how get_asset_path works - added unit test `test_asset_url` - updated changelog
| self.config.assets_external_path, url_path | ||
| res["external_url"] = "/".join([ | ||
| self.config.assets_external_path.rstrip('/'), self.config.assets_url_path.strip('/'), url_path.lstrip('/') | ||
| ] |
There was a problem hiding this comment.
Hmm, maybe we could just call get_asset_url here?
There was a problem hiding this comment.
That works! Passing all tests.
|
Looking good, just a couple of minor comments above, but also I think it needs linting (I sympathize with wanting aligned values in the test matrix but I don't think |
Co-authored-by: Alex Johnson <johnson.alex.c@gmail.com>
|
running npm format changed a bunch of other files, sorry for creating more review work...🤷♂️ |
|
Ah, I'm guessing you're on a newer version of Line 11 in c5ba38f |
|
oh shoot, you're right I am running 20.8b1. I can downgrade and reformat then if that's when you want to do. |
|
Downgrading and reformatting would be the easiest way to get this merged quickly 😄 We may upgrade but that's going to take a little work because we'll want to do it evenly across all the dash repos. |
|
Alright, I reset to before I ran the format routine, downgraded black to 19.10b0 and then redid the format. Things came out to be more expected since only my changes were reformatted by black. |
alexcjohnson
left a comment
There was a problem hiding this comment.
Very nice - thank you! 💃
also fix changelog for #1528
This pull request addresses #1527 by adding and if statement to the
get_asset_urlfunction in dash.py instructing the app to use the external asset path if it is defined.I have tested this with an short I wrote and published. If you run the app and examine the src attribute of the image, it references and image on my own site karosc.github.io.