-
-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e6f68ac
commit 98b6fe2
Showing
4 changed files
with
64 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
"""This module provides a Bokeh Location Model as a wrapper around the JS window.location api""" | ||
import pathlib | ||
|
||
from typing import List, Optional | ||
|
||
import param | ||
|
||
from bokeh.core.properties import Bool, Instance, Int, String | ||
from bokeh.layouts import column | ||
from bokeh.core.properties import Bool, String | ||
from bokeh.models import Model | ||
|
||
|
||
class Location(Model): | ||
"""A python wrapper around the JS `window.location` api. See | ||
""" | ||
A python wrapper around the JS `window.location` api. See | ||
https://www.w3schools.com/js/js_window_location.asp and | ||
https://www.w3.org/TR/html52/browsers.html#the-location-interface | ||
You can use this model to provide (parts of) the app state to the user as a bookmarkable and | ||
shareable link. | ||
You can use this model to provide (parts of) the app state to the | ||
user as a bookmarkable and shareable link. | ||
""" | ||
|
||
href = String(default="", help="The full url, e.g. 'https://localhost:80?color=blue#interact'") | ||
href = String(default="", help=""" | ||
The full url, e.g. 'https://localhost:80?color=blue#interact'""") | ||
|
||
hostname = String(default="", help=""" | ||
hostname in window.location e.g. 'panel.holoviz.org'""") | ||
|
||
pathname = String(default="", help=""" | ||
pathname in window.location e.g. '/user_guide/Interact.html'""") | ||
|
||
protocol = String(default="", help=""" | ||
protocol in window.location e.g. 'https'""") | ||
|
||
hostname = String(default="", help="hostname in window.location e.g. 'panel.holoviz.org'") | ||
port = String(default="", help=""" | ||
port in window.location e.g. 80""") | ||
|
||
pathname = String(default="", help="pathname in window.location e.g. '/user_guide/Interact.html'") | ||
search = String(default="", help=""" | ||
search in window.location e.g. '?color=blue'""") | ||
|
||
protocol = String(default="", help="protocol in window.location e.g. 'https'") | ||
port = String(default="", help="port in window.location e.g. 80") | ||
search = String(default="", help="search in window.location e.g. '?color=blue'") | ||
hash_ = String(default="", help="hash in window.location e.g. '#interact'") | ||
hash_ = String(default="", help=""" | ||
hash in window.location e.g. '#interact'""") | ||
|
||
reload = Bool( | ||
default=True, | ||
help="""Reload the page when the location is updated. For multipage apps this should be \ | ||
set to True, For single page apps this should be set to False""", | ||
) | ||
reload = Bool(default=True, help=""" | ||
Reload the page when the location is updated. For multipage apps | ||
this should be set to True, For single page apps this should be | ||
set to False""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
"""In this module we test the Bokeh Location Model""" | ||
|
||
import pytest | ||
import panel as pn | ||
from panel.models.location import Location | ||
|
||
|
||
def test_constructor(): | ||
# When | ||
actual = Location() | ||
# Then | ||
assert actual.href == "" | ||
assert actual.hostname == "" | ||
assert actual.pathname == "" | ||
assert actual.protocol == "" | ||
assert actual.port == "" | ||
assert actual.search == "" | ||
assert actual.hash_ == "" | ||
assert actual.reload == True | ||
|
||
|
||
def test_constructor_with__href(): | ||
# Given | ||
href = "https://panel.holoviz.org/user_guide/Interact.html:80?color=blue#interact" | ||
# When | ||
actual = Location( | ||
href="https://panel.holoviz.org/user_guide/Interact.html:80?color=blue#interact" | ||
) | ||
# Then | ||
assert actual.href == href | ||
assert actual.hostname == "" | ||
assert actual.pathname == "" | ||
assert actual.protocol == "" | ||
assert actual.port == "" | ||
assert actual.search == "" | ||
assert actual.hash_ == "" | ||
assert actual.reload == True | ||
|
||
|
||
def test_manual(): | ||
bkmodel = pn.pane.Bokeh(Location()) | ||
app = pn.Column(bkmodel) | ||
return app | ||
|
||
|
||
if __name__.startswith("bk"): | ||
test_manual().servable() | ||
import panel as pn | ||
|
||
from panel.models.location import Location | ||
|
||
|
||
def test_constructor(): | ||
# When | ||
actual = Location() | ||
# Then | ||
assert actual.href == "" | ||
assert actual.hostname == "" | ||
assert actual.pathname == "" | ||
assert actual.protocol == "" | ||
assert actual.port == "" | ||
assert actual.search == "" | ||
assert actual.hash_ == "" | ||
assert actual.reload == True | ||
|
||
|
||
def test_constructor_with__href(): | ||
# Given | ||
href = "https://panel.holoviz.org/user_guide/Interact.html:80?color=blue#interact" | ||
# When | ||
actual = Location( | ||
href="https://panel.holoviz.org/user_guide/Interact.html:80?color=blue#interact" | ||
) | ||
# Then | ||
assert actual.href == href | ||
assert actual.hostname == "" | ||
assert actual.pathname == "" | ||
assert actual.protocol == "" | ||
assert actual.port == "" | ||
assert actual.search == "" | ||
assert actual.hash_ == "" | ||
assert actual.reload == True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters