diff --git a/pyproject.toml b/pyproject.toml index 5a11bc1..a7a19ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,9 @@ wuttaweb = "wuttaweb.conf:WuttaWebConfigExtension" [project.entry-points."wutta.typer_imports"] wuttaweb = "wuttaweb.cli" +[project.entry-points."wutta.web.menus"] +wuttaweb = "wuttaweb.menus:MenuHandler" + [project.urls] Homepage = "https://wuttaproject.org/" diff --git a/src/wuttaweb/handler.py b/src/wuttaweb/handler.py index 1ac0b78..9ca6c5a 100644 --- a/src/wuttaweb/handler.py +++ b/src/wuttaweb/handler.py @@ -24,7 +24,10 @@ Web Handler """ +import warnings + from wuttjamaican.app import GenericHandler +from wuttjamaican.util import load_entry_points from wuttaweb import static, forms, grids @@ -106,22 +109,87 @@ class WebHandler(GenericHandler): def get_menu_handler(self, **kwargs): """ - Get the configured "menu" handler for the web app. + Get the configured :term:`menu handler` for the web app. Specify a custom handler in your config file like this: .. code-block:: ini [wutta.web] - menus.handler_spec = poser.web.menus:PoserMenuHandler + menus.handler.spec = poser.web.menus:PoserMenuHandler :returns: Instance of :class:`~wuttaweb.menus.MenuHandler`. """ - if not hasattr(self, 'menu_handler'): - spec = self.config.get(f'{self.appname}.web.menus.handler_spec', - default='wuttaweb.menus:MenuHandler') - self.menu_handler = self.app.load_object(spec)(self.config) - return self.menu_handler + spec = self.config.get(f'{self.appname}.web.menus.handler.spec') + if not spec: + spec = self.config.get(f'{self.appname}.web.menus.handler_spec') + if spec: + warnings.warn(f"setting '{self.appname}.web.menus.handler_spec' is deprecated; " + f"please use '{self.appname}.web.menus.handler_spec' instead", + DeprecationWarning) + else: + spec = self.config.get(f'{self.appname}.web.menus.handler.default_spec', + default='wuttaweb.menus:MenuHandler') + factory = self.app.load_object(spec) + return factory(self.config) + + def get_menu_handler_specs(self, default=None): + """ + Get the :term:`spec` strings for all available :term:`menu + handlers