Skip to content

Commit

Permalink
Add ability to set default Download parameters (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Jan 24, 2023
1 parent ad18a9b commit 5ab929f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lumen/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
ValidationError, match_suggestion_message, validate_callback,
)
from .variables.base import Variable, Variables
from .views.base import View # noqa
from .views.base import Download, View # noqa

if TYPE_CHECKING:
from bokeh.server.contexts import BokehSessionContext
Expand Down Expand Up @@ -290,6 +290,8 @@ class Defaults(Component):
`Defaults` to apply to the component classes.
"""

download = param.Dict(default={}, doc="Defaults for the Download object")

filters = param.List(doc="Defaults for Filter objects.", class_=dict)

sources = param.List(doc="Defaults for Source objects.", class_=dict)
Expand Down Expand Up @@ -337,6 +339,30 @@ def _validate_defaults(
raise ValidationError(msg, default, p)
return defaults

@classmethod
def _validate_download(
cls, download_defaults: Dict[str, Any], spec: Dict[str, Any], context: Dict[str, Any]
):
if not isinstance(download_defaults, dict):
msg = f'Defaults for Download component must be declared as a dictionary, not as a {type(download_defaults)}.'
raise ValidationError(msg, spec, 'download:')
for p in download_defaults:
if p in Download.param:
pobj = Download.param[p]
try:
pobj._validate(download_defaults[p])
except Exception as e:
msg = f"The default for Download {p!r} parameter failed validation: {str(e)}"
raise ValidationError(msg, download_defaults, p)
continue
msg = (
f'Default for Download {p!r} parameter cannot be set as there '
'is no such parameter.'
)
msg = match_suggestion_message(p, list(Download.param), msg)
raise ValidationError(msg, download_defaults, p)
return download_defaults

@classmethod
def _validate_filters(
cls, filter_defaults: List[Dict[str, Any]], spec: Dict[str, Any], context: Dict[str, Any]
Expand All @@ -362,6 +388,7 @@ def _validate_views(
return cls._validate_defaults(View, view_defaults, spec)

def apply(self):
Download.param.update(self.download)
for obj, defaults in ((Filter, self.filters), (Source, self.sources),
(Transform, self.transforms), (View, self.views)):
for default in defaults:
Expand Down

0 comments on commit 5ab929f

Please sign in to comment.