Skip to content

Commit

Permalink
[WIP] Change admin panel name
Browse files Browse the repository at this point in the history
  • Loading branch information
ndmlny-qs committed Aug 25, 2023
1 parent b08976c commit 3267382
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions panel/command/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ class Serve(_BkServe):
action = 'store_true',
help = "Whether to add an admin panel."
)),
('--admin-panel-name', dict(
metavar = "KEY=VALUE",
nargs = '+',
help = "Name to use for the admin panel.",
default = '/admin'
)),
('--admin-log-level', dict(
action = 'store',
default = None,
Expand Down Expand Up @@ -348,17 +354,20 @@ def customize_kwargs(self, args, server_kwargs):
if args.admin:
from ..io.admin import admin_panel
from ..io.server import per_app_patterns

# NOTE: `admin_panel_name` returns a list.
admin_path = args.admin_panel_name[0] if args.admin_panel_name else "/admin"
config._admin = True
app = Application(FunctionHandler(admin_panel))
unused_timeout = args.check_unused_sessions or 15000
state._admin_context = app_ctx = AdminApplicationContext(
app, unused_timeout=unused_timeout, url='/admin'
app, unused_timeout=unused_timeout, url=admin_path
)
if all(not isinstance(handler, DocumentLifecycleHandler) for handler in app._handlers):
app.add(DocumentLifecycleHandler())
app_patterns = []
for p in per_app_patterns:
route = '/admin' + p[0]
route = admin_path + p[0]
context = {"application_context": app_ctx}
app_patterns.append((route, p[1], context))

Expand Down
7 changes: 6 additions & 1 deletion panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ class _config(_base_config):

_admin = param.Boolean(default=False, doc="Whether the admin panel was enabled.")

_admin_panel_name = param.String(default=None, doc="Name to use for the admin panel.")

_admin_log_level = param.Selector(
default='DEBUG', objects=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
doc="Log level of the Admin Panel logger")
Expand Down Expand Up @@ -455,6 +457,10 @@ def _template_hook(self, value):
def _doc_build(self):
return os.environ.get('PANEL_DOC_BUILD')

@property
def admin_panel_name(self):
return os.environ.get('PANEL_ADMIN_PANEL_NAME', self._admin_panel_name)

@property
def admin_log_level(self):
admin_log_level = os.environ.get('PANEL_ADMIN_LOG_LEVEL', self._admin_log_level)
Expand Down Expand Up @@ -580,7 +586,6 @@ def theme(self):
config = _config(**{k: None if p.allow_None else getattr(_config, k)
for k, p in _params.items() if k != 'name'})


class panel_extension(_pyviz_extension):
"""
Initializes and configures Panel. You should always run `pn.extension`.
Expand Down

0 comments on commit 3267382

Please sign in to comment.